Skip to content
Snippets Groups Projects
Commit b9953a90 authored by Avi Kivity's avatar Avi Kivity
Browse files

semaphore: remove indirection accessing internal mutex

Previously, the mutex was stored using a pointer to avoid overflowing
glibc's sem_t.  Now we no longer have this restriction, drop the indirection.
parent 39daaed5
No related branches found
No related tags found
No related merge requests found
......@@ -2,13 +2,12 @@
semaphore::semaphore(unsigned val)
: _val(val)
, _mtx(new mutex)
{
}
void semaphore::post(unsigned units)
{
with_lock(*_mtx, [=] {
with_lock(_mtx, [=] {
_val += units;
auto i = _waiters.begin();
while (_val > 0 && i != _waiters.end()) {
......@@ -29,7 +28,7 @@ void semaphore::wait(unsigned units)
bool wait = false;
wait_record wr;
wr.owner = nullptr;
with_lock(*_mtx, [&] {
with_lock(_mtx, [&] {
if (_val >= units) {
_val -= units;
} else {
......@@ -47,7 +46,7 @@ void semaphore::wait(unsigned units)
bool semaphore::trywait(unsigned units)
{
bool ok = false;
with_lock(*_mtx, [&] {
with_lock(_mtx, [&] {
if (_val > units) {
_val -= units;
ok = true;
......
#ifndef SEMAPHORE_HH_
#define SEMAPHORE_HH_
#include <memory>
#include <osv/mutex.h>
#include <list>
#include <sched.hh>
......@@ -14,7 +13,7 @@ public:
bool trywait(unsigned units = 1);
private:
unsigned _val;
std::unique_ptr<mutex> _mtx;
mutex _mtx;
struct wait_record {
sched::thread* owner;
unsigned units;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment