00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef _THREADPOOL_H_
00020 #define _THREADPOOL_H_
00021
00048 #include <glib-object.h>
00049 #include "vmware/tools/plugin.h"
00050
00051 #define TOOLS_CORE_PROP_TPOOL "tcs_prop_thread_pool"
00052
00054 typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
00055 gpointer data);
00056
00066 typedef struct ToolsCorePool {
00067 guint (*submit)(ToolsAppCtx *ctx,
00068 ToolsCorePoolCb cb,
00069 gpointer data,
00070 GDestroyNotify dtor);
00071 void (*cancel)(guint id);
00072 gboolean (*start)(ToolsAppCtx *ctx,
00073 ToolsCorePoolCb cb,
00074 ToolsCorePoolCb interrupt,
00075 gpointer data,
00076 GDestroyNotify dtor);
00077 } ToolsCorePool;
00078
00079
00080
00081
00082
00093 G_INLINE_FUNC ToolsCorePool *
00094 ToolsCorePool_GetPool(ToolsAppCtx *ctx)
00095 {
00096 ToolsCorePool *pool = NULL;
00097 g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
00098 return pool;
00099 }
00100
00101
00102
00103
00104
00125 G_INLINE_FUNC guint
00126 ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
00127 ToolsCorePoolCb cb,
00128 gpointer data,
00129 GDestroyNotify dtor)
00130 {
00131 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00132 if (pool != NULL) {
00133 return pool->submit(ctx, cb, data, dtor);
00134 }
00135 return 0;
00136 }
00137
00138
00139
00140
00141
00155 G_INLINE_FUNC void
00156 ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
00157 guint taskId)
00158 {
00159 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00160 if (pool != NULL) {
00161 pool->cancel(taskId);
00162 }
00163 }
00164
00165
00166
00167
00168
00198 G_INLINE_FUNC gboolean
00199 ToolsCorePool_StartThread(ToolsAppCtx *ctx,
00200 ToolsCorePoolCb cb,
00201 ToolsCorePoolCb interrupt,
00202 gpointer data,
00203 GDestroyNotify dtor)
00204 {
00205 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00206 if (pool != NULL) {
00207 return pool->start(ctx, cb, interrupt, data, dtor);
00208 }
00209 return FALSE;
00210 }
00211
00214 #endif
00215