X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fnmem.c;h=244dc6b11ab83ed2f43db3adb3effaec7dbc2d75;hp=ea9a9b88a73c528b4820e7743ecf10592d7ff878;hb=81503ca4c08bfaf4eb6782a9207cc33fa941a442;hpb=068a5a7412f492019b4d6f5e89158098d44368f7 diff --git a/util/nmem.c b/util/nmem.c index ea9a9b8..244dc6b 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.6 1997-10-31 12:20:09 adam + * 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 * Improved memory debugging for xmalloc/nmem.c. References to NMEM * instead of ODR in n ESPEC-1 handling in source d1_espec.c. * Bug fix: missing fclose in data1_read_espec1. @@ -38,6 +45,8 @@ #include #ifdef WINDOWS #include +#elif _REENTRANT +#include #endif #define NMEM_CHUNK (10*1024) @@ -46,6 +55,10 @@ 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 @@ -82,8 +95,8 @@ static nmem_block *get_block(int size) if (get < size) get = size; - r = xmalloc(sizeof(*r)); - r->buf = xmalloc(r->size = get); + r = (nmem_block *)xmalloc(sizeof(*r)); + r->buf = (char *)xmalloc(r->size = get); } r->top = 0; return r; @@ -148,7 +161,7 @@ NMEM nmem_create(void) if (r) cfreelist = cfreelist->next; else - r = xmalloc(sizeof(*r)); + r = (nmem_control *)xmalloc(sizeof(*r)); NMEM_LEAVE; #if NMEM_DEBUG