open-vm-tools 11.0.0

threadPool.h
Go to the documentation of this file.
1 /*********************************************************
2 * Copyright (C) 2010-2019 VMware, Inc. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation version 2.1 and no later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11 * License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16 *
17 *********************************************************/
18
19 #ifndef _THREADPOOL_H_
20 #define _THREADPOOL_H_
21
48 #include <glib-object.h>
49 #include "vmware/tools/plugin.h"
50
51 #define TOOLS_CORE_PROP_TPOOL "tcs_prop_thread_pool"
52
54 typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
55 gpointer data);
56
66 typedef struct ToolsCorePool {
67 guint (*submit)(ToolsAppCtx *ctx,
68 ToolsCorePoolCb cb,
69 gpointer data,
70 GDestroyNotify dtor);
71 void (*cancel)(guint id);
72 gboolean (*start)(ToolsAppCtx *ctx,
73 const gchar *threadName,
74 ToolsCorePoolCb cb,
75 ToolsCorePoolCb interrupt,
76 gpointer data,
77 GDestroyNotify dtor);
78 } ToolsCorePool;
79
80
81 /*
82 *******************************************************************************
83 * ToolsCorePool_GetPool -- */
94 static inline ToolsCorePool *
95 ToolsCorePool_GetPool(ToolsAppCtx *ctx)
96 {
97 ToolsCorePool *pool = NULL;
98 g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
99 return pool;
100 }
101
102
103 /*
104 *******************************************************************************
105 * ToolsCorePool_SubmitTask -- */
126 static inline guint
127 ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
128 ToolsCorePoolCb cb,
129 gpointer data,
130 GDestroyNotify dtor)
131 {
132 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
133 if (pool != NULL) {
134 return pool->submit(ctx, cb, data, dtor);
135 }
136 return 0;
137 }
138
139
140 /*
141 *******************************************************************************
142 * ToolsCorePool_CancelTask -- */
156 static inline void
157 ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
158 guint taskId)
159 {
160 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
161 if (pool != NULL) {
162 pool->cancel(taskId);
163 }
164 }
165
166
167 /*
168 *******************************************************************************
169 * ToolsCorePool_StartThread -- */
200 static inline gboolean
201 ToolsCorePool_StartThread(ToolsAppCtx *ctx,
202 const gchar *threadName,
203 ToolsCorePoolCb cb,
204 ToolsCorePoolCb interrupt,
205 gpointer data,
206 GDestroyNotify dtor)
207 {
208 ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
209 if (pool != NULL) {
210 return pool->start(ctx, threadName, cb, interrupt, data, dtor);
211 }
212 return FALSE;
213 }
214
217 #endif /* _THREADPOOL_H_ */
218
ToolsCorePool
Public interface of the shared thread pool.
Definition: threadPool.h:65
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:282
plugin.h
ToolsCorePool
struct ToolsCorePool ToolsCorePool
Public interface of the shared thread pool.
ToolsCorePoolCb
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition: threadPool.h:53
ToolsAppCtx
Definition: plugin.h:250