add UNLEASHED_OBJ to unleashed.mk
[unleashed/tickless.git] / usr / src / cmd / ipf / lib / common / rwlock_emul.c
blob3bccd9ab05b9427e619aefdbd35958de6fb49a1d
1 #include "ipf.h"
3 #define EMM_MAGIC 0x97dd8b3a
5 void eMrwlock_read_enter(rw, file, line)
6 eMrwlock_t *rw;
7 char *file;
8 int line;
10 if (rw->eMrw_magic != EMM_MAGIC) {
11 fprintf(stderr, "%s:eMrwlock_read_enter(%p): bad magic: %#x\n",
12 rw->eMrw_owner, rw, rw->eMrw_magic);
13 abort();
15 if (rw->eMrw_read != 0 || rw->eMrw_write != 0) {
16 fprintf(stderr,
17 "%s:eMrwlock_read_enter(%p): already locked: %d/%d\n",
18 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
19 abort();
21 rw->eMrw_read++;
22 rw->eMrw_heldin = file;
23 rw->eMrw_heldat = line;
27 void eMrwlock_write_enter(rw, file, line)
28 eMrwlock_t *rw;
29 char *file;
30 int line;
32 if (rw->eMrw_magic != EMM_MAGIC) {
33 fprintf(stderr, "%s:eMrwlock_write_enter(%p): bad magic: %#x\n",
34 rw->eMrw_owner, rw, rw->eMrw_magic);
35 abort();
37 if (rw->eMrw_read != 0 || rw->eMrw_write != 0) {
38 fprintf(stderr,
39 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
40 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
41 abort();
43 rw->eMrw_write++;
44 rw->eMrw_heldin = file;
45 rw->eMrw_heldat = line;
49 void eMrwlock_downgrade(rw, file, line)
50 eMrwlock_t *rw;
51 char *file;
52 int line;
54 if (rw->eMrw_magic != EMM_MAGIC) {
55 fprintf(stderr, "%s:eMrwlock_write_enter(%p): bad magic: %#x\n",
56 rw->eMrw_owner, rw, rw->eMrw_magic);
57 abort();
59 if (rw->eMrw_read != 0 || rw->eMrw_write != 1) {
60 fprintf(stderr,
61 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
62 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
63 abort();
65 rw->eMrw_write--;
66 rw->eMrw_read++;
67 rw->eMrw_heldin = file;
68 rw->eMrw_heldat = line;
72 void eMrwlock_exit(rw)
73 eMrwlock_t *rw;
75 if (rw->eMrw_magic != EMM_MAGIC) {
76 fprintf(stderr, "%s:eMrwlock_exit(%p): bad magic: %#x\n",
77 rw->eMrw_owner, rw, rw->eMrw_magic);
78 abort();
80 if (rw->eMrw_read != 1 && rw->eMrw_write != 1) {
81 fprintf(stderr, "%s:eMrwlock_exit(%p): not locked: %d/%d\n",
82 rw->eMrw_owner, rw, rw->eMrw_read, rw->eMrw_write);
83 abort();
85 if (rw->eMrw_read == 1)
86 rw->eMrw_read--;
87 else if (rw->eMrw_write == 1)
88 rw->eMrw_write--;
89 rw->eMrw_heldin = NULL;
90 rw->eMrw_heldat = 0;
94 void eMrwlock_init(rw, who)
95 eMrwlock_t *rw;
96 char *who;
98 if (rw->eMrw_magic == EMM_MAGIC) { /* safe bet ? */
99 fprintf(stderr,
100 "%s:eMrwlock_init(%p): already initialised?: %#x\n",
101 rw->eMrw_owner, rw, rw->eMrw_magic);
102 abort();
104 rw->eMrw_magic = EMM_MAGIC;
105 rw->eMrw_read = 0;
106 rw->eMrw_write = 0;
107 if (who != NULL)
108 rw->eMrw_owner = strdup(who);
109 else
110 rw->eMrw_owner = NULL;
114 void eMrwlock_destroy(rw)
115 eMrwlock_t *rw;
117 if (rw->eMrw_magic != EMM_MAGIC) {
118 fprintf(stderr, "%s:eMrwlock_destroy(%p): bad magic: %#x\n",
119 rw->eMrw_owner, rw, rw->eMrw_magic);
120 abort();
122 memset(rw, 0xa5, sizeof(*rw));