open-vm-tools 12.4.0
threadPool.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2010-2019,2023 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 /*
49  * glib-object.h should not be placed inside `extern "C"' blocks.
50  * However, this header is often placed inside such blocks.
51  * Here we change back into C++ for glib-object.h
52  */
53 #ifdef __cplusplus
54 extern "C++" {
55 #endif
56 #include <glib-object.h>
57 #ifdef __cplusplus
58 }
59 #endif
60 
61 #include "vmware/tools/plugin.h"
62 
63 #define TOOLS_CORE_PROP_TPOOL "tcs_prop_thread_pool"
64 
66 typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
67  gpointer data);
68 
78 typedef struct ToolsCorePool {
79  guint (*submit)(ToolsAppCtx *ctx,
80  ToolsCorePoolCb cb,
81  gpointer data,
82  GDestroyNotify dtor);
83  void (*cancel)(guint id);
84  gboolean (*start)(ToolsAppCtx *ctx,
85  const gchar *threadName,
86  ToolsCorePoolCb cb,
87  ToolsCorePoolCb interrupt,
88  gpointer data,
89  GDestroyNotify dtor);
91 
92 
93 /*
94  *******************************************************************************
95  * ToolsCorePool_GetPool -- */
106 static inline ToolsCorePool *
107 ToolsCorePool_GetPool(ToolsAppCtx *ctx)
108 {
109  ToolsCorePool *pool = NULL;
110  g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
111  return pool;
112 }
113 
114 
115 /*
116  *******************************************************************************
117  * ToolsCorePool_SubmitTask -- */
138 static inline guint
139 ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
140  ToolsCorePoolCb cb,
141  gpointer data,
142  GDestroyNotify dtor)
143 {
144  ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
145  if (pool != NULL) {
146  return pool->submit(ctx, cb, data, dtor);
147  }
148  return 0;
149 }
150 
151 
152 /*
153  *******************************************************************************
154  * ToolsCorePool_CancelTask -- */
168 static inline void
169 ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
170  guint taskId)
171 {
172  ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
173  if (pool != NULL) {
174  pool->cancel(taskId);
175  }
176 }
177 
178 
179 /*
180  *******************************************************************************
181  * ToolsCorePool_StartThread -- */
212 static inline gboolean
213 ToolsCorePool_StartThread(ToolsAppCtx *ctx,
214  const gchar *threadName,
215  ToolsCorePoolCb cb,
216  ToolsCorePoolCb interrupt,
217  gpointer data,
218  GDestroyNotify dtor)
219 {
220  ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
221  if (pool != NULL) {
222  return pool->start(ctx, threadName, cb, interrupt, data, dtor);
223  }
224  return FALSE;
225 }
226 
229 #endif /* _THREADPOOL_H_ */
230 
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition: threadPool.h:66
struct ToolsCorePool ToolsCorePool
Public interface of the shared thread pool.
Definition: plugin.h:294
gpointer serviceObj
Definition: plugin.h:326
Public interface of the shared thread pool.
Definition: threadPool.h:78