threadPool.h
Go to the documentation of this file.
/*********************************************************
* Copyright (C) 2010-2019,2023 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation version 2.1 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*********************************************************/
#ifndef _THREADPOOL_H_
#define _THREADPOOL_H_
/*
* glib-object.h should not be placed inside `extern "C"' blocks.
* However, this header is often placed inside such blocks.
* Here we change back into C++ for glib-object.h
*/
#ifdef __cplusplus
extern "C++" {
#endif
#include <glib-object.h>
#ifdef __cplusplus
}
#endif
#include "vmware/tools/plugin.h"
#define TOOLS_CORE_PROP_TPOOL "tcs_prop_thread_pool"
typedef void (*ToolsCorePoolCb)(ToolsAppCtx *ctx,
gpointer data);
typedef struct ToolsCorePool {
guint (*submit)(ToolsAppCtx *ctx,
ToolsCorePoolCb cb,
gpointer data,
GDestroyNotify dtor);
void (*cancel)(guint id);
gboolean (*start)(ToolsAppCtx *ctx,
const gchar *threadName,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
GDestroyNotify dtor);
} ToolsCorePool;
/*
*******************************************************************************
* ToolsCorePool_GetPool -- */
static inline ToolsCorePool *
ToolsCorePool_GetPool(ToolsAppCtx *ctx)
{
ToolsCorePool *pool = NULL;
g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
return pool;
}
/*
*******************************************************************************
* ToolsCorePool_SubmitTask -- */
static inline guint
ToolsCorePool_SubmitTask(ToolsAppCtx *ctx,
ToolsCorePoolCb cb,
gpointer data,
GDestroyNotify dtor)
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
return pool->submit(ctx, cb, data, dtor);
}
return 0;
}
/*
*******************************************************************************
* ToolsCorePool_CancelTask -- */
static inline void
ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
guint taskId)
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
pool->cancel(taskId);
}
}
/*
*******************************************************************************
* ToolsCorePool_StartThread -- */
static inline gboolean
ToolsCorePool_StartThread(ToolsAppCtx *ctx,
const gchar *threadName,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
GDestroyNotify dtor)
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
return pool->start(ctx, threadName, cb, interrupt, data, dtor);
}
return FALSE;
}
#endif /* _THREADPOOL_H_ */
ToolsCorePoolCb
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition threadPool.h:66
plugin.h
ToolsAppCtx
Definition plugin.h:307
ToolsCorePool
Public interface of the shared thread pool.
Definition threadPool.h:78