mirror of
https://github.com/marian-nmt/marian.git
synced 2025-01-07 17:10:15 +03:00
tighten up locking
This commit is contained in:
parent
3aed45cd47
commit
138a414ddd
@ -274,17 +274,21 @@ DeviceInfo God::GetNextDevice() const
|
||||
Search &God::GetSearch() const
|
||||
{
|
||||
Search *obj;
|
||||
|
||||
{
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(m_accessLock);
|
||||
obj = m_search.get();
|
||||
boost::shared_lock<boost::shared_mutex> read_lock(accessLock_);
|
||||
obj = search_.get();
|
||||
if (obj) {
|
||||
// found exiting obj
|
||||
return *obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj == NULL) {
|
||||
boost::unique_lock<boost::shared_mutex> lock(m_accessLock);
|
||||
// create new obj
|
||||
boost::unique_lock<boost::shared_mutex> lock(accessLock_);
|
||||
obj = new Search(*this);
|
||||
search_.reset(obj);
|
||||
|
||||
obj = new Search(*this);
|
||||
m_search.reset(obj);
|
||||
}
|
||||
assert(obj);
|
||||
return *obj;
|
||||
}
|
||||
|
@ -100,6 +100,6 @@ class God {
|
||||
|
||||
mutable size_t threadIncr_;
|
||||
|
||||
mutable boost::thread_specific_ptr<Search> m_search;
|
||||
mutable boost::shared_mutex m_accessLock;
|
||||
mutable boost::thread_specific_ptr<Search> search_;
|
||||
mutable boost::shared_mutex accessLock_;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user