29d4392ca0
I put the helper functions in a separate header file, because they don't fit anywhere else. pthread_mutex_{lock,unlock} is used in two places: nss-systemd and hashmap. I don't indent to convert hashmap to use the helpers, because there it'd make the code more complicated. Is it worth to create a new header file even if the only use is in nss-systemd.c? I think yes, because it feels clean and also I think it's likely that pthread_mutex_{lock,unlock} will be used in other places later.
17 lines
418 B
C
17 lines
418 B
C
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
#pragma once
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "macro.h"
|
|
|
|
static inline pthread_mutex_t* pthread_mutex_lock_assert(pthread_mutex_t *mutex) {
|
|
assert_se(pthread_mutex_lock(mutex) == 0);
|
|
return mutex;
|
|
}
|
|
|
|
static inline void pthread_mutex_unlock_assertp(pthread_mutex_t **mutexp) {
|
|
if (*mutexp)
|
|
assert_se(pthread_mutex_unlock(*mutexp) == 0);
|
|
}
|