-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreadwrappers.c
70 lines (55 loc) · 1.91 KB
/
threadwrappers.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**********************************************************************
Module: threadwrappers.c
Author: Daniel Rea and Junseok Lee
Purpose: error-checking wrappers for pthread functions
For distribution to students. Not all functions implemented.
This is just from my solution with parts removed.
Treat it as a guide. Feel free to implement,
change, remove, etc, in your own solution.
**********************************************************************/
#include <errno.h>
#include <stdio.h>
#include "threadwrappers.h"
/********************Status check function used by functions below***************/
int statusCheck(int s)
{
if ((errno = s) != 0)
perror(NULL);
return s;
}
/********************Mutex functions***************/
int wrappedMutexInit(pthread_mutex_t *__mutex, const pthread_mutexattr_t *__mutexattr)
{
return statusCheck(pthread_mutex_init(__mutex,__mutexattr));
}
int wrappedMutexLock(pthread_mutex_t *__mutex)
{
return statusCheck(pthread_mutex_lock(__mutex));
}
int wrappedMutexUnlock(pthread_mutex_t *__mutex)
{
return statusCheck(pthread_mutex_unlock(__mutex));
}
/********************Thread functions***************/
int wrappedPthreadCreate(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine) (void *), void *arg)
{
return statusCheck(pthread_create(thread, attr, start_routine, arg));
}
int wrappedPthreadJoin(pthread_t __th, void **__thread_return)
{
return statusCheck(pthread_join(__th, __thread_return));
}
/********************Thread conditional functions***************/
int wrappedCondSignal(pthread_cond_t *__cond)
{
return statusCheck(pthread_cond_signal(__cond));
}
int wrappedCondWait(pthread_cond_t *__restrict__ __cond, pthread_mutex_t *__restrict__ __mutex)
{
return statusCheck(pthread_cond_wait(__cond, __mutex));
}
int wrappedPthreadBroadcast(pthread_cond_t *__cond)
{
return statusCheck(pthread_cond_broadcast(__cond));
}