CS350 COS
COS
Loading...
Searching...
No Matches
mutex.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Ali Mashtizadeh
3 * All rights reserved.
4 */
5
6#include <stdbool.h>
7#include <stdint.h>
8#include <string.h>
9
10#include <sys/cdefs.h>
11#include <sys/kassert.h>
12#include <sys/kconfig.h>
13#include <sys/kdebug.h>
14#include <sys/kmem.h>
15#include <sys/mp.h>
16#include <sys/queue.h>
17#include <sys/thread.h>
18#include <sys/spinlock.h>
19#include <sys/waitchannel.h>
20#include <sys/mutex.h>
21#include <errno.h>
22
23/*
24 * For debugging so we can assert the owner without holding a reference to the
25 * thread. You can access the current thread through curProc[CPU()].
26 */
27extern Thread *curProc[MAX_CPUS];
28
29void
30Mutex_Init(Mutex *mtx, const char *name)
31{
33 WaitChannel_Init(&mtx->chan, name);
34
35 return;
36}
37
38void
40{
43 return;
44}
45
51void
53{
54 /*
55 * You cannot hold a spinlock while trying to acquire a Mutex that may
56 * sleep!
57 */
58 ASSERT(Critical_Level() == 0);
59
60 /* XXXFILLMEIN */
61}
62
69int
71{
72 /* XXXFILLMEIN */
73
74 return 0;
75}
76
82void
84{
85 /* XXXFILLMEIN */
86
87 return;
88}
89
uint32_t Critical_Level()
Definition: critical.c:45
#define ASSERT(_x)
Definition: kassert.h:8
#define MAX_CPUS
Definition: kconfig.h:8
#define SPINLOCK_TYPE_NORMAL
Definition: spinlock.h:12
void Spinlock_Destroy(Spinlock *lock)
Definition: spinlock.c:61
void Spinlock_Init(Spinlock *lock, const char *name, uint64_t type)
Definition: spinlock.c:43
Definition: mutex.h:8
WaitChannel chan
Definition: mutex.h:12
Spinlock lock
Definition: mutex.h:11
Definition: thread.h:31
void Mutex_Destroy(Mutex *mtx)
Definition: mutex.c:39
void Mutex_Unlock(Mutex *mtx)
Definition: mutex.c:83
void Mutex_Lock(Mutex *mtx)
Definition: mutex.c:52
Thread * curProc[MAX_CPUS]
Definition: sched.c:41
void Mutex_Init(Mutex *mtx, const char *name)
Definition: mutex.c:30
int Mutex_TryLock(Mutex *mtx)
Definition: mutex.c:70
void WaitChannel_Init(WaitChannel *wc, const char *name)
Definition: waitchannel.c:28
void WaitChannel_Destroy(WaitChannel *wc)
Definition: waitchannel.c:40