CS350 COS
COS
Loading...
Searching...
No Matches
mutex.c
Go to the documentation of this file.
1
2#include <stdbool.h>
3#include <stdint.h>
4
5#include <syscall.h>
6#include <core/mutex.h>
7
8void
10{
11 mtx->lock = 0;
12}
13
14
15void
17{
18 while (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
20 }
21}
22
23bool
25{
26 if (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
27 return false;
28 } else {
29 return true;
30 }
31}
32
33void
35{
36 __sync_lock_release(&mtx->lock);
37}
38
uint64_t lock
Definition: mutex.h:6
Definition: mutex.h:5
int OSThreadSleep(uint64_t time)
Definition: syscall.c:125
void CoreMutex_Lock(CoreMutex *mtx)
Definition: mutex.c:16
void CoreMutex_Unlock(CoreMutex *mtx)
Definition: mutex.c:34
bool CoreMutex_TryLock(CoreMutex *mtx)
Definition: mutex.c:24
void CoreMutex_Init(CoreMutex *mtx)
Definition: mutex.c:9