X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fnmem.c;h=5f55cee7acd9d003dfa3c46931c10434673a5cf9;hp=418962ab3ae98bd05d42f84b14bb5216138c4429;hb=a49837cbe6fcbeeb9ce857b0eeb942619ba80b5e;hpb=9fc822fe67ef4f5a898d9a85fbae7dd9a3435023 diff --git a/util/nmem.c b/util/nmem.c index 418962a..5f55cee 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -4,7 +4,17 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.10 1998-07-20 12:35:57 adam + * Revision 1.13 1998-10-19 15:24:21 adam + * New nmem utility, nmem_transfer, that transfer blocks from one + * NMEM to another. + * + * Revision 1.12 1998/10/13 16:00:18 adam + * Implemented nmem_critical_{enter,leave}. + * + * Revision 1.11 1998/08/21 14:13:36 adam + * Added GNU Configure script to build Makefiles. + * + * Revision 1.10 1998/07/20 12:35:57 adam * Added more memory diagnostics (when NMEM_DEBUG is 1). * * Revision 1.9 1998/07/07 15:49:01 adam @@ -52,7 +62,13 @@ #ifdef WINDOWS #include #elif _REENTRANT + +#if HAVE_PTHREAD_H #include +#elif HAVE_THREAD_H +#include +#endif + #endif #define NMEM_CHUNK (4*1024) @@ -62,7 +78,7 @@ static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) #define NMEM_LEAVE LeaveCriticalSection(&critical_section) #elif _REENTRANT -static pthread_mutex_t nmem_mutex; +static pthread_mutex_t nmem_mutex = PTHREAD_MUTEX_INITIALIZER; #define NMEM_ENTER pthread_mutex_lock(&nmem_mutex); #define NMEM_LEAVE pthread_mutex_unlock(&nmem_mutex); #else @@ -138,8 +154,8 @@ void nmem_reset(NMEM n) n->blocks = n->blocks->next; free_block(t); } - NMEM_LEAVE; n->total = 0; + NMEM_LEAVE; } #if NMEM_DEBUG @@ -225,6 +241,29 @@ void nmem_destroy(NMEM n) #endif } +void nmem_transfer (NMEM dst, NMEM src) +{ + nmem_block *t; + while ((t=src->blocks)) + { + src->blocks = t->next; + t->next = dst->blocks; + dst->blocks = t; + } + dst->total += src->total; + src->total = 0; +} + +void nmem_critical_enter (void) +{ + NMEM_ENTER; +} + +void nmem_critical_leave (void) +{ + NMEM_LEAVE; +} + void nmem_init (void) { #ifdef WINDOWS