3 #define EMM_MAGIC 0x97dd8b3a
5 void eMrwlock_read_enter(rw
, file
, 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
);
15 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 0) {
17 "%s:eMrwlock_read_enter(%p): already locked: %d/%d\n",
18 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
22 rw
->eMrw_heldin
= file
;
23 rw
->eMrw_heldat
= line
;
27 void eMrwlock_write_enter(rw
, file
, 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
);
37 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 0) {
39 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
40 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
44 rw
->eMrw_heldin
= file
;
45 rw
->eMrw_heldat
= line
;
49 void eMrwlock_downgrade(rw
, file
, 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
);
59 if (rw
->eMrw_read
!= 0 || rw
->eMrw_write
!= 1) {
61 "%s:eMrwlock_write_enter(%p): already locked: %d/%d\n",
62 rw
->eMrw_owner
, rw
, rw
->eMrw_read
, rw
->eMrw_write
);
67 rw
->eMrw_heldin
= file
;
68 rw
->eMrw_heldat
= line
;
72 void eMrwlock_exit(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
);
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
);
85 if (rw
->eMrw_read
== 1)
87 else if (rw
->eMrw_write
== 1)
89 rw
->eMrw_heldin
= NULL
;
94 void eMrwlock_init(rw
, who
)
98 if (rw
->eMrw_magic
== EMM_MAGIC
) { /* safe bet ? */
100 "%s:eMrwlock_init(%p): already initialised?: %#x\n",
101 rw
->eMrw_owner
, rw
, rw
->eMrw_magic
);
104 rw
->eMrw_magic
= EMM_MAGIC
;
108 rw
->eMrw_owner
= strdup(who
);
110 rw
->eMrw_owner
= NULL
;
114 void eMrwlock_destroy(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
);
122 memset(rw
, 0xa5, sizeof(*rw
));