};
static GMutex *smc_tree_mutex = NULL; /* mutex for G_SLICE=debug-blocks */
+#ifndef G_OS_WIN32
+
+#include <pthread.h>
+static pthread_mutex_t sdt_mutex = PTHREAD_MUTEX_INITIALIZER;
+#define SDT_LOCK() pthread_mutex_lock (&sdt_mutex)
+#define SDT_UNLOCK() pthread_mutex_unlock (&sdt_mutex)
+
+#else
+
+/* We don't want to depend on pthreads on Win32, at least for now. But
+ * if we change GThread to use pthreads-win32 we could use pthreads
+ * here, too.
+ */
+
+static CRITICAL_SECTION sdt_mutex;
+#define SDT_LOCK() EnterCriticalSection (&sdt_mutex)
+#define SDT_UNLOCK() LeaveCriticalSection (&sdt_mutex)
+
+#endif
+
/* --- auxillary funcitons --- */
void
g_slice_set_config (GSliceConfig ckey,
allocator->magazine_mutex = g_mutex_new();
allocator->slab_mutex = g_mutex_new();
if (allocator->config.debug_blocks)
- smc_tree_mutex = g_mutex_new();
+ {
+ smc_tree_mutex = g_mutex_new();
+#ifdef G_OS_WIN32
+ InitializeCriticalSection (&sdt_mutex);
+#endif
+ }
}
static inline void
return cmp > 0 ? check + 1 : check; /* return insertion position for inexact match */
}
-#include <pthread.h>
-static pthread_mutex_t sdt_mutex = PTHREAD_MUTEX_INITIALIZER;
-
static void
smc_tree_insert (SmcKType key,
SmcVType value)
{
- pthread_mutex_lock (&sdt_mutex);
+ SDT_LOCK ();
g_mutex_lock (smc_tree_mutex);
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
if (!smc_tree_root)
entry->key = key;
entry->value = value;
g_mutex_unlock (smc_tree_mutex);
- pthread_mutex_unlock (&sdt_mutex);
+ SDT_UNLOCK ();
}
static gboolean
{
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
gboolean found_one = FALSE;
- pthread_mutex_lock (&sdt_mutex);
+ SDT_LOCK ();
*value_p = 0;
g_mutex_lock (smc_tree_mutex);
SmcEntry *entry = NULL;
}
}
g_mutex_unlock (smc_tree_mutex);
- pthread_mutex_unlock (&sdt_mutex);
+ SDT_UNLOCK ();
return found_one;
}
{
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
gboolean found_one = FALSE;
- pthread_mutex_lock (&sdt_mutex);
+ SDT_LOCK ();
g_mutex_lock (smc_tree_mutex);
if (smc_tree_root && smc_tree_root[ix0])
{
}
}
g_mutex_unlock (smc_tree_mutex);
- pthread_mutex_unlock (&sdt_mutex);
+ SDT_UNLOCK ();
return found_one;
}
void
g_slice_debug_tree_statistics (void)
{
- pthread_mutex_lock (&sdt_mutex);
+ SDT_LOCK ();
g_mutex_lock (smc_tree_mutex);
if (smc_tree_root)
{
else
fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
g_mutex_unlock (smc_tree_mutex);
- pthread_mutex_unlock (&sdt_mutex);
+ SDT_UNLOCK ();
/* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
* PID %CPU %MEM VSZ RSS COMMAND