--- deliantra/server/common/utils.C 2007/11/08 19:43:24 1.68 +++ deliantra/server/common/utils.C 2008/04/02 11:13:53 1.73 @@ -471,7 +471,7 @@ void *salloc_ (int n) throw (std::bad_alloc) { -#ifdef PREFER_MALLOC +#if PREFER_MALLOC void *ptr = malloc (n); #else slice_alloc += n; @@ -496,6 +496,46 @@ return ptr; } +/******************************************************************************/ + +#if DEBUG_SALLOC + +#define MAGIC 0xa1b2c35543deadLL + +void *g_slice_alloc (unsigned long size) +{ + unsigned long *p = (unsigned long *) (g_slice_alloc)(size + sizeof (unsigned long)); + *p++ = size ^ MAGIC; + //fprintf (stderr, "g_slice_alloc %ld %p\n", size, p);//D + return (void *)p; +} + +void *g_slice_alloc0 (unsigned long size) +{ + return memset (g_slice_alloc (size), 0, size); +} + +void g_slice_free1 (unsigned long size, void *ptr) +{ + if (expect_true (ptr)) + { + //fprintf (stderr, "g_slice_free %ld %p\n", size, ptr);//D + unsigned long *p = (unsigned long *)ptr; + unsigned long s = *--p ^ MAGIC; + + if (size != (unsigned long)(*p ^ MAGIC)) + LOG (logBacktrace | llevError, "slice free size (%lx) doesn't match alloc size (%lx)\n", size, s); + + *p = MAGIC; + + (g_slice_free1)(s + sizeof (unsigned long), p); + } +} + +#endif + +/******************************************************************************/ + void assign (char *dst, const char *src, int maxlen) { if (!src) @@ -610,3 +650,15 @@ 0x2d02ef8dL }; +void thread::start (void *(*start_routine)(void *), void *arg) +{ + sigset_t fullsigset, oldsigset; + sigfillset (&fullsigset); + + pthread_sigmask (SIG_SETMASK, &fullsigset, &oldsigset); + + if (pthread_create (&id, 0, start_routine, arg)) + cleanup ("unable to create a new thread"); + + pthread_sigmask (SIG_SETMASK, &oldsigset, 0); +}