Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / rwlock_emul.c
blob013f707b75b5305a614de9b3717ff4e392f19d18
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2003 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: rwlock_emul.c,v 1.1.4.1 2006/06/16 17:21:17 darrenr Exp
9 */
11 #include "ipf.h"
13 #define EMM_MAGIC 0x97dd8b3a
15 void eMrwlock_read_enter(rw, file, line)
16 eMrwlock_t *rw;
17 char *file;
18 int line;
20 if (rw->eMrw_magic != EMM_MAGIC) {
21 fprintf(stderr, "%s:eMrwlock_read_enter(%p): bad magic: %#x\n",
22 rw->eMrw_owner, rw, rw->eMrw_magic);
23 abort();
25 if (rw->eMrw_read != 0 || rw->eMrw_write != 0) {
26 fprintf(stderr,
27 "%s:eMrwlock_read_enter(%p): already locked: %d/%d\n",
28 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
29 abort();
31 rw->eMrw_read++;
32 rw->eMrw_heldin = file;
33 rw->eMrw_heldat = line;
37 void eMrwlock_write_enter(rw, file, line)
38 eMrwlock_t *rw;
39 char *file;
40 int line;
42 if (rw->eMrw_magic != EMM_MAGIC) {
43 fprintf(stderr, "%s:eMrwlock_write_enter(%p): bad magic: %#x\n",
44 rw->eMrw_owner, rw, rw->eMrw_magic);
45 abort();
47 if (rw->eMrw_read != 0 || rw->eMrw_write != 0) {
48 fprintf(stderr,
49 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
50 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
51 abort();
53 rw->eMrw_write++;
54 rw->eMrw_heldin = file;
55 rw->eMrw_heldat = line;
59 void eMrwlock_downgrade(rw, file, line)
60 eMrwlock_t *rw;
61 char *file;
62 int line;
64 if (rw->eMrw_magic != EMM_MAGIC) {
65 fprintf(stderr, "%s:eMrwlock_write_enter(%p): bad magic: %#x\n",
66 rw->eMrw_owner, rw, rw->eMrw_magic);
67 abort();
69 if (rw->eMrw_read != 0 || rw->eMrw_write != 1) {
70 fprintf(stderr,
71 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
72 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
73 abort();
75 rw->eMrw_write--;
76 rw->eMrw_read++;
77 rw->eMrw_heldin = file;
78 rw->eMrw_heldat = line;
82 void eMrwlock_exit(rw)
83 eMrwlock_t *rw;
85 if (rw->eMrw_magic != EMM_MAGIC) {
86 fprintf(stderr, "%s:eMrwlock_exit(%p): bad magic: %#x\n",
87 rw->eMrw_owner, rw, rw->eMrw_magic);
88 abort();
90 if (rw->eMrw_read != 1 && rw->eMrw_write != 1) {
91 fprintf(stderr, "%s:eMrwlock_exit(%p): not locked: %d/%d\n",
92 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
93 abort();
95 if (rw->eMrw_read == 1)
96 rw->eMrw_read--;
97 else if (rw->eMrw_write == 1)
98 rw->eMrw_write--;
99 rw->eMrw_heldin = NULL;
100 rw->eMrw_heldat = 0;
104 void eMrwlock_init(rw, who)
105 eMrwlock_t *rw;
106 char *who;
108 if (rw->eMrw_magic == EMM_MAGIC) { /* safe bet ? */
109 fprintf(stderr,
110 "%s:eMrwlock_init(%p): already initialised?: %#x\n",
111 rw->eMrw_owner, rw, rw->eMrw_magic);
112 abort();
114 rw->eMrw_magic = EMM_MAGIC;
115 rw->eMrw_read = 0;
116 rw->eMrw_write = 0;
117 if (who != NULL)
118 rw->eMrw_owner = strdup(who);
119 else
120 rw->eMrw_owner = NULL;
124 void eMrwlock_destroy(rw)
125 eMrwlock_t *rw;
127 if (rw->eMrw_magic != EMM_MAGIC) {
128 fprintf(stderr, "%s:eMrwlock_destroy(%p): bad magic: %#x\n",
129 rw->eMrw_owner, rw, rw->eMrw_magic);
130 abort();
132 memset(rw, 0xa5, sizeof(*rw));