Skip to content

Commit fdfd387

Browse files
committed
Use locks to guard exceptions
1 parent bdd48ec commit fdfd387

File tree

5 files changed

+45
-42
lines changed

5 files changed

+45
-42
lines changed

changelog.in

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ Date: ?-?-?
6868
[DESCRIPTION]
6969
New stuff!
7070

71+
[ENTRY]
72+
Module: kernel
73+
What: bug
74+
Rank: minor
75+
Thanks: Conrad Drescher
76+
[DESCRIPTION]
77+
Use locks to guard mutexes in case tracers throw exceptions.
78+
79+
[ENTRY]
80+
Module: search
81+
What: bug
82+
Rank: minor
83+
Thanks: Conrad Drescher
84+
[DESCRIPTION]
85+
Use locks to guard mutexes in case tracers throw exceptions.
86+
7187
[ENTRY]
7288
Module: minimodel
7389
What: bug

gecode/kernel/core.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,9 +914,10 @@ namespace Gecode {
914914

915915

916916
Group::Group(void) {
917-
m.acquire();
918-
gid = next++;
919-
m.release();
917+
{
918+
Support::Lock l(m);
919+
gid = next++;
920+
}
920921
if (gid == GROUPID_MAX)
921922
throw TooManyGroups("Group::Group");
922923
}

gecode/kernel/memory/region.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,37 @@ namespace Gecode {
4242
Region::Chunk*
4343
Region::Pool::chunk(void) {
4444
Chunk* n;
45-
m.acquire();
46-
if (c != nullptr) {
47-
assert(n_c > 0U);
48-
n = c; c = c->next; n_c--;
49-
} else {
50-
n = new Region::Chunk;
45+
{
46+
Support::Lock l(m);
47+
if (c != nullptr) {
48+
assert(n_c > 0U);
49+
n = c; c = c->next; n_c--;
50+
} else {
51+
n = new Region::Chunk;
52+
}
53+
n->reset();
5154
}
52-
n->reset();
53-
m.release();
5455
return n;
5556
}
5657
void
5758
Region::Pool::chunk(Chunk* u) {
58-
m.acquire();
59+
Support::Lock l(m);
5960
if (n_c == Kernel::MemoryConfig::n_hc_cache) {
6061
delete u;
6162
} else {
6263
u->next = c; c = u;
6364
n_c++;
6465
}
65-
m.release();
6666
}
6767
Region::Pool::~Pool(void) {
68-
m.acquire();
69-
// If that were the case there is a memory leak!
68+
Support::Lock l(m);
69+
// If that were the case there would be a memory leak!
7070
assert(c != nullptr);
7171
do {
7272
Chunk* n=c->next;
7373
delete c;
7474
c=n;
7575
} while (c != nullptr);
76-
m.release();
7776
}
7877

7978
Region::Pool& Region::pool(void) {

gecode/kernel/trace/tracer.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,43 +256,38 @@ namespace Gecode {
256256
forceinline void
257257
ViewTracer<View>::_init(const Space& home,
258258
const ViewTraceRecorder<View>& t) {
259-
m.acquire();
259+
Support::Lock l(m);
260260
init(home,t);
261-
m.release();
262261
}
263262
template<class View>
264263
forceinline void
265264
ViewTracer<View>::_prune(const Space& home,
266265
const ViewTraceRecorder<View>& t,
267266
const ViewTraceInfo& vti,
268267
int i, typename TraceTraits<View>::TraceDelta& d) {
269-
m.acquire();
268+
Support::Lock l(m);
270269
prune(home,t,vti,i,d);
271-
m.release();
272270
}
273271
template<class View>
274272
forceinline void
275273
ViewTracer<View>::_fail(const Space& home,
276274
const ViewTraceRecorder<View>& t) {
277-
m.acquire();
275+
Support::Lock l(m);
278276
fail(home,t);
279-
m.release();
280277
}
281278
template<class View>
282279
forceinline void
283280
ViewTracer<View>::_fix(const Space& home,
284281
const ViewTraceRecorder<View>& t) {
285-
m.acquire();
282+
Support::Lock l(m);
286283
fix(home,t);
287-
m.release();
288284
}
289285
template<class View>
290286
forceinline void
291287
ViewTracer<View>::_done(const Space& home,
292288
const ViewTraceRecorder<View>& t) {
293-
m.acquire();
289+
Support::Lock l(m);
294290
done(home,t);
295-
m.release();
296291
}
297292

298293
template<class View>
@@ -312,23 +307,20 @@ namespace Gecode {
312307
forceinline void
313308
Tracer::_propagate(const Space& home,
314309
const PropagateTraceInfo& pti) {
315-
m.acquire();
310+
Support::Lock l(m);
316311
propagate(home,pti);
317-
m.release();
318312
}
319313
forceinline void
320314
Tracer::_commit(const Space& home,
321315
const CommitTraceInfo& cti) {
322-
m.acquire();
316+
Support::Lock l(m);
323317
commit(home,cti);
324-
m.release();
325318
}
326319
forceinline void
327320
Tracer::_post(const Space& home,
328321
const PostTraceInfo& pti) {
329-
m.acquire();
322+
Support::Lock l(m);
330323
post(home,pti);
331-
m.release();
332324
}
333325

334326
forceinline

gecode/search/tracer.hpp

100644100755
Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -200,23 +200,20 @@ namespace Gecode {
200200
*/
201201
forceinline void
202202
SearchTracer::_round(unsigned int eid) {
203-
m.acquire();
203+
Support::Lock l(m);
204204
round(eid);
205-
m.release();
206205
}
207206

208207
forceinline void
209208
SearchTracer::_skip(const EdgeInfo& ei) {
210-
m.acquire();
209+
Support::Lock l(m);
211210
skip(ei);
212-
m.release();
213211
}
214212

215213
forceinline void
216214
SearchTracer::_node(const EdgeInfo& ei, const NodeInfo& ni) {
217-
m.acquire();
215+
Support::Lock l(m);
218216
node(ei,ni);
219-
m.release();
220217
}
221218

222219
forceinline
@@ -255,11 +252,9 @@ namespace Gecode {
255252

256253
forceinline void
257254
SearchTracer::worker(void) {
258-
m.acquire();
259-
if (--n_active == 0U) {
255+
Support::Lock l(m);
256+
if (--n_active == 0U)
260257
done();
261-
}
262-
m.release();
263258
}
264259

265260
forceinline unsigned int

0 commit comments

Comments
 (0)