X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=util%2Fnmem.c;h=518226ba46992b6ae52ca87effab3041e5376cee;hb=febd96e724a673b84f5db8f48dfb71c805c7f5e6;hp=4f458471b36b1917249e534e871e91281bc288d8;hpb=1fbf9907e66c5697b9537a1a4849295c05b12b6b;p=yaz-moved-to-github.git diff --git a/util/nmem.c b/util/nmem.c index 4f45847..518226b 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -1,10 +1,24 @@ /* - * Copyright (c) 1995-1998, Index Data. + * Copyright (c) 1995-1999, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.11 1998-08-21 14:13:36 adam + * Revision 1.15 1999-02-11 09:10:26 adam + * Function nmem_init only mandatory on Windows. + * + * Revision 1.14 1999/02/02 13:57:40 adam + * Uses preprocessor define WIN32 instead of WINDOWS to build code + * for Microsoft WIN32. + * + * 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 @@ -49,10 +63,11 @@ * allocation. Evemtually we'll put in something better. */ +#include #include #include #include -#ifdef WINDOWS +#ifdef WIN32 #include #elif _REENTRANT @@ -66,7 +81,7 @@ #define NMEM_CHUNK (4*1024) -#ifdef WINDOWS +#ifdef WIN32 static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) #define NMEM_LEAVE LeaveCriticalSection(&critical_section) @@ -82,6 +97,7 @@ static pthread_mutex_t nmem_mutex = PTHREAD_MUTEX_INITIALIZER; static nmem_block *freelist = NULL; /* "global" freelists */ static nmem_control *cfreelist = NULL; static int nmem_active_no = 0; +static int nmem_init_flag = 0; static void free_block(nmem_block *p) { @@ -147,8 +163,8 @@ void nmem_reset(NMEM n) n->blocks = n->blocks->next; free_block(t); } - NMEM_LEAVE; n->total = 0; + NMEM_LEAVE; } #if NMEM_DEBUG @@ -166,6 +182,9 @@ void *nmem_malloc(NMEM n, int size) #endif if (!n) return xmalloc(size); +#ifdef WIN32 + assert (nmem_init_flag); +#endif NMEM_ENTER; p = n->blocks; if (!p || p->size - p->top < size) @@ -234,9 +253,33 @@ 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 + nmem_init_flag = 1; +#ifdef WIN32 InitializeCriticalSection(&critical_section); #endif nmem_active_no = 0; @@ -259,7 +302,7 @@ void nmem_exit (void) cfreelist = cfreelist->next; xfree (cfl); } -#ifdef WINDOWS +#ifdef WIN32 DeleteCriticalSection(&critical_section); #endif }