diff options
author | Emil Velikov <emil.velikov@collabora.com> | 2016-04-24 16:14:04 +0100 |
---|---|---|
committer | Emil Velikov <emil.l.velikov@gmail.com> | 2016-05-23 12:07:45 +0100 |
commit | 6ce11e7e2c6be033e0d712fc39359de7b955c2bf (patch) | |
tree | 8cd3b4f1488a6f9f80fc74e37f0f7d798ddbb56e /include | |
parent | 4424bf5da4f9cd18bb30fc14d1d8403e4ec6caff (diff) |
c11/threads: create mutexattrs only when needed
If the mutexattrs are the default one can just pass NULL to
pthread_mutex_init. As the compiler does not know this detail it
unnecessarily creates/destroys the attrs.
Signed-off-by: Emil Velikov <emil.velikov@collabora.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/c11/threads_posix.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/c11/threads_posix.h b/include/c11/threads_posix.h index ce9853b18b..11d36e4623 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; |