bindings: C++ binding fixes

Disable preemption in critical sections and fix comment
This commit is contained in:
Adam Belay 2019-02-13 19:20:22 +00:00
parent ffb0a71cf2
commit 7425cd4b3f
3 changed files with 11 additions and 12 deletions

View File

@ -1,4 +1,4 @@
// udp.h - support for UDP networking
// net.h - support for networking
#pragma once

View File

@ -13,15 +13,15 @@ void ThreadTrampoline(void *arg) {
void ThreadTrampolineWithJoin(void *arg) {
thread_internal::join_data *d = static_cast<thread_internal::join_data*>(arg);
d->func_();
spin_lock(&d->lock_);
spin_lock_np(&d->lock_);
if (d->done_) {
spin_unlock(&d->lock_);
spin_unlock_np(&d->lock_);
if (d->waiter_) thread_ready(d->waiter_);
return;
}
d->done_ = true;
d->waiter_ = thread_self();
thread_park_and_unlock(&d->lock_);
thread_park_and_unlock_np(&d->lock_);
}
} // namespace thread_internal
@ -55,9 +55,9 @@ Thread::Thread(std::function<void()>&& func) {
void Thread::Detach() {
if (unlikely(join_data_ == nullptr)) BUG();
spin_lock(&join_data_->lock_);
spin_lock_np(&join_data_->lock_);
if (join_data_->done_) {
spin_unlock(&join_data_->lock_);
spin_unlock_np(&join_data_->lock_);
assert(join_data_->waiter_ != nullptr);
thread_ready(join_data_->waiter_);
join_data_ = nullptr;
@ -65,16 +65,16 @@ void Thread::Detach() {
}
join_data_->done_ = true;
join_data_->waiter_ = nullptr;
spin_unlock(&join_data_->lock_);
spin_unlock_np(&join_data_->lock_);
join_data_ = nullptr;
}
void Thread::Join() {
if (unlikely(join_data_ == nullptr)) BUG();
spin_lock(&join_data_->lock_);
spin_lock_np(&join_data_->lock_);
if (join_data_->done_) {
spin_unlock(&join_data_->lock_);
spin_unlock_np(&join_data_->lock_);
assert(join_data_->waiter_ != nullptr);
thread_ready(join_data_->waiter_);
join_data_ = nullptr;
@ -82,7 +82,7 @@ void Thread::Join() {
}
join_data_->done_ = true;
join_data_->waiter_ = thread_self();
thread_park_and_unlock(&join_data_->lock_);
thread_park_and_unlock_np(&join_data_->lock_);
join_data_ = nullptr;
}

View File

@ -4,8 +4,7 @@
extern "C" {
#include <base/assert.h>
#include <base/lock.h>
#include <runtime/thread.h>
#include <runtime/sync.h>
}
#include <functional>