mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
Make it compile on Win32 without pthreads: Use a Win32 critical section
2006-12-28 Tor Lillqvist <tml@novell.com> * glib/gslice.c: Make it compile on Win32 without pthreads: Use a Win32 critical section instead.
This commit is contained in:
parent
fd1f409e41
commit
b713fbc11a
@ -1,5 +1,8 @@
|
|||||||
2006-12-28 Tor Lillqvist <tml@novell.com>
|
2006-12-28 Tor Lillqvist <tml@novell.com>
|
||||||
|
|
||||||
|
* glib/gslice.c: Make it compile on Win32 without pthreads: Use a
|
||||||
|
Win32 critical section instead.
|
||||||
|
|
||||||
* glib/gmessages.c (g_logv): On Win32, if we get a fatal error
|
* glib/gmessages.c (g_logv): On Win32, if we get a fatal error
|
||||||
message while being debugged we break into the debugger with
|
message while being debugged we break into the debugger with
|
||||||
G_BREAKPOINT(). Don't call abort() if the user is foolhardy enough
|
G_BREAKPOINT(). Don't call abort() if the user is foolhardy enough
|
||||||
|
@ -203,6 +203,26 @@ static SliceConfig slice_config = {
|
|||||||
};
|
};
|
||||||
static GMutex *smc_tree_mutex = NULL; /* mutex for G_SLICE=debug-blocks */
|
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 --- */
|
/* --- auxillary funcitons --- */
|
||||||
void
|
void
|
||||||
g_slice_set_config (GSliceConfig ckey,
|
g_slice_set_config (GSliceConfig ckey,
|
||||||
@ -376,7 +396,12 @@ _g_slice_thread_init_nomessage (void)
|
|||||||
allocator->magazine_mutex = g_mutex_new();
|
allocator->magazine_mutex = g_mutex_new();
|
||||||
allocator->slab_mutex = g_mutex_new();
|
allocator->slab_mutex = g_mutex_new();
|
||||||
if (allocator->config.debug_blocks)
|
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
|
static inline void
|
||||||
@ -1280,14 +1305,11 @@ smc_tree_branch_lookup_nearest_L (SmcBranch *branch,
|
|||||||
return cmp > 0 ? check + 1 : check; /* return insertion position for inexact match */
|
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
|
static void
|
||||||
smc_tree_insert (SmcKType key,
|
smc_tree_insert (SmcKType key,
|
||||||
SmcVType value)
|
SmcVType value)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock (&sdt_mutex);
|
SDT_LOCK ();
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (smc_tree_mutex);
|
||||||
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
||||||
if (!smc_tree_root)
|
if (!smc_tree_root)
|
||||||
@ -1310,7 +1332,7 @@ smc_tree_insert (SmcKType key,
|
|||||||
entry->key = key;
|
entry->key = key;
|
||||||
entry->value = value;
|
entry->value = value;
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (smc_tree_mutex);
|
||||||
pthread_mutex_unlock (&sdt_mutex);
|
SDT_UNLOCK ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@ -1319,7 +1341,7 @@ smc_tree_lookup (SmcKType key,
|
|||||||
{
|
{
|
||||||
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
||||||
gboolean found_one = FALSE;
|
gboolean found_one = FALSE;
|
||||||
pthread_mutex_lock (&sdt_mutex);
|
SDT_LOCK ();
|
||||||
*value_p = 0;
|
*value_p = 0;
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (smc_tree_mutex);
|
||||||
SmcEntry *entry = NULL;
|
SmcEntry *entry = NULL;
|
||||||
@ -1335,7 +1357,7 @@ smc_tree_lookup (SmcKType key,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (smc_tree_mutex);
|
||||||
pthread_mutex_unlock (&sdt_mutex);
|
SDT_UNLOCK ();
|
||||||
return found_one;
|
return found_one;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1344,7 +1366,7 @@ smc_tree_remove (SmcKType key)
|
|||||||
{
|
{
|
||||||
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
unsigned int ix0 = SMC_TRUNK_HASH (key), ix1 = SMC_BRANCH_HASH (key);
|
||||||
gboolean found_one = FALSE;
|
gboolean found_one = FALSE;
|
||||||
pthread_mutex_lock (&sdt_mutex);
|
SDT_LOCK ();
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (smc_tree_mutex);
|
||||||
if (smc_tree_root && smc_tree_root[ix0])
|
if (smc_tree_root && smc_tree_root[ix0])
|
||||||
{
|
{
|
||||||
@ -1366,7 +1388,7 @@ smc_tree_remove (SmcKType key)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (smc_tree_mutex);
|
||||||
pthread_mutex_unlock (&sdt_mutex);
|
SDT_UNLOCK ();
|
||||||
return found_one;
|
return found_one;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1374,7 +1396,7 @@ smc_tree_remove (SmcKType key)
|
|||||||
void
|
void
|
||||||
g_slice_debug_tree_statistics (void)
|
g_slice_debug_tree_statistics (void)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock (&sdt_mutex);
|
SDT_LOCK ();
|
||||||
g_mutex_lock (smc_tree_mutex);
|
g_mutex_lock (smc_tree_mutex);
|
||||||
if (smc_tree_root)
|
if (smc_tree_root)
|
||||||
{
|
{
|
||||||
@ -1408,7 +1430,7 @@ g_slice_debug_tree_statistics (void)
|
|||||||
else
|
else
|
||||||
fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
|
fprintf (stderr, "GSlice: MemChecker: root=NULL\n");
|
||||||
g_mutex_unlock (smc_tree_mutex);
|
g_mutex_unlock (smc_tree_mutex);
|
||||||
pthread_mutex_unlock (&sdt_mutex);
|
SDT_UNLOCK ();
|
||||||
|
|
||||||
/* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
|
/* sample statistics (beast + GSLice + 24h scripted core & GUI activity):
|
||||||
* PID %CPU %MEM VSZ RSS COMMAND
|
* PID %CPU %MEM VSZ RSS COMMAND
|
||||||
|
Loading…
x
Reference in New Issue
Block a user