open-vm-tools 2011.10.26
|
00001 /********************************************************* 00002 * Copyright (C) 2010 VMware, Inc. All rights reserved. 00003 * 00004 * This program is free software; you can redistribute it and/or modify it 00005 * under the terms of the GNU Lesser General Public License as published 00006 * by the Free Software Foundation version 2.1 and no later version. 00007 * 00008 * This program is distributed in the hope that it will be useful, but 00009 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 00010 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public 00011 * License for more details. 00012 * 00013 * You should have received a copy of the GNU Lesser General Public License 00014 * along with this program; if not, write to the Free Software Foundation, Inc., 00015 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 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 * ToolsCorePool_GetPool -- */ 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 * ToolsCorePool_SubmitTask -- */ 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 * ToolsCorePool_CancelTask -- */ 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 * ToolsCorePool_StartThread -- */ 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 /* _THREADPOOL_H_ */ 00215