Skip to content

Commit

Permalink
Use locks to guard exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
chschulte committed Feb 11, 2019
1 parent bdd48ec commit fdfd387
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 42 deletions.
16 changes: 16 additions & 0 deletions changelog.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ Date: ?-?-?
[DESCRIPTION]
New stuff!

[ENTRY]
Module: kernel
What: bug
Rank: minor
Thanks: Conrad Drescher
[DESCRIPTION]
Use locks to guard mutexes in case tracers throw exceptions.

[ENTRY]
Module: search
What: bug
Rank: minor
Thanks: Conrad Drescher
[DESCRIPTION]
Use locks to guard mutexes in case tracers throw exceptions.

[ENTRY]
Module: minimodel
What: bug
Expand Down
7 changes: 4 additions & 3 deletions gecode/kernel/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,9 +914,10 @@ namespace Gecode {


Group::Group(void) {
m.acquire();
gid = next++;
m.release();
{
Support::Lock l(m);
gid = next++;
}
if (gid == GROUPID_MAX)
throw TooManyGroups("Group::Group");
}
Expand Down
25 changes: 12 additions & 13 deletions gecode/kernel/memory/region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,38 +42,37 @@ namespace Gecode {
Region::Chunk*
Region::Pool::chunk(void) {
Chunk* n;
m.acquire();
if (c != nullptr) {
assert(n_c > 0U);
n = c; c = c->next; n_c--;
} else {
n = new Region::Chunk;
{
Support::Lock l(m);
if (c != nullptr) {
assert(n_c > 0U);
n = c; c = c->next; n_c--;
} else {
n = new Region::Chunk;
}
n->reset();
}
n->reset();
m.release();
return n;
}
void
Region::Pool::chunk(Chunk* u) {
m.acquire();
Support::Lock l(m);
if (n_c == Kernel::MemoryConfig::n_hc_cache) {
delete u;
} else {
u->next = c; c = u;
n_c++;
}
m.release();
}
Region::Pool::~Pool(void) {
m.acquire();
// If that were the case there is a memory leak!
Support::Lock l(m);
// If that were the case there would be a memory leak!
assert(c != nullptr);
do {
Chunk* n=c->next;
delete c;
c=n;
} while (c != nullptr);
m.release();
}

Region::Pool& Region::pool(void) {
Expand Down
24 changes: 8 additions & 16 deletions gecode/kernel/trace/tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,43 +256,38 @@ namespace Gecode {
forceinline void
ViewTracer<View>::_init(const Space& home,
const ViewTraceRecorder<View>& t) {
m.acquire();
Support::Lock l(m);
init(home,t);
m.release();
}
template<class View>
forceinline void
ViewTracer<View>::_prune(const Space& home,
const ViewTraceRecorder<View>& t,
const ViewTraceInfo& vti,
int i, typename TraceTraits<View>::TraceDelta& d) {
m.acquire();
Support::Lock l(m);
prune(home,t,vti,i,d);
m.release();
}
template<class View>
forceinline void
ViewTracer<View>::_fail(const Space& home,
const ViewTraceRecorder<View>& t) {
m.acquire();
Support::Lock l(m);
fail(home,t);
m.release();
}
template<class View>
forceinline void
ViewTracer<View>::_fix(const Space& home,
const ViewTraceRecorder<View>& t) {
m.acquire();
Support::Lock l(m);
fix(home,t);
m.release();
}
template<class View>
forceinline void
ViewTracer<View>::_done(const Space& home,
const ViewTraceRecorder<View>& t) {
m.acquire();
Support::Lock l(m);
done(home,t);
m.release();
}

template<class View>
Expand All @@ -312,23 +307,20 @@ namespace Gecode {
forceinline void
Tracer::_propagate(const Space& home,
const PropagateTraceInfo& pti) {
m.acquire();
Support::Lock l(m);
propagate(home,pti);
m.release();
}
forceinline void
Tracer::_commit(const Space& home,
const CommitTraceInfo& cti) {
m.acquire();
Support::Lock l(m);
commit(home,cti);
m.release();
}
forceinline void
Tracer::_post(const Space& home,
const PostTraceInfo& pti) {
m.acquire();
Support::Lock l(m);
post(home,pti);
m.release();
}

forceinline
Expand Down
15 changes: 5 additions & 10 deletions gecode/search/tracer.hpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -200,23 +200,20 @@ namespace Gecode {
*/
forceinline void
SearchTracer::_round(unsigned int eid) {
m.acquire();
Support::Lock l(m);
round(eid);
m.release();
}

forceinline void
SearchTracer::_skip(const EdgeInfo& ei) {
m.acquire();
Support::Lock l(m);
skip(ei);
m.release();
}

forceinline void
SearchTracer::_node(const EdgeInfo& ei, const NodeInfo& ni) {
m.acquire();
Support::Lock l(m);
node(ei,ni);
m.release();
}

forceinline
Expand Down Expand Up @@ -255,11 +252,9 @@ namespace Gecode {

forceinline void
SearchTracer::worker(void) {
m.acquire();
if (--n_active == 0U) {
Support::Lock l(m);
if (--n_active == 0U)
done();
}
m.release();
}

forceinline unsigned int
Expand Down

0 comments on commit fdfd387

Please sign in to comment.