* Sebastian Hammer, Adam Dickmeiss
*
* $Log: nmem.c,v $
- * Revision 1.10 1998-07-20 12:35:57 adam
+ * 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
* Added more memory diagnostics (when NMEM_DEBUG is 1).
*
* Revision 1.9 1998/07/07 15:49:01 adam
#ifdef WINDOWS
#include <windows.h>
#elif _REENTRANT
+
+#if HAVE_PTHREAD_H
#include <pthread.h>
+#elif HAVE_THREAD_H
+#include <thread.h>
+#endif
+
#endif
#define NMEM_CHUNK (4*1024)
#define NMEM_ENTER EnterCriticalSection(&critical_section)
#define NMEM_LEAVE LeaveCriticalSection(&critical_section)
#elif _REENTRANT
-static pthread_mutex_t nmem_mutex;
+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);
#else
n->blocks = n->blocks->next;
free_block(t);
}
- NMEM_LEAVE;
n->total = 0;
+ NMEM_LEAVE;
}
#if NMEM_DEBUG
#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