threadPool.h
Go to the documentation of this file.
/*********************************************************
* Copyright (C) 2010-2016 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_
#include <glib-object.h>
#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,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
GDestroyNotify dtor);
} ToolsCorePool;
/*
*******************************************************************************
* ToolsCorePool_GetPool -- */
G_INLINE_FUNC ToolsCorePool *
ToolsCorePool_GetPool(ToolsAppCtx *ctx)
{
ToolsCorePool *pool = NULL;
g_object_get(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &pool, NULL);
return pool;
}
/*
*******************************************************************************
* ToolsCorePool_SubmitTask -- */
G_INLINE_FUNC 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 -- */
G_INLINE_FUNC void
ToolsCorePool_CancelTask(ToolsAppCtx *ctx,
guint taskId)
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
pool->cancel(taskId);
}
}
/*
*******************************************************************************
* ToolsCorePool_StartThread -- */
G_INLINE_FUNC gboolean
ToolsCorePool_StartThread(ToolsAppCtx *ctx,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
GDestroyNotify dtor)
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
return pool->start(ctx, cb, interrupt, data, dtor);
}
return FALSE;
}
#endif /* _THREADPOOL_H_ */
ToolsCorePool_GetPool
G_INLINE_FUNC ToolsCorePool * ToolsCorePool_GetPool(ToolsAppCtx *ctx)
Returns the thread pool instance for the service.
Definition: threadPool.h:94
ToolsCorePool_CancelTask
G_INLINE_FUNC void ToolsCorePool_CancelTask(ToolsAppCtx *ctx, guint taskId)
Cancels a task previously submitted to the pool.
Definition: threadPool.h:156
plugin.h
ToolsCorePool
struct ToolsCorePool ToolsCorePool
Public interface of the shared thread pool.
ToolsCorePoolCb
void(* ToolsCorePoolCb)(ToolsAppCtx *ctx, gpointer data)
Definition: threadPool.h:54
ToolsCorePool_StartThread
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
ToolsAppCtx::serviceObj
gpointer serviceObj
Definition: plugin.h:271
ToolsCorePool
Public interface of the shared thread pool.
Definition: threadPool.h:66
ToolsAppCtx
Definition: plugin.h:241
ToolsCorePool_SubmitTask
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