open-vm-tools 12.2.5
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
54typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
55 gpointer data);
56
66typedef struct ToolsCorePool {
67 guint (*submit)(ToolsAppCtx *ctx,
69 gpointer data,
70 GDestroyNotify dtor);
71 void (*cancel)(guint id);
72 gboolean (*start)(ToolsAppCtx *ctx,
73 const gchar *threadName,
75 ToolsCorePoolCb interrupt,
76 gpointer data,
77 GDestroyNotify dtor);
79
80
81/*
82 *******************************************************************************
83 * ToolsCorePool_GetPool -- */
94static inline ToolsCorePool *
95ToolsCorePool_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 -- */
126static inline guint
127ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
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 -- */
156static inline void
157ToolsCorePool_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 -- */
200static inline gboolean
201ToolsCorePool_StartThread(ToolsAppCtx *ctx,
202 const gchar *threadName,
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
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition: threadPool.h:54
struct ToolsCorePool ToolsCorePool
Public interface of the shared thread pool.
Definition: plugin.h:282
gpointer serviceObj
Definition: plugin.h:314
Public interface of the shared thread pool.
Definition: threadPool.h:66