Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Unified Diff: third_party/grpc/src/cpp/server/dynamic_thread_pool.h

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/grpc/src/cpp/server/dynamic_thread_pool.h
diff --git a/third_party/tcmalloc/vendor/src/base/spinlock_internal.h b/third_party/grpc/src/cpp/server/dynamic_thread_pool.h
similarity index 56%
copy from third_party/tcmalloc/vendor/src/base/spinlock_internal.h
copy to third_party/grpc/src/cpp/server/dynamic_thread_pool.h
index 44942609f40a87492a7aeed0068a5e27bf9cd157..5ba7533c05f41872cf10edb14609fd47376e2383 100644
--- a/third_party/tcmalloc/vendor/src/base/spinlock_internal.h
+++ b/third_party/grpc/src/cpp/server/dynamic_thread_pool.h
@@ -1,4 +1,6 @@
-/* Copyright (c) 2010, Google Inc.
+/*
+ *
+ * Copyright 2015, Google Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -27,38 +29,55 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * ---
- * This file is an internal part spinlock.cc and once.cc
- * It may not be used directly by code outside of //base.
*/
-#ifndef BASE_SPINLOCK_INTERNAL_H_
-#define BASE_SPINLOCK_INTERNAL_H_
+#ifndef GRPC_INTERNAL_CPP_DYNAMIC_THREAD_POOL_H
+#define GRPC_INTERNAL_CPP_DYNAMIC_THREAD_POOL_H
+
+#include <list>
+#include <memory>
+#include <queue>
+
+#include <grpc++/impl/sync.h>
+#include <grpc++/impl/thd.h>
+#include <grpc++/support/config.h>
+
+#include "src/cpp/server/thread_pool_interface.h"
+
+namespace grpc {
+
+class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface {
+ public:
+ explicit DynamicThreadPool(int reserve_threads);
+ ~DynamicThreadPool();
+
+ void Add(const std::function<void()>& callback) GRPC_OVERRIDE;
-#include <config.h>
-#include "base/basictypes.h"
-#include "base/atomicops.h"
+ private:
+ class DynamicThread {
+ public:
+ DynamicThread(DynamicThreadPool* pool);
+ ~DynamicThread();
-namespace base {
-namespace internal {
+ private:
+ DynamicThreadPool* pool_;
+ std::unique_ptr<grpc::thread> thd_;
+ void ThreadFunc();
+ };
+ grpc::mutex mu_;
+ grpc::condition_variable cv_;
+ grpc::condition_variable shutdown_cv_;
+ bool shutdown_;
+ std::queue<std::function<void()>> callbacks_;
+ int reserve_threads_;
+ int nthreads_;
+ int threads_waiting_;
+ std::list<DynamicThread*> dead_threads_;
-// SpinLockWait() waits until it can perform one of several transitions from
-// "from" to "to". It returns when it performs a transition where done==true.
-struct SpinLockWaitTransition {
- int32 from;
- int32 to;
- bool done;
+ void ThreadFunc();
+ static void ReapThreads(std::list<DynamicThread*>* tlist);
};
-// Wait until *w can transition from trans[i].from to trans[i].to for some i
-// satisfying 0<=i<n && trans[i].done, atomically make the transition,
-// then return the old value of *w. Make any other atomic tranistions
-// where !trans[i].done, but continue waiting.
-int32 SpinLockWait(volatile Atomic32 *w, int n,
- const SpinLockWaitTransition trans[]);
-void SpinLockWake(volatile Atomic32 *w, bool all);
-void SpinLockDelay(volatile Atomic32 *w, int32 value, int loop);
+} // namespace grpc
-} // namespace internal
-} // namespace base
-#endif
+#endif // GRPC_INTERNAL_CPP_DYNAMIC_THREAD_POOL_H
« no previous file with comments | « third_party/grpc/src/cpp/server/create_default_thread_pool.cc ('k') | third_party/grpc/src/cpp/server/dynamic_thread_pool.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698