CS350 COS
COS
Loading...
Searching...
No Matches
mutex.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include <syscall.h>
#include <core/mutex.h>
Include dependency graph for mutex.c:

Go to the source code of this file.

Functions

void CoreMutex_Init (CoreMutex *mtx)
 
void CoreMutex_Lock (CoreMutex *mtx)
 
bool CoreMutex_TryLock (CoreMutex *mtx)
 
void CoreMutex_Unlock (CoreMutex *mtx)
 

Function Documentation

◆ CoreMutex_Init()

void CoreMutex_Init ( CoreMutex mtx)

Definition at line 9 of file mutex.c.

10{
11 mtx->lock = 0;
12}
uint64_t lock
Definition: mutex.h:6
Here is the caller graph for this function:

◆ CoreMutex_Lock()

void CoreMutex_Lock ( CoreMutex mtx)

Definition at line 16 of file mutex.c.

17{
18 while (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
20 }
21}
int OSThreadSleep(uint64_t time)
Definition: syscall.c:125
Here is the call graph for this function:
Here is the caller graph for this function:

◆ CoreMutex_TryLock()

bool CoreMutex_TryLock ( CoreMutex mtx)

Definition at line 24 of file mutex.c.

25{
26 if (__sync_lock_test_and_set(&mtx->lock, 1) == 1) {
27 return false;
28 } else {
29 return true;
30 }
31}

◆ CoreMutex_Unlock()

void CoreMutex_Unlock ( CoreMutex mtx)

Definition at line 34 of file mutex.c.

35{
36 __sync_lock_release(&mtx->lock);
37}
Here is the caller graph for this function: