X-Git-Url: http://jsfdemo.indexdata.com/?a=blobdiff_plain;f=util%2Fnmem.c;h=70c90145c2a441c4f2623f5dff99ba4a689245e4;hb=fd4adcc80d442f84c6a1894e890b1b6ccd02615e;hp=1b191c4da266a14422409ccfe6a27b4af47aec32;hpb=c9b1ffcb5d47aa1cd0c0812c55bd1a3301cf834c;p=yaz-moved-to-github.git diff --git a/util/nmem.c b/util/nmem.c index 1b191c4..70c9014 100644 --- a/util/nmem.c +++ b/util/nmem.c @@ -4,7 +4,16 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: nmem.c,v $ - * Revision 1.29 2001-10-04 00:37:58 adam + * Revision 1.32 2001-11-13 23:00:43 adam + * Separate malloc debug library. Removal of ASN_COMPILED-#ifdefs. + * + * Revision 1.31 2001/10/24 12:24:43 adam + * WIN32 updates: ZOOM runs, nmem_init/nmem_exit called in DllMain. + * + * Revision 1.30 2001/10/05 13:55:17 adam + * Added defines YAZ_GNU_THREADS, YAZ_POSIX_THREADS in code and yaz-config + * + * 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 @@ -119,13 +128,12 @@ #include #endif -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +#if YAZ_POSIX_THREADS #include -#elif HAVE_PTH_H -#include #endif +#if YAZ_GNU_THREADS +#include #endif #define NMEM_CHUNK (4*1024) @@ -134,40 +142,30 @@ static CRITICAL_SECTION critical_section; #define NMEM_ENTER EnterCriticalSection(&critical_section) #define NMEM_LEAVE LeaveCriticalSection(&critical_section) -#endif - -#ifdef _REENTRANT -#if HAVE_PTHREAD_H +struct nmem_mutex { + CRITICAL_SECTION m_handle; +}; +#elif YAZ_POSIX_THREADS 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; +struct nmem_mutex { + pthread_mutex_t m_handle; +}; +#elif YAZ_GNU_THREADS +static pth_mutex_t nmem_mutex = PTH_MUTEX_INIT; #define NMEM_ENTER pth_mutex_acquire(&nmem_mutex, 0, 0) #define NMEM_LEAVE pth_mutex_release(&nmem_mutex) -#else -#error x -#endif +struct nmem_mutex { + pth_mutex_t m_handle; +}; #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 + int dummy; }; +#endif YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) { @@ -177,8 +175,10 @@ YAZ_EXPORT void nmem_mutex_create(NMEM_MUTEX *p) *p = (NMEM_MUTEX) malloc (sizeof(**p)); #ifdef WIN32 InitializeCriticalSection(&(*p)->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_init (&(*p)->m_handle, 0); +#elif YAZ_GNU_THREADS + pth_mutex_init (&(*p)->m_handle); #endif } NMEM_LEAVE; @@ -190,7 +190,7 @@ YAZ_EXPORT void nmem_mutex_enter(NMEM_MUTEX p) { #ifdef WIN32 EnterCriticalSection(&p->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_lock(&p->m_handle); #endif } @@ -202,7 +202,7 @@ YAZ_EXPORT void nmem_mutex_leave(NMEM_MUTEX p) { #ifdef WIN32 LeaveCriticalSection(&p->m_handle); -#elif _REENTRANT +#elif YAZ_POSIX_THREADS pthread_mutex_unlock(&p->m_handle); #endif } @@ -225,7 +225,11 @@ YAZ_EXPORT void nmem_mutex_destroy(NMEM_MUTEX *p) static nmem_block *freelist = NULL; /* "global" freelists */ static nmem_control *cfreelist = NULL; static int nmem_active_no = 0; +#ifdef WIN32 static int nmem_init_flag = 0; +#else +static int nmem_init_flag = 1; +#endif #if NMEM_DEBUG struct nmem_debug_info { @@ -481,14 +485,9 @@ void nmem_init (void) { #ifdef WIN32 InitializeCriticalSection(&critical_section); -#endif - -#ifdef _REENTRANT -#if HAVE_PTH_H +#elif YAZ_GNU_THREADS yaz_log (LOG_LOG, "pth_init"); pth_init (); - pth_mutex_init (&nmem_mutex); -#endif #endif nmem_active_no = 0; freelist = NULL; @@ -500,6 +499,7 @@ void nmem_exit (void) { if (--nmem_init_flag == 0) { + yaz_log (LOG_LOG, "nmem_exit ............."); oid_exit(); while (freelist) { @@ -520,3 +520,20 @@ void nmem_exit (void) } } + +#ifdef WIN32 +BOOL WINAPI DllMain (HINSTANCE hinstDLL, + DWORD reason, + LPVOID reserved) +{ + switch (reason) + { + case DLL_PROCESS_ATTACH: + nmem_init (); + break; + case DLL_PROCESS_DETACH: + nmem_exit (); + } + return TRUE; +} +#endif