open-vm-tools 10.1.5
threadPool.h
Go to the documentation of this file.
1 /*********************************************************
2  * Copyright (C) 2010-2016 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  ToolsCorePoolCb cb,
74  ToolsCorePoolCb interrupt,
75  gpointer data,
76  GDestroyNotify dtor);
78 
79 
80 /*
81  *******************************************************************************
82  * ToolsCorePool_GetPool -- */
93 G_INLINE_FUNC ToolsCorePool *
95 {
96  ToolsCorePool *pool = NULL;
97  g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
98  return pool;
99 }
100 
101 
102 /*
103  *******************************************************************************
104  * ToolsCorePool_SubmitTask -- */
125 G_INLINE_FUNC guint
127  ToolsCorePoolCb cb,
128  gpointer data,
129  GDestroyNotify dtor)
130 {
132  if (pool != NULL) {
133  return pool->submit(ctx, cb, data, dtor);
134  }
135  return 0;
136 }
137 
138 
139 /*
140  *******************************************************************************
141  * ToolsCorePool_CancelTask -- */
155 G_INLINE_FUNC void
157  guint taskId)
158 {
160  if (pool != NULL) {
161  pool->cancel(taskId);
162  }
163 }
164 
165 
166 /*
167  *******************************************************************************
168  * ToolsCorePool_StartThread -- */
198 G_INLINE_FUNC gboolean
200  ToolsCorePoolCb cb,
201  ToolsCorePoolCb interrupt,
202  gpointer data,
203  GDestroyNotify dtor)
204 {
206  if (pool != NULL) {
207  return pool->start(ctx, cb, interrupt, data, dtor);
208  }
209  return FALSE;
210 }
211 
214 #endif /* _THREADPOOL_H_ */
215 
G_INLINE_FUNC ToolsCorePool * ToolsCorePool_GetPool(ToolsAppCtx *ctx)
Returns the thread pool instance for the service.
Definition: threadPool.h:94
G_INLINE_FUNC void ToolsCorePool_CancelTask(ToolsAppCtx *ctx, guint taskId)
Cancels a task previously submitted to the pool.
Definition: threadPool.h:156
struct ToolsCorePool ToolsCorePool
Public interface of the shared thread pool.
G_INLINE_FUNC gboolean ToolsCorePool_StartThread(ToolsAppCtx *ctx, ToolsCorePoolCb cb, ToolsCorePoolCb interrupt, gpointer data, GDestroyNotify dtor)
Starts a task on its own thread.
Definition: threadPool.h:199
gpointer serviceObj
Definition: plugin.h:271
Public interface of the shared thread pool.
Definition: threadPool.h:66
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition: threadPool.h:54
Definition: plugin.h:241
G_INLINE_FUNC guint ToolsCorePool_SubmitTask(ToolsAppCtx *ctx, ToolsCorePoolCb cb, gpointer data, GDestroyNotify dtor)
Submits a task for execution in the thread pool.
Definition: threadPool.h:126