-
Notifications
You must be signed in to change notification settings - Fork 0
/
myPthreads.c
45 lines (38 loc) · 1.01 KB
/
myPthreads.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include "shared_data.h"
// --------------PTHREAD--------------
void Pthread_mutex_lock(pthread_mutex_t* mutex) {
int err;
if((err = pthread_mutex_lock(&(*mutex))) != 0){
errno = err;
perror("In lock acquire");
pthread_exit(&errno);
}
}
void Pthread_mutex_unlock(pthread_mutex_t* mutex) {
int err;
if((err = pthread_mutex_unlock(&(*mutex))) != 0){
errno = err;
perror("In lock release");
pthread_exit(&errno);
}
}
void Pthread_cond_signal(pthread_cond_t* condition) {
int err;
if((err = pthread_cond_signal(&(*condition))) != 0){
errno = err;
perror("Sending signal");
pthread_exit(&errno);
}
}
void Pthread_cond_wait(pthread_cond_t* condition, pthread_mutex_t* mutex) {
int err;
if((err = pthread_cond_wait(&(*condition), &(*mutex))) != 0){
errno = err;
perror("Waiting signal");
pthread_exit(&errno);
}
}