atom_* renamed to atomic_*; add mutex.*

This commit is contained in:
2022-08-31 08:57:57 +02:00
parent f9856341c1
commit 330efbdbb2
7 changed files with 52 additions and 12 deletions

24
mutex.c Normal file
View File

@@ -0,0 +1,24 @@
/*
* Copyright 2022 Oleg Borodin <borodin@unix7.org>
*/
#include "mutex.h"
#include "atomic.h"
void mutex_init(mutex_t* mutex) {
mutex->value = 1;
}
int32_t mutex_wait(mutex_t* mutex) {
//while(mutex->value <= 0);
//mutex->value--;
//return mutex->value;
while (atomic_dec32(&(mutex->value), (int32_t)0) <= 0);
return atomic_dec32(&(mutex->value), (int32_t)1);
}
int32_t mutex_post(mutex_t* mutex) {
//mutex->value++;
//return mutex->value;
return atomic_inc32(&(mutex->value), (int32_t)1);
}