Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
waitchannel.h File Reference
#include <sys/cdefs.h>
#include <sys/queue.h>
Include dependency graph for waitchannel.h:

Go to the source code of this file.

Data Structures

struct  WaitChannel
 

Macros

#define WAITCHANNEL_NAMELEN   32
 

Typedefs

typedef struct WaitChannel WaitChannel
 

Functions

void WaitChannel_EarlyInit ()
 
void WaitChannel_Init (WaitChannel *wc, const char *name)
 
void WaitChannel_Destroy (WaitChannel *wc)
 
void WaitChannel_Lock (WaitChannel *wc) __LOCK_EX(wc -> lock)
 
void WaitChannel_Sleep (WaitChannel *wc) __UNLOCK_EX(wc -> lock)
 
void WaitChannel_Wake (WaitChannel *wc)
 
void WaitChannel_WakeAll (WaitChannel *wc)
 

Macro Definition Documentation

◆ WAITCHANNEL_NAMELEN

#define WAITCHANNEL_NAMELEN   32

Definition at line 8 of file waitchannel.h.

Typedef Documentation

◆ WaitChannel

typedef struct WaitChannel WaitChannel

Function Documentation

◆ WaitChannel_Destroy()

void WaitChannel_Destroy ( WaitChannel wc)

Definition at line 40 of file waitchannel.c.

41{
42 ASSERT(TAILQ_EMPTY(&wchan->chanQueue));
43
45 LIST_REMOVE(wchan, chanList);
47
48 Spinlock_Destroy(&wchan->lock);
49}
#define ASSERT(_x)
Definition: kassert.h:8
#define LIST_REMOVE(elm, field)
Definition: queue.h:465
#define TAILQ_EMPTY(head)
Definition: queue.h:553
void Spinlock_Unlock(Spinlock *lock) __UNLOCK_EX(*lock)
Definition: spinlock.c:109
void Spinlock_Destroy(Spinlock *lock)
Definition: spinlock.c:61
void Spinlock_Lock(Spinlock *lock) __LOCK_EX(*lock)
Definition: spinlock.c:75
Spinlock chanListLock
Definition: waitchannel.c:18
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitChannel_EarlyInit()

void WaitChannel_EarlyInit ( )
Here is the caller graph for this function:

◆ WaitChannel_Init()

void WaitChannel_Init ( WaitChannel wc,
const char *  name 
)

Definition at line 28 of file waitchannel.c.

29{
30 TAILQ_INIT(&wchan->chanQueue);
31 strncpy(&wchan->name[0], name, WAITCHANNEL_NAMELEN);
32 Spinlock_Init(&wchan->lock, name, SPINLOCK_TYPE_NORMAL);
33
35 LIST_INSERT_HEAD(&chanList, wchan, chanList);
37}
#define TAILQ_INIT(head)
Definition: queue.h:597
#define LIST_INSERT_HEAD(head, elm, field)
Definition: queue.h:451
#define SPINLOCK_TYPE_NORMAL
Definition: spinlock.h:12
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
Definition: spinlock.c:43
char * strncpy(char *to, const char *from, size_t len)
Definition: string.c:34
#define WAITCHANNEL_NAMELEN
Definition: waitchannel.h:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ WaitChannel_Lock()

void WaitChannel_Lock ( WaitChannel wchan)

WaitChannel_Lock –

Acquires the wait channel lock.

Definition at line 57 of file waitchannel.c.

58{
59 Spinlock_Lock(&wchan->lock);
60}
Spinlock lock
Definition: waitchannel.h:12
Here is the call graph for this function:

◆ WaitChannel_Sleep()

void WaitChannel_Sleep ( WaitChannel wchan)

WaitChannel_Sleep –

Places the current thread to asleep while releasing the wait channel lock.

Side Effect: Retains a reference to thread until the thread is woken up.

Definition at line 71 of file waitchannel.c.

72{
73 Thread *thr = Sched_Current();
74
76 TAILQ_INSERT_TAIL(&wchan->chanQueue, thr, chanQueue);
77 Spinlock_Unlock(&wchan->lock);
78
80}
void Sched_SetWaiting(Thread *thr)
Definition: sched.c:104
void Sched_Scheduler()
Definition: sched.c:189
Thread * Sched_Current()
Definition: sched.c:56
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:641
Definition: thread.h:31
Here is the call graph for this function:

◆ WaitChannel_Wake()

void WaitChannel_Wake ( WaitChannel wchan)

WaitChannel_Wake –

Wake up a single thread.

Side Effects: Releases the thread reference once complete.

Definition at line 91 of file waitchannel.c.

92{
93 Thread *thr;
94
95 Spinlock_Lock(&wchan->lock);
96
97 thr = TAILQ_FIRST(&wchan->chanQueue);
98 if (thr != NULL) {
99 TAILQ_REMOVE(&wchan->chanQueue, thr, chanQueue);
101 Thread_Release(thr);
102 }
103
104 Spinlock_Unlock(&wchan->lock);
105}
void Thread_Release(Thread *thr)
Definition: thread.c:265
void Sched_SetRunnable(Thread *thr)
Definition: sched.c:77
#define TAILQ_FIRST(head)
Definition: queue.h:555
#define TAILQ_REMOVE(head, elm, field)
Definition: queue.h:659
#define NULL
Definition: stddef.h:6
Here is the call graph for this function:

◆ WaitChannel_WakeAll()

void WaitChannel_WakeAll ( WaitChannel wchan)

WaitChannel_WakeAll –

Wakes up all threads currently sleeping on the wait channel.

Side Effects: Releases all thread references.

Definition at line 116 of file waitchannel.c.

117{
118 Thread *thr;
119 Thread *thrTemp;
120
121 Spinlock_Lock(&wchan->lock);
122
123 TAILQ_FOREACH_SAFE(thr, &wchan->chanQueue, chanQueue, thrTemp) {
124 TAILQ_REMOVE(&wchan->chanQueue, thr, chanQueue);
126 Thread_Release(thr);
127 }
128
129 Spinlock_Unlock(&wchan->lock);
130}
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:567
Here is the call graph for this function: