mirror of
https://github.com/Hizenberg469/MultiThreading_Part_A.git
synced 2026-04-20 02:22:23 +03:00
Recursive Mutex
This commit is contained in:
40
RecursiveMutex/RecursiveMutex.h
Normal file
40
RecursiveMutex/RecursiveMutex.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef __REC_MUTEX__
|
||||
#define __REC_MUTEX__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct rec_mutex_ {
|
||||
|
||||
/* number of locks by same threads*/
|
||||
uint16_t nLocks;
|
||||
|
||||
/* Thread ID to lock the thread */
|
||||
pthread_t lockingThread;
|
||||
|
||||
/* Condition variable to block all the other thread
|
||||
for accessing the C.S */
|
||||
pthread_cond_t cv;
|
||||
|
||||
/* mutex to provide mutual exclusiveness for
|
||||
changing the state of the recursive mutex */
|
||||
pthread_mutex_t stateMutex;
|
||||
|
||||
/* Number of thread waiting for this mutex lock grant*/
|
||||
uint16_t nWaited;
|
||||
}rec_mutex_t;
|
||||
|
||||
void
|
||||
rec_mutex_init(rec_mutex_t* mutex);
|
||||
|
||||
void
|
||||
rec_mutex_lock(rec_mutex_t* mutex);
|
||||
|
||||
void
|
||||
rec_mutex_unlock(rec_mutex_t* mutex);
|
||||
|
||||
void
|
||||
rec_mutex_destroy(rec_mutex_t* mutex);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user