])
#
-# Check for glib 2.6.14 or greater.
+# Check for glib 2.34.0 or greater.
#
AC_VMW_CHECK_LIB([glib-2.0],
[GLIB2],
guint maxFiles;
gboolean append;
gboolean error;
- GStaticMutex lock;
+ GMutex lock;
} FileLogger;
FileLogger *logger = data;
gsize written;
- g_static_mutex_lock(&logger->lock);
+ g_mutex_lock(&logger->lock);
if (logger->error) {
goto exit;
}
exit:
- g_static_mutex_unlock(&logger->lock);
+ g_mutex_unlock(&logger->lock);
}
if (logger->file != NULL) {
g_io_channel_unref(logger->file);
}
- g_static_mutex_free(&logger->lock);
+ g_mutex_clear(&logger->lock);
g_free(logger->path);
g_free(logger);
}
data->append = append;
data->maxSize = maxSize * 1024 * 1024;
data->maxFiles = maxFiles + 1; /* To account for the active log file. */
- g_static_mutex_init(&data->lock);
+ g_mutex_init(&data->lock);
return &data->handler;
}
/*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
#include <stdio.h>
#if defined(_WIN32)
-static GStaticMutex gConsoleLock = G_STATIC_MUTEX_INIT;
+static GMutex gConsoleLock;
static gint gRefCount = 0;
#endif
StdLogger *sdata = data;
if (!sdata->attached) {
- g_static_mutex_lock(&gConsoleLock);
+ g_mutex_lock(&gConsoleLock);
if (gRefCount != 0 || GlibUtils_AttachConsole()) {
gRefCount++;
sdata->attached = TRUE;
}
- g_static_mutex_unlock(&gConsoleLock);
+ g_mutex_unlock(&gConsoleLock);
}
if (!sdata->attached) {
{
#if defined(_WIN32)
StdLogger *sdata = data;
- g_static_mutex_lock(&gConsoleLock);
+ g_mutex_lock(&gConsoleLock);
if (sdata->attached && --gRefCount == 0) {
FreeConsole();
}
- g_static_mutex_unlock(&gConsoleLock);
+ g_mutex_unlock(&gConsoleLock);
#endif
g_free(data);
}
/*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
static SysLogger *gSysLogger;
-static GStaticMutex gSysLoggerLock = G_STATIC_MUTEX_INIT;
+static GMutex gSysLoggerLock;
/*
{
g_return_if_fail(data == gSysLogger);
g_return_if_fail(gSysLogger->refcount > 0);
- g_static_mutex_lock(&gSysLoggerLock);
+ g_mutex_lock(&gSysLoggerLock);
gSysLogger->refcount -= 1;
if (gSysLogger->refcount == 0) {
closelog();
g_free(gSysLogger);
gSysLogger = NULL;
}
- g_static_mutex_unlock(&gSysLoggerLock);
+ g_mutex_unlock(&gSysLoggerLock);
}
GlibUtils_CreateSysLogger(const char *domain,
const char *facility)
{
- g_static_mutex_lock(&gSysLoggerLock);
+ g_mutex_lock(&gSysLoggerLock);
if (gSysLogger == NULL) {
int facid = LOG_USER;
} else {
gSysLogger->refcount += 1;
}
- g_static_mutex_unlock(&gSysLoggerLock);
+ g_mutex_unlock(&gSysLoggerLock);
return &gSysLogger->handler;
}
/*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
GDestroyNotify dtor);
void (*cancel)(guint id);
gboolean (*start)(ToolsAppCtx *ctx,
+ const gchar *threadName,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
* some other method of communicating with the thread.
*
* @param[in] ctx Application context.
+ * @param[in] threadName Name for the new thread.
* @param[in] cb Function that implements the task to execute.
* @param[in] interrupt A function that will request the task to be
* interrupted. This will be called when the pool
G_INLINE_FUNC gboolean
ToolsCorePool_StartThread(ToolsAppCtx *ctx,
+ const gchar *threadName,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
{
ToolsCorePool *pool = ToolsCorePool_GetPool(ctx);
if (pool != NULL) {
- return pool->start(ctx, cb, interrupt, data, dtor);
+ return pool->start(ctx, threadName, cb, interrupt, data, dtor);
}
return FALSE;
}
void *g_malloc0_n(size_t n, size_t s) { return Util_SafeCalloc(n, s); }
void g_free(void *p) { free(p); }
-GMutex* g_static_mutex_get_mutex_impl(GStaticMutex *mutex) { return NULL; }
-
-void g_static_mutex_free(GStaticMutex *mutex) { }
-void g_static_mutex_init(GStaticMutex *mutex) { }
+void g_mutex_init(GMutex *mutex) { }
+void g_mutex_clear(GMutex *mutex) { }
void g_mutex_lock(GMutex *mutex) { }
void g_mutex_unlock(GMutex *mutex) { }
gboolean chanStarted;
/* Synchronize with any RpcChannel_Send calls by other threads. */
- g_static_mutex_lock(&chan->impl.outLock);
+ g_mutex_lock(&chan->impl.outLock);
g_source_unref(chan->restartTimer);
chan->restartTimer = NULL;
gVSocketFailed = FALSE;
chanStarted = RpcChannel_Start(&chan->impl);
- g_static_mutex_unlock(&chan->impl.outLock);
+ g_mutex_unlock(&chan->impl.outLock);
if (!chanStarted) {
Warning("Channel restart failed [%d]\n", chan->rpcResetErrorCount);
if (chan->resetCb != NULL) {
return;
}
- g_static_mutex_lock(&chan->outLock);
+ g_mutex_lock(&chan->outLock);
RpcChannelStopNoLock(chan);
RpcChannelTeardown(chan);
#endif
- g_static_mutex_unlock(&chan->outLock);
+ g_mutex_unlock(&chan->outLock);
- g_static_mutex_free(&chan->outLock);
+ g_mutex_clear(&chan->outLock);
g_free(chan);
}
chan = BackdoorChannel_New();
#endif
if (chan) {
- g_static_mutex_init(&chan->outLock);
+ g_mutex_init(&chan->outLock);
}
return chan;
}
void
RpcChannel_Stop(RpcChannel *chan)
{
- g_static_mutex_lock(&chan->outLock);
+ g_mutex_lock(&chan->outLock);
RpcChannelStopNoLock(chan);
- g_static_mutex_unlock(&chan->outLock);
+ g_mutex_unlock(&chan->outLock);
}
ASSERT(chan && chan->funcs);
- g_static_mutex_lock(&chan->outLock);
+ g_mutex_lock(&chan->outLock);
funcs = chan->funcs;
ASSERT(funcs->send);
}
exit:
- g_static_mutex_unlock(&chan->outLock);
+ g_mutex_unlock(&chan->outLock);
return ok && rpcStatus;
}
const char *appName;
gpointer appCtx;
#endif
- GStaticMutex outLock;
+ GMutex outLock;
#if defined(NEED_RPCIN)
struct RpcIn *in;
gboolean inStarted;
/*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
typedef struct MsgState {
HashTable *domains; /* List of text domains. */
- GStaticMutex lock; /* Mutex to protect shared state. */
+ GMutex lock; /* Mutex to protect shared state. */
} MsgState;
{
ASSERT(gMsgState == NULL);
gMsgState = g_new0(MsgState, 1);
- g_static_mutex_init(&gMsgState->lock);
+ g_mutex_init(&gMsgState->lock);
return NULL;
}
* This lock is pretty coarse-grained, but a lot of the code below just runs
* in exceptional situations, so it should be OK.
*/
- g_static_mutex_lock(&state->lock);
+ g_mutex_lock(&state->lock);
catalog = MsgGetCatalog(domain);
if (catalog != NULL) {
}
}
- g_static_mutex_unlock(&state->lock);
+ g_mutex_unlock(&state->lock);
return strp;
}
if (gMsgState->domains != NULL) {
HashTable_Free(gMsgState->domains);
}
- g_static_mutex_free(&gMsgState->lock);
+ g_mutex_clear(&gMsgState->lock);
g_free(gMsgState);
}
}
"catalog dir '%s'.\n", domain, lang, catdir);
}
} else {
- g_static_mutex_lock(&state->lock);
+ g_mutex_lock(&state->lock);
MsgSetCatalog(domain, catalog);
- g_static_mutex_unlock(&state->lock);
+ g_mutex_unlock(&state->lock);
}
g_free(file);
free(dfltdir);
/*********************************************************
- * Copyright (C) 2008-2017 VMware, Inc. All rights reserved.
+ * Copyright (C) 2008-2018 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
gchar *defaultPath = NULL;
gchar *localPath = NULL;
/* GStatBuf was added in 2.26. */
-#if GLIB_CHECK_VERSION(2, 26, 0)
GStatBuf confStat;
-#else
- struct stat confStat;
-#endif
GHashTable *old = NULL;
GError *err = NULL;
GKeyFile *cfg = NULL;
g_source_unref(gBackupState->abortTimer);
}
- g_static_mutex_lock(&gBackupState->opLock);
+ g_mutex_lock(&gBackupState->opLock);
if (gBackupState->currentOp != NULL) {
VmBackup_Cancel(gBackupState->currentOp);
VmBackup_Release(gBackupState->currentOp);
}
- g_static_mutex_unlock(&gBackupState->opLock);
+ g_mutex_unlock(&gBackupState->opLock);
VmBackup_SendEvent(VMBACKUP_EVENT_REQUESTOR_DONE, VMBACKUP_SUCCESS, "");
if (gBackupState->completer != NULL) {
gBackupState->completer->release(gBackupState->completer);
}
- g_static_mutex_free(&gBackupState->opLock);
+ g_mutex_clear(&gBackupState->opLock);
g_free(gBackupState->scriptArg);
g_free(gBackupState->volumes);
g_free(gBackupState->snapshots);
gBackupState->machineState != VMBACKUP_MSTATE_SYNC_ERROR) {
const char *eventMsg = "Quiesce aborted.";
/* Mark the current operation as cancelled. */
- g_static_mutex_lock(&gBackupState->opLock);
+ g_mutex_lock(&gBackupState->opLock);
if (gBackupState->currentOp != NULL) {
VmBackup_Cancel(gBackupState->currentOp);
VmBackup_Release(gBackupState->currentOp);
gBackupState->currentOp = NULL;
}
- g_static_mutex_unlock(&gBackupState->opLock);
+ g_mutex_unlock(&gBackupState->opLock);
#ifdef __linux__
/* Thaw the guest if already quiesced */
*pending = FALSE;
- g_static_mutex_lock(&gBackupState->opLock);
+ g_mutex_lock(&gBackupState->opLock);
if (gBackupState->currentOp != NULL) {
g_debug("%s: checking %s\n", __FUNCTION__, gBackupState->currentOpName);
}
exit:
- g_static_mutex_unlock(&gBackupState->opLock);
+ g_mutex_unlock(&gBackupState->opLock);
return retVal;
}
gBackupState->provider = provider;
gBackupState->completer = completer;
gBackupState->needsPriv = FALSE;
- g_static_mutex_init(&gBackupState->opLock);
+ g_mutex_init(&gBackupState->opLock);
gBackupState->enableNullDriver = VMBACKUP_CONFIG_GET_BOOL(ctx->config,
"enableNullDriver",
TRUE);
ToolsAppCtx *ctx;
VmBackupOp *currentOp;
const char *currentOpName;
- GStaticMutex opLock; // See note above
+ GMutex opLock; // See note above
char *volumes;
char *snapshots;
guint pollPeriod;
ASSERT(state->currentOp == NULL);
ASSERT(currentOpName != NULL);
- g_static_mutex_lock(&state->opLock);
+ g_mutex_lock(&state->opLock);
state->currentOp = op;
state->callback = callback;
state->currentOpName = currentOpName;
state->forceRequeue = (callback != NULL && op == NULL);
- g_static_mutex_unlock(&state->opLock);
+ g_mutex_unlock(&state->opLock);
return (op != NULL);
}
}
context = g_option_context_new(NULL);
-#if GLIB_CHECK_VERSION(2, 12, 0)
g_option_context_set_summary(context, N_("Runs the VMware Tools daemon."));
-#endif
g_option_context_add_main_entries(context, clOptions, NULL);
g_option_group_set_error_hook(g_option_context_get_main_group(context),
ToolsCoreCmdLineError);
GMainContext *gctx;
ToolsServiceProperty ctxProp = { TOOLS_CORE_PROP_CTX };
- if (!g_thread_supported()) {
- g_thread_init(NULL);
- }
-
/*
* Useful for debugging purposes. Log the vesion and build information.
*/
id -= 1;
- g_mutex_lock(self->lock);
+ g_mutex_lock(&self->lock);
if (id < self->props->len) {
ServiceProperty *p = &g_array_index(self->props, ServiceProperty, id);
g_value_set_pointer(value, p->value);
}
- g_mutex_unlock(self->lock);
+ g_mutex_unlock(&self->lock);
}
id -= 1;
- g_mutex_lock(self->lock);
+ g_mutex_lock(&self->lock);
if (id < self->props->len) {
p = &g_array_index(self->props, ServiceProperty, id);
p->value = g_value_get_pointer(value);
}
- g_mutex_unlock(self->lock);
+ g_mutex_unlock(&self->lock);
if (p != NULL) {
g_object_notify(object, p->name);
params);
self = TOOLSCORE_SERVICE(object);
- self->lock = g_mutex_new();
+ g_mutex_init(&self->lock);
self->props = g_array_new(FALSE, FALSE, sizeof (ServiceProperty));
return object;
}
g_array_free(self->props, TRUE);
- g_mutex_free(self->lock);
+ g_mutex_clear(&self->lock);
}
prop->name,
G_PARAM_READWRITE);
- g_mutex_lock(obj->lock);
+ g_mutex_lock(&obj->lock);
sprop.id = ++PROP_ID_SEQ;
sprop.name = g_strdup(prop->name);
g_array_append_val(obj->props, sprop);
g_object_class_install_property(G_OBJECT_CLASS(klass), sprop.id, pspec);
- g_mutex_unlock(obj->lock);
+ g_mutex_unlock(&obj->lock);
}
/*********************************************************
- * Copyright (C) 2009-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2009-2018 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
typedef struct ToolsCoreService {
GObject parent;
- GMutex *lock;
+ GMutex lock;
GArray *props;
} ToolsCoreService;
/*********************************************************
- * Copyright (C) 2010-2016 VMware, Inc. All rights reserved.
+ * Copyright (C) 2010-2018 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
GThreadPool *pool;
GQueue *workQueue;
GPtrArray *threads;
- GMutex *lock;
+ GMutex lock;
guint nextWorkId;
} ThreadPoolState;
* In multi-threaded mode, the thread pool callback already did this.
*/
if (gState.pool == NULL) {
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
g_queue_remove(gState.workQueue, work);
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
}
work->cb(gState.ctx, work->data);
task->cb(gState.ctx, task->data);
task->active = FALSE;
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
/* If not active, the shutdown function will clean things up. */
if (gState.active) {
g_ptr_array_remove(gState.threads, task);
task,
ToolsCorePoolDestroyThread);
}
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
return NULL;
}
{
WorkerTask *work;
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
work = g_queue_pop_tail(gState.workQueue);
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
ASSERT(work != NULL);
task->data = data;
task->dtor = dtor;
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
if (!gState.active) {
g_free(task);
ToolsCorePoolDestroyTask);
exit:
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
return id;
}
g_return_if_fail(id != 0);
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
if (!gState.active) {
goto exit;
}
}
exit:
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
if (task != NULL) {
if (task->srcId > 0) {
*
* @see ToolsCorePool_StartThread()
*
- * @param[in] ctx Application context.
- * @param[in] cb Callback that executes the task.
- * @param[in] interrupt Callback that interrupts the task.
- * @param[in] data Opaque data.
- * @param[in] dtor Destructor for the task data.
+ * @param[in] ctx Application context.
+ * @param[in] threadName Name for the new thread.
+ * @param[in] cb Callback that executes the task.
+ * @param[in] interrupt Callback that interrupts the task.
+ * @param[in] data Opaque data.
+ * @param[in] dtor Destructor for the task data.
*
* @return TRUE iff thread was successfully started.
*
static gboolean
ToolsCorePoolStart(ToolsAppCtx *ctx,
+ const gchar *threadName,
ToolsCorePoolCb cb,
ToolsCorePoolCb interrupt,
gpointer data,
GError *err = NULL;
StandaloneTask *task = NULL;
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
if (!gState.active) {
goto exit;
}
task->interrupt = interrupt;
task->data = data;
task->dtor = dtor;
- task->thread = g_thread_create(ToolsCorePoolRunThread, task, TRUE, &err);
+ task->thread = g_thread_try_new(threadName, ToolsCorePoolRunThread, task, &err);
if (err == NULL) {
g_ptr_array_add(gState.threads, task);
}
exit:
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
return task != NULL;
}
gState.pool = g_thread_pool_new(ToolsCorePoolRunWorker,
NULL, maxThreads, FALSE, &err);
if (err == NULL) {
-#if GLIB_CHECK_VERSION(2, 10, 0)
gint maxIdleTime;
gint maxUnused;
g_thread_pool_set_max_idle_time(maxIdleTime);
g_thread_pool_set_max_unused_threads(maxUnused);
-#endif
} else {
g_warning("error initializing thread pool, running single threaded: %s",
err->message);
}
gState.active = TRUE;
- gState.lock = g_mutex_new();
+ g_mutex_init(&gState.lock);
gState.threads = g_ptr_array_new();
gState.workQueue = g_queue_new();
{
guint i;
- g_mutex_lock(gState.lock);
+ g_mutex_lock(&gState.lock);
gState.active = FALSE;
- g_mutex_unlock(gState.lock);
+ g_mutex_unlock(&gState.lock);
/* Notify all spawned threads to stop. */
for (i = 0; i < gState.threads->len; i++) {
/* Cleanup. */
g_ptr_array_free(gState.threads, TRUE);
g_queue_free(gState.workQueue);
- g_mutex_free(gState.lock);
+ g_mutex_clear(&gState.lock);
memset(&gState, 0, sizeof gState);
g_object_set(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, NULL, NULL);
}
}
ret = ToolsCorePool_StartThread(ctx,
+ "HangDetector",
DetectorThread,
DetectorTerminate,
NULL,
if (g_file_test(path, G_FILE_TEST_EXISTS)) {
/* GStatBuf was added in 2.26. */
-#if GLIB_CHECK_VERSION(2, 26, 0)
GStatBuf fstats;
-#else
- struct stat fstats;
-#endif
if (g_stat(path, &fstats) > -1) {
g_atomic_int_set(&data->logSize, (gint) fstats.st_size);