X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fnmem.c;h=981c22c07a9568c61319aa436f06132c0ab3ed5c;hp=99d22cdc86163142c4f631f9e40e522dbde5cfc7;hb=5379711b958f1b4ae4148b1734f618e71b3dd6ef;hpb=044d170f0a963555486df54653cd2fdc5815928b diff --git a/util/nmem.c b/util/nmem.c index 99d22cd..981c22c 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -1,10 +1,17 @@ /* - * Copyright (c) 1995-1997, Index Data. + * Copyright (c) 1995-1998, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.7 1998-02-11 11:53:36 adam + * Revision 1.9 1998-07-07 15:49:01 adam + * Reduced chunk size. + * + * Revision 1.8 1998/07/03 14:21:27 adam + * Added critical sections for pthreads-library. Thanks to Ian Ibbotson, + * Fretwell Downing Informatics. + * + * Revision 1.7 1998/02/11 11:53:36 adam * Changed code so that it compiles as C++. * * Revision 1.6 1997/10/31 12:20:09 adam @@ -41,14 +48,20 @@ #include #ifdef WINDOWS #include +#elif _REENTRANT +#include #endif -#define NMEM_CHUNK (10*1024) +#define NMEM_CHUNK (4*1024) #ifdef WINDOWS 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; +#define NMEM_ENTER pthread_mutex_lock(&nmem_mutex); +#define NMEM_LEAVE pthread_mutex_unlock(&nmem_mutex); #else #define NMEM_ENTER #define NMEM_LEAVE @@ -75,10 +88,12 @@ static nmem_block *get_block(int size) if (r->size >= size) break; if (r) + { if (l) l->next = r->next; else freelist = r->next; + } else { int get = NMEM_CHUNK;