4 * Copyright (C) 2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: rwlock_emul.c,v 1.1.4.1 2006/06/16 17:21:17 darrenr Exp
13 #define EMM_MAGIC 0x97dd8b3a
15 void eMrwlock_read_enter(rw
, file
, 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
);
25 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 0) {
27 "%s:eMrwlock_read_enter(%p): already locked: %d/%d\n",
28 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
32 rw
->eMrw_heldin
= file
;
33 rw
->eMrw_heldat
= line
;
37 void eMrwlock_write_enter(rw
, file
, 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
);
47 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 0) {
49 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
50 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
54 rw
->eMrw_heldin
= file
;
55 rw
->eMrw_heldat
= line
;
59 void eMrwlock_downgrade(rw
, file
, 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
);
69 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 1) {
71 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
72 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
77 rw
->eMrw_heldin
= file
;
78 rw
->eMrw_heldat
= line
;
82 void eMrwlock_exit(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
);
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
);
95 if (rw
->eMrw_read
== 1)
97 else if (rw
->eMrw_write
== 1)
99 rw
->eMrw_heldin
= NULL
;
104 void eMrwlock_init(rw
, who
)
108 if (rw
->eMrw_magic
== EMM_MAGIC
) { /* safe bet ? */
110 "%s:eMrwlock_init(%p): already initialised?: %#x\n",
111 rw
->eMrw_owner
, rw
, rw
->eMrw_magic
);
114 rw
->eMrw_magic
= EMM_MAGIC
;
118 rw
->eMrw_owner
= strdup(who
);
120 rw
->eMrw_owner
= NULL
;
124 void eMrwlock_destroy(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
);
132 memset(rw
, 0xa5, sizeof(*rw
));