summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/c11/threads_posix.h9
1 files changed, 7 insertions, 2 deletions
diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h
index ce9853b18b3..11d36e46239 100644
--- a/include/c11/threads_posix.h
+++ b/include/c11/threads_posix.h
@@ -180,9 +180,14 @@ mtx_init(mtx_t *mtx, int type)
&& type != (mtx_timed|mtx_recursive)
&& type != (mtx_try|mtx_recursive))
return thrd_error;
+
+ if ((type & mtx_recursive) == 0) {
+ pthread_mutex_init(mtx, NULL);
+ return thrd_success;
+ }
+
pthread_mutexattr_init(&attr);
- if ((type & mtx_recursive) != 0)
- pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
+ pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(mtx, &attr);
pthread_mutexattr_destroy(&attr);
return thrd_success;