Go to the documentation of this file.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
00044 #include <glib-object.h>
00045 #include "vmware/tools/plugin.h"
00046
00047 #define TOOLS_CORE_PROP_TPOOL "tcs_prop_thread_pool"
00048
00050 typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
00051 gpointer data);
00052
00062 typedef struct ToolsCorePool {
00063 guint (*submit)(ToolsAppCtx *ctx,
00064 ToolsCorePoolCb cb,
00065 gpointer data,
00066 GDestroyNotify dtor);
00067 void (*cancel)(guint id);
00068 gboolean (*start)(ToolsAppCtx *ctx,
00069 ToolsCorePoolCb cb,
00070 ToolsCorePoolCb interrupt,
00071 gpointer data,
00072 GDestroyNotify dtor);
00073 } ToolsCorePool;
00074
00075
00076
00077
00078
00089 G_INLINE_FUNC ToolsCorePool *
00090 ToolsCorePool_GetPool(ToolsAppCtx *ctx)
00091 {
00092 ToolsCorePool *pool = NULL;
00093 g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
00094 return pool;
00095 }
00096
00097
00098
00099
00100
00121 G_INLINE_FUNC guint
00122 ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
00123 ToolsCorePoolCb cb,
00124 gpointer data,
00125 GDestroyNotify dtor)
00126 {
00127 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00128 if (pool != NULL) {
00129 return pool->submit(ctx, cb, data, dtor);
00130 }
00131 return 0;
00132 }
00133
00134
00135
00136
00137
00151 G_INLINE_FUNC void
00152 ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
00153 guint taskId)
00154 {
00155 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00156 if (pool != NULL) {
00157 pool->cancel(taskId);
00158 }
00159 }
00160
00161
00162
00163
00164
00194 G_INLINE_FUNC gboolean
00195 ToolsCorePool_StartThread(ToolsAppCtx *ctx,
00196 ToolsCorePoolCb cb,
00197 ToolsCorePoolCb interrupt,
00198 gpointer data,
00199 GDestroyNotify dtor)
00200 {
00201 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
00202 if (pool != NULL) {
00203 return pool->start(ctx, cb, interrupt, data, dtor);
00204 }
00205 return FALSE;
00206 }
00207
00208
00209 #endif
00210