summaryrefslogtreecommitdiff
path: root/lib/mutex_emul.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mutex_emul.c')
-rw-r--r--lib/mutex_emul.c81
1 files changed, 63 insertions, 18 deletions
diff --git a/lib/mutex_emul.c b/lib/mutex_emul.c
index 1a5815658236f..57ed987388869 100644
--- a/lib/mutex_emul.c
+++ b/lib/mutex_emul.c
@@ -1,20 +1,28 @@
/*
- * Copyright (C) 2003 by Darren Reed.
- *
- * See the IPFILTER.LICENCE file for details on licencing.
- *
- * $Id: mutex_emul.c,v 1.2.4.1 2006/06/16 17:21:06 darrenr Exp $
- */
+ * Copyright (C) 2012 by Darren Reed.
+ *
+ * See the IPFILTER.LICENCE file for details on licencing.
+ *
+ * $Id$
+ */
#include "ipf.h"
#define EMM_MAGIC 0x9d7adba3
-void eMmutex_enter(mtx, file, line)
-eMmutex_t *mtx;
-char *file;
-int line;
+static int mutex_debug = 0;
+static FILE *mutex_file = NULL;
+static int initcount = 0;
+
+void
+eMmutex_enter(mtx, file, line)
+ eMmutex_t *mtx;
+ char *file;
+ int line;
{
+ if (mutex_debug & 2)
+ fprintf(mutex_file, "%s:%d:eMmutex_enter(%s)\n", file, line,
+ mtx->eMm_owner);
if (mtx->eMm_magic != EMM_MAGIC) {
fprintf(stderr, "%s:eMmutex_enter(%p): bad magic: %#x\n",
mtx->eMm_owner, mtx, mtx->eMm_magic);
@@ -31,9 +39,15 @@ int line;
}
-void eMmutex_exit(mtx)
-eMmutex_t *mtx;
+void
+eMmutex_exit(mtx, file, line)
+ eMmutex_t *mtx;
+ char *file;
+ int line;
{
+ if (mutex_debug & 2)
+ fprintf(mutex_file, "%s:%d:eMmutex_exit(%s)\n", file, line,
+ mtx->eMm_owner);
if (mtx->eMm_magic != EMM_MAGIC) {
fprintf(stderr, "%s:eMmutex_exit(%p): bad magic: %#x\n",
mtx->eMm_owner, mtx, mtx->eMm_magic);
@@ -50,10 +64,18 @@ eMmutex_t *mtx;
}
-void eMmutex_init(mtx, who)
-eMmutex_t *mtx;
-char *who;
+void
+eMmutex_init(mtx, who, file, line)
+ eMmutex_t *mtx;
+ char *who;
+ char *file;
+ int line;
{
+ if (mutex_file == NULL && mutex_debug)
+ mutex_file = fopen("ipf_mutex_log", "w");
+ if (mutex_debug & 1)
+ fprintf(mutex_file, "%s:%d:eMmutex_init(%p,%s)\n",
+ file, line, mtx, who);
if (mtx->eMm_magic == EMM_MAGIC) { /* safe bet ? */
fprintf(stderr,
"%s:eMmutex_init(%p): already initialised?: %#x\n",
@@ -66,21 +88,44 @@ char *who;
mtx->eMm_owner = strdup(who);
else
mtx->eMm_owner = NULL;
+ initcount++;
}
-void eMmutex_destroy(mtx)
-eMmutex_t *mtx;
+void
+eMmutex_destroy(mtx, file, line)
+ eMmutex_t *mtx;
+ char *file;
+ int line;
{
+ if (mutex_debug & 1)
+ fprintf(mutex_file,
+ "%s:%d:eMmutex_destroy(%p,%s)\n", file, line,
+ mtx, mtx->eMm_owner);
if (mtx->eMm_magic != EMM_MAGIC) {
fprintf(stderr, "%s:eMmutex_destroy(%p): bad magic: %#x\n",
mtx->eMm_owner, mtx, mtx->eMm_magic);
abort();
}
if (mtx->eMm_held != 0) {
- fprintf(stderr, "%s:eMmutex_enter(%p): still locked: %d\n",
+ fprintf(stderr,
+ "%s:eMmutex_enter(%p): still locked: %d\n",
mtx->eMm_owner, mtx, mtx->eMm_held);
abort();
}
+ if (mtx->eMm_owner != NULL)
+ free(mtx->eMm_owner);
memset(mtx, 0xa5, sizeof(*mtx));
+ initcount--;
+}
+
+
+void
+ipf_mutex_clean()
+{
+ if (initcount != 0) {
+ if (mutex_file)
+ fprintf(mutex_file, "initcount %d\n", initcount);
+ abort();
+ }
}