Loading...
Searching...
No Matches
vspace::Semaphore Class Reference

`#include <vspace.h>`

## Public Member Functions

| Semaphore (size_t value=0)
size_t | value ()
void | post ()
bool | try_wait ()
void | wait ()
bool | start_wait (internals::ipc_signal_t sig=0)
bool | stop_wait ()

## Private Member Functions

void | next (int &index)
bool | _idle ()

## Private Attributes

int | _owner
int | _waiting [internals::MAX_PROCESS+1]
internals::ipc_signal_t | _signals [internals::MAX_PROCESS+1]
int | _head
int | _tail
size_t | _value
FastLock | _lock

## Friends

template<typename T>
class | SyncVar

## Detailed Description

Definition at line 2345 of file vspace.h.

## Constructor & Destructor Documentation

## Semaphore()

vspace::Semaphore::Semaphore | ( | size_t | value = 0 | ) |

inline

Definition at line 2366 of file vspace.h.

:
_owner(0), _head(0), _tail(0), _value(value), _lock() {
}
vspace::Semaphore::_head
int _head
Definition vspace.h:2350
vspace::Semaphore::_owner
int _owner
Definition vspace.h:2347
vspace::Semaphore::_value
size_t _value
Definition vspace.h:2357
vspace::Semaphore::_lock
FastLock _lock
Definition vspace.h:2358
vspace::Semaphore::value
size_t value()
Definition vspace.h:2369
vspace::Semaphore::_tail
int _tail
Definition vspace.h:2350

## Member Function Documentation

## _idle()

bool vspace::Semaphore::_idle | ( |  | ) |

inline private

Definition at line 2359 of file vspace.h.

{
return _head == _tail;
}

## next()

void vspace::Semaphore::next | ( | int & | index | ) |

inline private

Definition at line 2351 of file vspace.h.

{
if (index == internals::MAX_PROCESS)
index = 0;
else
index++;
}
vspace::internals::MAX_PROCESS
static const int MAX_PROCESS
Definition vspace.h:1419
index
static int index(p_Length length, p_Ord ord)
Definition p_Procs_Impl.h:592

## post()

void Semaphore::post | ( |  | ) |

Definition at line 1111 of file vspace.cc.

{
int wakeup = -1;
internals::ipc_signal_t sig;
_lock.lock();
if (_head == _tail) {
_value++;
} else {
// don't increment value, as we'll pass that on to the next process.
wakeup = _waiting[_head];
sig = _signals[_head];
next(_head);
}
_lock.unlock();
if (wakeup >= 0) {
internals::send_signal(wakeup, sig);
}
}
vspace::Semaphore::_waiting
int _waiting[internals::MAX_PROCESS+1]
Definition vspace.h:2348
vspace::Semaphore::_signals
internals::ipc_signal_t _signals[internals::MAX_PROCESS+1]
Definition vspace.h:2349
next
ListNode * next
Definition janet.h:31
vspace::internals::ipc_signal_t
int ipc_signal_t
Definition vspace.h:1481
vspace::internals::send_signal
bool send_signal(int processno, ipc_signal_t sig, bool lock)
Definition vspace.cc:967

## start_wait()

bool Semaphore::start_wait | ( | internals::ipc_signal_t | sig = 0 | ) |

Definition at line 1154 of file vspace.cc.

{
_lock.lock();
if (_value > 0) {
if (internals::send_signal(internals::vmem.current_process, sig))
_value--;
_lock.unlock();
return false;
}
_waiting[_tail] = internals::vmem.current_process;
_signals[_tail] = sig;
next(_tail);
_lock.unlock();
return true;
}
vspace::internals::vmem
static VMem & vmem
Definition vspace.h:1635
vspace::internals::VMem::current_process
int current_process
Definition vspace.h:1592

## stop_wait()

bool Semaphore::stop_wait | ( |  | ) |

Definition at line 1169 of file vspace.cc.

{
bool result = false;
_lock.lock();
for (int i = _head; i != _tail; next(i)) {
if (_waiting[i] == internals::vmem.current_process) {
int last = i;
next(i);
while (i != _tail) {
_waiting[last] = _waiting[i];
_signals[last] = _signals[i];
last = i;
next(i);
}
_tail = last;
result = true;
break;
}
}
_lock.unlock();
return result;
}
i
int i
Definition cfEzgcd.cc:132
result
return result
Definition facAbsBiFact.cc:76
last
STATIC_VAR poly last
Definition hdegree.cc:1138

## try_wait()

bool Semaphore::try_wait | ( |  | ) |

Definition at line 1129 of file vspace.cc.

{
bool result = false;
_lock.lock();
if (_value > 0) {
_value--;
result = true;
}
_lock.unlock();
return result;
}

## value()

size_t vspace::Semaphore::value | ( |  | ) |

inline

Definition at line 2369 of file vspace.h.

{
return _value;
}

## wait()

void Semaphore::wait | ( |  | ) |

Definition at line 1140 of file vspace.cc.

{
_lock.lock();
if (_value > 0) {
_value--;
_lock.unlock();
return;
}
_waiting[_tail] = internals::vmem.current_process;
_signals[_tail] = 0;
next(_tail);
_lock.unlock();
internals::wait_signal();
}
vspace::internals::wait_signal
ipc_signal_t wait_signal(bool lock)
Definition vspace.cc:1075

## Friends And Related Symbol Documentation

## SyncVar

template<typename T>

friend class SyncVar

friend

Definition at line 2363 of file vspace.h.

## Field Documentation

## _head

int vspace::Semaphore::_head

private

Definition at line 2350 of file vspace.h.

## _lock

FastLock vspace::Semaphore::_lock

private

Definition at line 2358 of file vspace.h.

## _owner

int vspace::Semaphore::_owner

private

Definition at line 2347 of file vspace.h.

## _signals

internals::ipc_signal_t vspace::Semaphore::_signals[internals::MAX_PROCESS+1]

private

Definition at line 2349 of file vspace.h.

## _tail

int vspace::Semaphore::_tail

private

Definition at line 2350 of file vspace.h.

## _value

size_t vspace::Semaphore::_value

private

Definition at line 2357 of file vspace.h.

## _waiting

int vspace::Semaphore::_waiting[internals::MAX_PROCESS+1]

private

Definition at line 2348 of file vspace.h.

The documentation for this class was generated from the following files:

- kernel/oswrapper/vspace.h
- kernel/oswrapper/vspace.cc