PengZheng commented on code in PR #591: URL: https://github.com/apache/celix/pull/591#discussion_r1278798213
########## libs/utils/include/celix_threads.h: ########## @@ -90,34 +95,155 @@ CELIX_UTILS_EXPORT celix_status_t celixThreadMutex_create(celix_thread_mutex_t * CELIX_UTILS_EXPORT celix_status_t celixThreadMutex_destroy(celix_thread_mutex_t *mutex); +CELIX_DEFINE_AUTOPTR_CLEANUP_FUNC(celix_thread_mutex_t, celixThreadMutex_destroy) + CELIX_UTILS_EXPORT celix_status_t celixThreadMutex_lock(celix_thread_mutex_t *mutex); +CELIX_UTILS_EXPORT celix_status_t celixThreadMutex_tryLock(celix_thread_mutex_t *mutex); + CELIX_UTILS_EXPORT celix_status_t celixThreadMutex_unlock(celix_thread_mutex_t *mutex); +/** + * Opaque type. See celix_mutex_locker_new() for details. + */ +typedef void celix_mutex_locker_t; + +/** + * @brief Lock @a mutex and return a new celix_mutex_locker_t. + * + * Unlock with celixThreadMutexLocker_free(). Using celixThreadMutex_lock() on @a mutex + * while a celix_mutex_locker_t exists can lead to undefined behaviour. + * + * No allocation is performed, it is equivalent to a celixThreadMutex_lock() call. + * This is intended to be used with celix_autoptr(). + * + * @param mutex A mutex to lock + * @return A new locker to be used with celix_autoptr(). + */ +static inline celix_mutex_locker_t* celixThreadMutexLocker_new(celix_thread_mutex_t* mutex) { Review Comment: I agree that new/free is misleading. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org