Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / mutex_emul.c
bloba36a030a905c195e8ac74cd10ae4bab778fc649b
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2003 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: mutex_emul.c,v 1.2.4.1 2006/06/16 17:21:06 darrenr Exp
9 */
11 #include "ipf.h"
13 #define EMM_MAGIC 0x9d7adba3
15 void eMmutex_enter(mtx, file, line)
16 eMmutex_t *mtx;
17 char *file;
18 int line;
20 if (mtx->eMm_magic != EMM_MAGIC) {
21 fprintf(stderr, "%s:eMmutex_enter(%p): bad magic: %#x\n",
22 mtx->eMm_owner, mtx, mtx->eMm_magic);
23 abort();
25 if (mtx->eMm_held != 0) {
26 fprintf(stderr, "%s:eMmutex_enter(%p): already locked: %d\n",
27 mtx->eMm_owner, mtx, mtx->eMm_held);
28 abort();
30 mtx->eMm_held++;
31 mtx->eMm_heldin = file;
32 mtx->eMm_heldat = line;
36 void eMmutex_exit(mtx)
37 eMmutex_t *mtx;
39 if (mtx->eMm_magic != EMM_MAGIC) {
40 fprintf(stderr, "%s:eMmutex_exit(%p): bad magic: %#x\n",
41 mtx->eMm_owner, mtx, mtx->eMm_magic);
42 abort();
44 if (mtx->eMm_held != 1) {
45 fprintf(stderr, "%s:eMmutex_exit(%p): not locked: %d\n",
46 mtx->eMm_owner, mtx, mtx->eMm_held);
47 abort();
49 mtx->eMm_held--;
50 mtx->eMm_heldin = NULL;
51 mtx->eMm_heldat = 0;
55 void eMmutex_init(mtx, who)
56 eMmutex_t *mtx;
57 char *who;
59 if (mtx->eMm_magic == EMM_MAGIC) { /* safe bet ? */
60 fprintf(stderr,
61 "%s:eMmutex_init(%p): already initialised?: %#x\n",
62 mtx->eMm_owner, mtx, mtx->eMm_magic);
63 abort();
65 mtx->eMm_magic = EMM_MAGIC;
66 mtx->eMm_held = 0;
67 if (who != NULL)
68 mtx->eMm_owner = strdup(who);
69 else
70 mtx->eMm_owner = NULL;
74 void eMmutex_destroy(mtx)
75 eMmutex_t *mtx;
77 if (mtx->eMm_magic != EMM_MAGIC) {
78 fprintf(stderr, "%s:eMmutex_destroy(%p): bad magic: %#x\n",
79 mtx->eMm_owner, mtx, mtx->eMm_magic);
80 abort();
82 if (mtx->eMm_held != 0) {
83 fprintf(stderr, "%s:eMmutex_enter(%p): still locked: %d\n",
84 mtx->eMm_owner, mtx, mtx->eMm_held);
85 abort();
87 memset(mtx, 0xa5, sizeof(*mtx));