4 * Copyright (C) 2003 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: mutex_emul.c,v 1.2.4.1 2006/06/16 17:21:06 darrenr Exp
13 #define EMM_MAGIC 0x9d7adba3
15 void eMmutex_enter(mtx
, file
, line
)
20 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
21 fprintf(stderr
, "%s:eMmutex_enter(%p): bad magic: %#x\n",
22 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
25 if (mtx
->eMm_held
!= 0) {
26 fprintf(stderr
, "%s:eMmutex_enter(%p): already locked: %d\n",
27 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
31 mtx
->eMm_heldin
= file
;
32 mtx
->eMm_heldat
= line
;
36 void eMmutex_exit(mtx
)
39 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
40 fprintf(stderr
, "%s:eMmutex_exit(%p): bad magic: %#x\n",
41 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
44 if (mtx
->eMm_held
!= 1) {
45 fprintf(stderr
, "%s:eMmutex_exit(%p): not locked: %d\n",
46 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
50 mtx
->eMm_heldin
= NULL
;
55 void eMmutex_init(mtx
, who
)
59 if (mtx
->eMm_magic
== EMM_MAGIC
) { /* safe bet ? */
61 "%s:eMmutex_init(%p): already initialised?: %#x\n",
62 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
65 mtx
->eMm_magic
= EMM_MAGIC
;
68 mtx
->eMm_owner
= strdup(who
);
70 mtx
->eMm_owner
= NULL
;
74 void eMmutex_destroy(mtx
)
77 if (mtx
->eMm_magic
!= EMM_MAGIC
) {
78 fprintf(stderr
, "%s:eMmutex_destroy(%p): bad magic: %#x\n",
79 mtx
->eMm_owner
, mtx
, mtx
->eMm_magic
);
82 if (mtx
->eMm_held
!= 0) {
83 fprintf(stderr
, "%s:eMmutex_enter(%p): still locked: %d\n",
84 mtx
->eMm_owner
, mtx
, mtx
->eMm_held
);
87 memset(mtx
, 0xa5, sizeof(*mtx
));