Skip to content

Commit

Permalink
Don't block when locking finalizer list mutex.
Browse files Browse the repository at this point in the history
brixen committed Jun 9, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 3f7bc1e commit b3f1724
Showing 2 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions machine/memory/finalizer.cpp
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ namespace rubinius {
MachineThread::wakeup(state);

while(thread_running_) {
std::lock_guard<std::mutex> guard(list_mutex());
LockWaiting<std::mutex> guard(state, list_mutex());
list_condition().notify_one();
}
}
@@ -253,7 +253,7 @@ namespace rubinius {
if(finishing_) return;

{
std::lock_guard<std::mutex> guard(list_mutex());
LockWaiting<std::mutex> guard(state, list_mutex());

for(FinalizerObjects::iterator i = live_list_.begin();
i != live_list_.end();
@@ -300,7 +300,7 @@ namespace rubinius {
}

void FinalizerThread::add_finalizer(STATE, FinalizerObject* obj) {
std::lock_guard<std::mutex> guard(list_mutex());
LockWaiting<std::mutex> guard(state, list_mutex());

live_list_.push_back(obj);
vm()->metrics().gc.objects_queued++;
20 changes: 9 additions & 11 deletions machine/thread_phase.hpp
Original file line number Diff line number Diff line change
@@ -76,26 +76,24 @@ namespace rubinius {
}
};

template <class T>
class LockWaiting : public utilities::thread::LockGuardTemplate<T> {
State* state_;
ThreadNexus::Phase phase_;
template <typename T>
class LockWaiting {
T& lock_;

public:
LockWaiting(STATE, T& in_lock)
: utilities::thread::LockGuardTemplate<T>(in_lock, false)
, state_(state)
: lock_(in_lock)
{
phase_ = state_->vm()->thread_phase();
state_->vm()->thread_nexus()->waiting_phase(state_->vm());
ThreadNexus::Phase phase = state->vm()->thread_phase();
state->vm()->thread_nexus()->waiting_phase(state->vm());

this->lock();
lock_.lock();

state_->vm()->thread_nexus()->restore_phase(state_->vm(), phase_);
state->vm()->thread_nexus()->restore_phase(state->vm(), phase);
}

~LockWaiting() {
this->unlock();
lock_.unlock();
}
};

0 comments on commit b3f1724

Please sign in to comment.