Lines 31-39
Link Here
|
31 |
#define MAX_ITER 200 |
31 |
#define MAX_ITER 200 |
32 |
#define CHILDREN 6 |
32 |
#define CHILDREN 6 |
33 |
#define MAX_COUNTER (MAX_ITER * CHILDREN) |
33 |
#define MAX_COUNTER (MAX_ITER * CHILDREN) |
|
|
34 |
#define MAX_WAIT_USEC (1000*1000) |
34 |
|
35 |
|
35 |
static apr_proc_mutex_t *proc_lock; |
36 |
static apr_proc_mutex_t *proc_lock; |
36 |
static volatile int *x; |
37 |
static volatile int *x; |
|
|
38 |
static int trylock_flag = 0; |
37 |
|
39 |
|
38 |
/* a slower more racy way to implement (*x)++ */ |
40 |
/* a slower more racy way to implement (*x)++ */ |
39 |
static int increment(int n) |
41 |
static int increment(int n) |
Lines 49-55
Link Here
|
49 |
*proc = apr_pcalloc(p, sizeof(**proc)); |
51 |
*proc = apr_pcalloc(p, sizeof(**proc)); |
50 |
|
52 |
|
51 |
/* slight delay to allow things to settle */ |
53 |
/* slight delay to allow things to settle */ |
52 |
apr_sleep (1); |
54 |
apr_sleep(1); |
53 |
|
55 |
|
54 |
rv = apr_proc_fork(*proc, p); |
56 |
rv = apr_proc_fork(*proc, p); |
55 |
if (rv == APR_INCHILD) { |
57 |
if (rv == APR_INCHILD) { |
Lines 68-77
Link Here
|
68 |
exit(1); |
70 |
exit(1); |
69 |
|
71 |
|
70 |
do { |
72 |
do { |
71 |
if (apr_proc_mutex_lock(proc_lock)) |
73 |
if (trylock_flag) { |
72 |
exit(1); |
74 |
int wait_usec = 0; |
|
|
75 |
|
76 |
while (rv = apr_proc_mutex_trylock(proc_lock)) { |
77 |
if (!APR_STATUS_IS_EBUSY(rv)) |
78 |
exit(1); |
79 |
if (++wait_usec >= MAX_WAIT_USEC) |
80 |
exit(1); |
81 |
apr_sleep(1); |
82 |
} |
83 |
} |
84 |
else { |
85 |
if (apr_proc_mutex_lock(proc_lock)) |
86 |
exit(1); |
87 |
} |
88 |
|
73 |
i++; |
89 |
i++; |
74 |
*x = increment(*x); |
90 |
*x = increment(*x); |
|
|
91 |
|
75 |
if (apr_proc_mutex_unlock(proc_lock)) |
92 |
if (apr_proc_mutex_unlock(proc_lock)) |
76 |
exit(1); |
93 |
exit(1); |
77 |
} while (i < MAX_ITER); |
94 |
} while (i < MAX_ITER); |
Lines 104-110
Link Here
|
104 |
APR_ASSERT_SUCCESS(tc, "create the mutex", rv); |
121 |
APR_ASSERT_SUCCESS(tc, "create the mutex", rv); |
105 |
if (rv != APR_SUCCESS) |
122 |
if (rv != APR_SUCCESS) |
106 |
return; |
123 |
return; |
107 |
|
124 |
|
|
|
125 |
trylock_flag = 0; |
126 |
*x = 0; |
127 |
|
108 |
for (n = 0; n < CHILDREN; n++) |
128 |
for (n = 0; n < CHILDREN; n++) |
109 |
make_child(tc, &child[n], p); |
129 |
make_child(tc, &child[n], p); |
110 |
|
130 |
|
Lines 112-117
Link Here
|
112 |
await_child(tc, child[n]); |
132 |
await_child(tc, child[n]); |
113 |
|
133 |
|
114 |
ABTS_ASSERT(tc, "Locks don't appear to work", *x == MAX_COUNTER); |
134 |
ABTS_ASSERT(tc, "Locks don't appear to work", *x == MAX_COUNTER); |
|
|
135 |
|
136 |
rv = apr_proc_mutex_trylock(proc_lock); |
137 |
if (rv == APR_ENOTIMPL) { |
138 |
ABTS_NOT_IMPL(tc, "apr_proc_mutex_trylock not implemented"); |
139 |
return; |
140 |
} |
141 |
APR_ASSERT_SUCCESS(tc, "check for trylock", rv); |
142 |
|
143 |
rv = apr_proc_mutex_unlock(proc_lock); |
144 |
APR_ASSERT_SUCCESS(tc, "unlock after trylock check", rv); |
145 |
|
146 |
trylock_flag = 1; |
147 |
*x = 0; |
148 |
|
149 |
for (n = 0; n < CHILDREN; n++) |
150 |
make_child(tc, &child[n], p); |
151 |
|
152 |
for (n = 0; n < CHILDREN; n++) |
153 |
await_child(tc, child[n]); |
154 |
|
155 |
ABTS_ASSERT(tc, "Locks don't appear to work with trylock", |
156 |
*x == MAX_COUNTER); |
115 |
} |
157 |
} |
116 |
#endif |
158 |
#endif |
117 |
|
159 |
|