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

condvar: rename members to conform to coding style


the _ prefix helps to distinguish between members and non-members; helps with
the next patch.

Signed-off-by: default avatarAvi Kivity <avi@cloudius-systems.com>
parent 8b224474
No related branches found
No related tags found
No related merge requests found
...@@ -32,22 +32,22 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr) ...@@ -32,22 +32,22 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr)
int ret = 0; int ret = 0;
wait_record wr(sched::thread::current()); wait_record wr(sched::thread::current());
mutex_lock(&condvar->m); mutex_lock(&condvar->_m);
if (!condvar->waiters_fifo.oldest) { if (!condvar->_waiters_fifo.oldest) {
condvar->waiters_fifo.oldest = &wr; condvar->_waiters_fifo.oldest = &wr;
} else { } else {
condvar->waiters_fifo.newest->next = &wr; condvar->_waiters_fifo.newest->next = &wr;
} }
condvar->waiters_fifo.newest = &wr; condvar->_waiters_fifo.newest = &wr;
// Remember user_mutex for "wait morphing" feature. Assert our assumption // Remember user_mutex for "wait morphing" feature. Assert our assumption
// that concurrent waits use the same mutex. // that concurrent waits use the same mutex.
assert(!condvar->user_mutex || condvar->user_mutex == user_mutex); assert(!condvar->_user_mutex || condvar->_user_mutex == user_mutex);
condvar->user_mutex = user_mutex; condvar->_user_mutex = user_mutex;
// This preempt_disable() is just an optimization, to avoid context // This preempt_disable() is just an optimization, to avoid context
// switch between the two unlocks. // switch between the two unlocks.
sched::preempt_disable(); sched::preempt_disable();
mutex_unlock(user_mutex); mutex_unlock(user_mutex);
mutex_unlock(&condvar->m); mutex_unlock(&condvar->_m);
sched::preempt_enable(); sched::preempt_enable();
// Wait until either the timer expires or condition variable signaled // Wait until either the timer expires or condition variable signaled
...@@ -55,19 +55,19 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr) ...@@ -55,19 +55,19 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr)
if (!wr.woken()) { if (!wr.woken()) {
ret = ETIMEDOUT; ret = ETIMEDOUT;
// wr is still in the linked list (because of a timeout) so remove it: // wr is still in the linked list (because of a timeout) so remove it:
mutex_lock(&condvar->m); mutex_lock(&condvar->_m);
if (&wr == condvar->waiters_fifo.oldest) { if (&wr == condvar->_waiters_fifo.oldest) {
condvar->waiters_fifo.oldest = wr.next; condvar->_waiters_fifo.oldest = wr.next;
if (!wr.next) { if (!wr.next) {
condvar->waiters_fifo.newest = nullptr; condvar->_waiters_fifo.newest = nullptr;
} }
} else { } else {
wait_record *p = condvar->waiters_fifo.oldest; wait_record *p = condvar->_waiters_fifo.oldest;
while (p) { while (p) {
if (&wr == p->next) { if (&wr == p->next) {
p->next = p->next->next; p->next = p->next->next;
if(!p->next) { if(!p->next) {
condvar->waiters_fifo.newest = p; condvar->_waiters_fifo.newest = p;
} }
break; break;
} }
...@@ -77,7 +77,7 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr) ...@@ -77,7 +77,7 @@ int condvar_wait(condvar_t *condvar, mutex_t* user_mutex, sched::timer* tmr)
ret = 0; ret = 0;
} }
} }
mutex_unlock(&condvar->m); mutex_unlock(&condvar->_m);
if (!ret) { if (!ret) {
// wr is no longer in the queue, so either wr.wake() is // wr is no longer in the queue, so either wr.wake() is
// already done, or wake_all() has just taken the whole queue // already done, or wake_all() has just taken the whole queue
...@@ -105,47 +105,47 @@ void condvar_wake_one(condvar_t *condvar) ...@@ -105,47 +105,47 @@ void condvar_wake_one(condvar_t *condvar)
// To make wake with no waiters faster, and avoid unnecessary contention // To make wake with no waiters faster, and avoid unnecessary contention
// in that case, first check the queue head outside the lock. If it is not // in that case, first check the queue head outside the lock. If it is not
// empty, we still need to take the lock, and re-read the head. // empty, we still need to take the lock, and re-read the head.
if (!condvar->waiters_fifo.oldest) { if (!condvar->_waiters_fifo.oldest) {
return; return;
} }
mutex_lock(&condvar->m); mutex_lock(&condvar->_m);
wait_record *wr = condvar->waiters_fifo.oldest; wait_record *wr = condvar->_waiters_fifo.oldest;
if (wr) { if (wr) {
condvar->waiters_fifo.oldest = wr->next; condvar->_waiters_fifo.oldest = wr->next;
if (wr->next == nullptr) { if (wr->next == nullptr) {
condvar->waiters_fifo.newest = nullptr; condvar->_waiters_fifo.newest = nullptr;
} }
// Rather than wake the waiter here (wr->wake()) and have it wait // Rather than wake the waiter here (wr->wake()) and have it wait
// again for the mutex, we do "wait morphing" - have it continue to // again for the mutex, we do "wait morphing" - have it continue to
// sleep until the mutex becomes available. // sleep until the mutex becomes available.
condvar->user_mutex->send_lock(wr); condvar->_user_mutex->send_lock(wr);
// To help the assert() in condvar_wait(), we need to zero saved // To help the assert() in condvar_wait(), we need to zero saved
// user_mutex when all concurrent condvar_wait()s are done. // user_mutex when all concurrent condvar_wait()s are done.
if (!condvar->waiters_fifo.oldest) { if (!condvar->_waiters_fifo.oldest) {
condvar->user_mutex = nullptr; condvar->_user_mutex = nullptr;
} }
} }
mutex_unlock(&condvar->m); mutex_unlock(&condvar->_m);
} }
void condvar_wake_all(condvar_t *condvar) void condvar_wake_all(condvar_t *condvar)
{ {
trace_condvar_wake_all(condvar); trace_condvar_wake_all(condvar);
if (!condvar->waiters_fifo.oldest) { if (!condvar->_waiters_fifo.oldest) {
return; return;
} }
mutex_lock(&condvar->m); mutex_lock(&condvar->_m);
wait_record *wr = condvar->waiters_fifo.oldest; wait_record *wr = condvar->_waiters_fifo.oldest;
// To help the assert() in condvar_wait(), we need to zero saved // To help the assert() in condvar_wait(), we need to zero saved
// user_mutex when all concurrent condvar_wait()s are done. // user_mutex when all concurrent condvar_wait()s are done.
auto user_mutex = condvar->user_mutex; auto user_mutex = condvar->_user_mutex;
condvar->user_mutex = nullptr; condvar->_user_mutex = nullptr;
condvar->waiters_fifo.oldest = condvar->waiters_fifo.newest = nullptr; condvar->_waiters_fifo.oldest = condvar->_waiters_fifo.newest = nullptr;
mutex_unlock(&condvar->m); mutex_unlock(&condvar->_m);
while (wr) { while (wr) {
auto next_wr = wr->next; // need to save - *wr invalid after wake auto next_wr = wr->next; // need to save - *wr invalid after wake
auto cpu_wr = wr->thread()->tcpu(); auto cpu_wr = wr->thread()->tcpu();
......
...@@ -72,7 +72,7 @@ struct wait_record; ...@@ -72,7 +72,7 @@ struct wait_record;
* counter in the waker, and decide exactly who to wake. * counter in the waker, and decide exactly who to wake.
*/ */
typedef struct condvar { typedef struct condvar {
mutex_t m; mutex_t _m;
struct { struct {
// A FIFO queue of waiters - a linked list from oldest (next in line // A FIFO queue of waiters - a linked list from oldest (next in line
// to be woken) towards newest. The wait records themselves are held // to be woken) towards newest. The wait records themselves are held
...@@ -80,12 +80,12 @@ typedef struct condvar { ...@@ -80,12 +80,12 @@ typedef struct condvar {
// allocation is needed for this list. // allocation is needed for this list.
struct wait_record *oldest; struct wait_record *oldest;
struct wait_record *newest; struct wait_record *newest;
} waiters_fifo; } _waiters_fifo;
// Remember mutex last used in a wait(), for use in "wait morphing" // Remember mutex last used in a wait(), for use in "wait morphing"
// feature. We disallow (as Posix Threads do) using different mutexes in // feature. We disallow (as Posix Threads do) using different mutexes in
// concurrent wait()s on the same condvar. We could lift this requirement, // concurrent wait()s on the same condvar. We could lift this requirement,
// but then we would need to remember the user_mutex on each wait_record. // but then we would need to remember the user_mutex on each wait_record.
mutex_t *user_mutex; mutex_t *_user_mutex;
#ifdef __cplusplus #ifdef __cplusplus
// In C++, for convenience also provide methods. // In C++, for convenience also provide methods.
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
void assert_idle(condvar *c) void assert_idle(condvar *c)
{ {
assert (!c->waiters_fifo.newest); assert (!c->_waiters_fifo.newest);
assert (!c->waiters_fifo.oldest); assert (!c->_waiters_fifo.oldest);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
......
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