3 #define EMM_MAGIC 0x9d7adba3
5 void eMmutex_enter(mtx
, file
, line
)
10 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
11 fprintf(stderr
, "%s:eMmutex_enter(%p): bad magic: %#x\n",
12 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
15 if (mtx
->eMm_held
!= 0) {
16 fprintf(stderr
, "%s:eMmutex_enter(%p): already locked: %d\n",
17 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
21 mtx
->eMm_heldin
= file
;
22 mtx
->eMm_heldat
= line
;
26 void eMmutex_exit(mtx
)
29 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
30 fprintf(stderr
, "%s:eMmutex_exit(%p): bad magic: %#x\n",
31 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
34 if (mtx
->eMm_held
!= 1) {
35 fprintf(stderr
, "%s:eMmutex_exit(%p): not locked: %d\n",
36 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
40 mtx
->eMm_heldin
= NULL
;
45 void eMmutex_init(mtx
, who
)
49 if (mtx
->eMm_magic
== EMM_MAGIC
) { /* safe bet ? */
51 "%s:eMmutex_init(%p): already initialised?: %#x\n",
52 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
55 mtx
->eMm_magic
= EMM_MAGIC
;
58 mtx
->eMm_owner
= strdup(who
);
60 mtx
->eMm_owner
= NULL
;
64 void eMmutex_destroy(mtx
)
67 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
68 fprintf(stderr
, "%s:eMmutex_destroy(%p): bad magic: %#x\n",
69 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
72 if (mtx
->eMm_held
!= 0) {
73 fprintf(stderr
, "%s:eMmutex_enter(%p): still locked: %d\n",
74 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
77 memset(mtx
, 0xa5, sizeof(*mtx
));