summaryrefslogtreecommitdiff
path: root/src/threads/mtx_init.c
blob: f161a0a1f901b9f38957319861c686a0cec82ef5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <threads.h>
#include <pthread.h>
#include <errno.h>

int mtx_init(mtx_t *mtx, int type)
{
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	if (type & mtx_recursive) {
		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
	} else {
		pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_DEFAULT);
	}
	return pthread_mutex_init(mtx, &attr) == 0 ? thrd_success : thrd_error;
}

/*
STDC(201112)
*/