X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=util%2Fnmem.c;h=1b191c4da266a14422409ccfe6a27b4af47aec32;hp=d337d3fc9cca476f4aac71de3754eafa43c6d890;hb=c9b1ffcb5d47aa1cd0c0812c55bd1a3301cf834c;hpb=a9407df0295ee7745827b2f053b3f4698857720d diff --git a/util/nmem.c b/util/nmem.c index d337d3f..1b191c4 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -1,10 +1,22 @@ /* - * Copyright (c) 1995-2000, Index Data. + * Copyright (c) 1995-2001, Index Data. * See the file LICENSE for details. * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.25 2001-06-26 14:11:27 adam + * Revision 1.29 2001-10-04 00:37:58 adam + * Fixes for GNU threads (not working yet). + * + * Revision 1.28 2001/10/03 23:55:18 adam + * GNU threads support. + * + * Revision 1.27 2001/09/27 12:09:18 adam + * Function nmem_exit calls oid_exit (when reference is 0). + * + * Revision 1.26 2001/07/19 19:51:42 adam + * Added typecasts to make C++ happy. + * + * Revision 1.25 2001/06/26 14:11:27 adam * Added MUTEX functions for NMEM module (used by OID utility). * * Revision 1.24 2000/05/11 14:37:55 adam @@ -101,14 +113,17 @@ #include #include #include +#include + #ifdef WIN32 #include -#elif _REENTRANT +#endif +#ifdef _REENTRANT #if HAVE_PTHREAD_H #include -#elif HAVE_THREAD_H -#include +#elif HAVE_PTH_H +#include #endif #endif @@ -119,21 +134,36 @@ static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) #define NMEM_LEAVE LeaveCriticalSection(&critical_section) -#elif _REENTRANT +#endif + +#ifdef _REENTRANT +#if HAVE_PTHREAD_H 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); +#elif HAVE_PTH_H +static pth_mutex_t nmem_mutex; +#define NMEM_ENTER pth_mutex_acquire(&nmem_mutex, 0, 0) +#define NMEM_LEAVE pth_mutex_release(&nmem_mutex) +#else +#error x +#endif #else #define NMEM_ENTER #define NMEM_LEAVE #endif - struct nmem_mutex { #ifdef WIN32 CRITICAL_SECTION m_handle; #elif _REENTRANT + +#if HAVE_PTHREAD_H pthread_mutex_t m_handle; +#elif HAVE_PTH_H + pth_mutex_t m_handle; +#endif + #else int m_handle; #endif @@ -144,7 +174,7 @@ YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) NMEM_ENTER; if (!*p) { - *p = malloc (sizeof(**p)); + *p = (NMEM_MUTEX) malloc (sizeof(**p)); #ifdef WIN32 InitializeCriticalSection(&(*p)->m_handle); #elif _REENTRANT @@ -452,6 +482,14 @@ void nmem_init (void) #ifdef WIN32 InitializeCriticalSection(&critical_section); #endif + +#ifdef _REENTRANT +#if HAVE_PTH_H + yaz_log (LOG_LOG, "pth_init"); + pth_init (); + pth_mutex_init (&nmem_mutex); +#endif +#endif nmem_active_no = 0; freelist = NULL; cfreelist = NULL; @@ -462,6 +500,7 @@ void nmem_exit (void) { if (--nmem_init_flag == 0) { + oid_exit(); while (freelist) { struct nmem_block *fl = freelist;