LF OS
Hobby operating system for amd64 with high ambitions
Loading...
Searching...
No Matches
mutex.c File Reference

(7c4d7d1 userspace/term: change eyecandy inclusion to use objcopy instead of xxd)

#include <tpa.h>
#include <vm.h>
#include <panic.h>
#include <mutex.h>
#include <log.h>
#include <scheduler.h>
#include <errno.h>
+ Include dependency graph for mutex.c:

Go to the source code of this file.

Data Structures

struct  mutex_data
 

Functions

void init_mutex (void)
 
mutex_t mutex_create (void)
 
void mutex_destroy (mutex_t mutex)
 
bool mutex_lock (mutex_t mutex, pid_t holder)
 
bool mutex_unlock (mutex_t mutex, pid_t holder)
 
void mutex_unlock_holder (pid_t pid)
 
void sc_handle_locking_create_mutex (uint64_t *mutex, uint64_t *error)
 
void sc_handle_locking_destroy_mutex (uint64_t mutex, uint64_t *error)
 
void sc_handle_locking_lock_mutex (uint64_t mutex, bool trylock, uint64_t *error)
 
void sc_handle_locking_unlock_mutex (uint64_t mutex, uint64_t *error)
 

Variables

static tpa_tmutexes
 
static uint64_t next_mutex = 1
 

Data Structure Documentation

◆ mutex_data

struct mutex_data

Definition at line 12 of file mutex.c.

+ Collaboration diagram for mutex_data:
Data Fields
pid_t holder PID of the process who holds the current lock.
int state Current state of this mutex, 0 = unlocked.

Function Documentation

◆ init_mutex()

void init_mutex ( void  )

Definition at line 20 of file mutex.c.

References kernel_alloc, mutexes, and tpa_new().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutex_create()

mutex_t mutex_create ( void  )

Definition at line 24 of file mutex.c.

References mutexes, next_mutex, panic_message(), mutex_data::state, and tpa_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutex_destroy()

void mutex_destroy ( mutex_t  mutex)

Definition at line 38 of file mutex.c.

References logw, mutex, mutexes, panic_message(), mutex_data::state, tpa_get(), and tpa_set().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutex_lock()

bool mutex_lock ( mutex_t  mutex,
pid_t  holder 
)

Definition at line 52 of file mutex.c.

References mutex_data::holder, mutex, mutexes, panic_message(), mutex_data::state, and tpa_get().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutex_unlock()

bool mutex_unlock ( mutex_t  mutex,
pid_t  holder 
)

Definition at line 68 of file mutex.c.

References mutex_data::holder, logw, mutex, wait_data::mutex, mutexes, panic_message(), scheduler_waitable_done(), mutex_data::state, tpa_get(), and wait_reason_mutex.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutex_unlock_holder()

void mutex_unlock_holder ( pid_t  pid)

Definition at line 95 of file mutex.c.

References mutex_data::holder, logd, logw, mutex, mutex_unlock(), mutexes, pid, mutex_data::state, tpa_get(), and tpa_next().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sc_handle_locking_create_mutex()

void sc_handle_locking_create_mutex ( uint64_t mutex,
uint64_t error 
)

Definition at line 117 of file mutex.c.

References ENOMEM, error, logw, mutex, mutex_create(), and next_mutex.

+ Here is the call graph for this function:

◆ sc_handle_locking_destroy_mutex()

void sc_handle_locking_destroy_mutex ( uint64_t  mutex,
uint64_t error 
)

Definition at line 128 of file mutex.c.

References EBUSY, EINVAL, error, mutex, mutex_destroy(), mutexes, mutex_data::state, and tpa_get().

+ Here is the call graph for this function:

◆ sc_handle_locking_lock_mutex()

void sc_handle_locking_lock_mutex ( uint64_t  mutex,
bool  trylock,
uint64_t error 
)

Definition at line 144 of file mutex.c.

References EBUSY, EINVAL, error, mutex_data::holder, logw, mutex, wait_data::mutex, mutex_lock(), mutexes, scheduler_current_process, scheduler_wait_for(), mutex_data::state, tpa_get(), trylock, and wait_reason_mutex.

+ Here is the call graph for this function:

◆ sc_handle_locking_unlock_mutex()

void sc_handle_locking_unlock_mutex ( uint64_t  mutex,
uint64_t error 
)

Definition at line 184 of file mutex.c.

References EINVAL, EPERM, error, mutex_data::holder, mutex, mutex_unlock(), mutexes, scheduler_current_process, mutex_data::state, and tpa_get().

+ Here is the call graph for this function:

Variable Documentation

◆ mutexes

tpa_t* mutexes
static

Definition at line 9 of file mutex.c.

◆ next_mutex

uint64_t next_mutex = 1
static

Definition at line 10 of file mutex.c.