Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / mutex_emul.c
blob9497ffebae555d179514ff3cd56705c14622e60e
1 #include "ipf.h"
3 #define EMM_MAGIC 0x9d7adba3
5 void eMmutex_enter(mtx, file, line)
6 eMmutex_t *mtx;
7 char *file;
8 int 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);
13 abort();
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);
18 abort();
20 mtx->eMm_held++;
21 mtx->eMm_heldin = file;
22 mtx->eMm_heldat = line;
26 void eMmutex_exit(mtx)
27 eMmutex_t *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);
32 abort();
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);
37 abort();
39 mtx->eMm_held--;
40 mtx->eMm_heldin = NULL;
41 mtx->eMm_heldat = 0;
45 void eMmutex_init(mtx, who)
46 eMmutex_t *mtx;
47 char *who;
49 if (mtx->eMm_magic == EMM_MAGIC) { /* safe bet ? */
50 fprintf(stderr,
51 "%s:eMmutex_init(%p): already initialised?: %#x\n",
52 mtx->eMm_owner, mtx, mtx->eMm_magic);
53 abort();
55 mtx->eMm_magic = EMM_MAGIC;
56 mtx->eMm_held = 0;
57 if (who != NULL)
58 mtx->eMm_owner = strdup(who);
59 else
60 mtx->eMm_owner = NULL;
64 void eMmutex_destroy(mtx)
65 eMmutex_t *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);
70 abort();
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);
75 abort();
77 memset(mtx, 0xa5, sizeof(*mtx));