aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib/iomgr/executor.h
diff options
context:
space:
mode:
authorGravatar Sree Kuchibhotla <sreek@google.com>2018-07-09 14:53:54 -0700
committerGravatar Sree Kuchibhotla <sreek@google.com>2018-07-09 15:05:44 -0700
commit7e9d52530d0145fe8202d2fd35621407745e91ab (patch)
treefc2ea24ecd128d38bc582e25504a8eb2ef4d802d /src/core/lib/iomgr/executor.h
parent46f399a28256ffd153eeca80245ef65a671afaed (diff)
Move executor implementation into GrpcExecutor class
Diffstat (limited to 'src/core/lib/iomgr/executor.h')
-rw-r--r--src/core/lib/iomgr/executor.h56
1 files changed, 46 insertions, 10 deletions
diff --git a/src/core/lib/iomgr/executor.h b/src/core/lib/iomgr/executor.h
index 68d540af55..cafe47decb 100644
--- a/src/core/lib/iomgr/executor.h
+++ b/src/core/lib/iomgr/executor.h
@@ -21,30 +21,66 @@
#include <grpc/support/port_platform.h>
+#include "src/core/lib/gpr/spinlock.h"
+#include "src/core/lib/gprpp/thd.h"
#include "src/core/lib/iomgr/closure.h"
+typedef struct {
+ gpr_mu mu;
+ size_t id; // For debugging purposes
+ gpr_cv cv;
+ grpc_closure_list elems;
+ size_t depth; // Number of closures in the closure list
+ bool shutdown;
+ bool queued_long_job;
+ grpc_core::Thread thd;
+} thread_state;
+
typedef enum {
GRPC_EXECUTOR_SHORT,
GRPC_EXECUTOR_LONG
} grpc_executor_job_length;
-/** Initialize the global executor.
- *
- * This mechanism is meant to outsource work (grpc_closure instances) to a
- * thread, for those cases where blocking isn't an option but there isn't a
- * non-blocking solution available. */
+class GrpcExecutor {
+ public:
+ GrpcExecutor(const char* executor_name);
+ void Init();
+
+ /** Is the executor multi-threaded? */
+ bool IsThreaded();
+
+ /* Enable/disable threading - must be called after Init and Shutdown() */
+ void SetThreading(bool threading);
+
+ /** Shutdown the executor, running all pending work as part of the call */
+ void Shutdown();
+
+ /** Enqueue the closure onto the executor. is_short is true if the closure is
+ * a short job (i.e expected to not block and complete quickly) */
+ void Enqueue(grpc_closure* closure, grpc_error* error, bool is_short);
+
+ private:
+ static size_t RunClosures(grpc_closure_list list);
+ static void ThreadMain(void* arg);
+
+ const char* name;
+ thread_state* thd_state;
+ size_t max_threads;
+ gpr_atm num_threads;
+ gpr_spinlock adding_thread_lock;
+};
+
+// == Global executor functions ==
+
void grpc_executor_init();
-grpc_closure_scheduler* grpc_executor_scheduler(grpc_executor_job_length);
+grpc_closure_scheduler* grpc_executor_scheduler(
+ grpc_executor_job_length length);
-/** Shutdown the executor, running all pending work as part of the call */
void grpc_executor_shutdown();
-/** Is the executor multi-threaded? */
bool grpc_executor_is_threaded();
-/* enable/disable threading - must be called after grpc_executor_init and before
- grpc_executor_shutdown */
void grpc_executor_set_threading(bool enable);
#endif /* GRPC_CORE_LIB_IOMGR_EXECUTOR_H */