Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/upipe-pthread/umutex_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ extern "C" {
*/
struct umutex *umutex_pthread_alloc(const pthread_mutexattr_t *mutexattr);

/** @This tries to lock a mutex.
*
* @param umutex pointer to a umutex structure
* @return an error code, UBASE_ERR_BUSY for EBUSY
*/
int umutex_pthread_trylock(struct umutex *umutex);

#ifdef __cplusplus
}
#endif
Expand Down
17 changes: 17 additions & 0 deletions lib/upipe-pthread/umutex_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ static inline int umutex_pthread_lock(struct umutex *umutex)
}
}

/** @This tries to lock a mutex.
*
* @param umutex pointer to a umutex structure
* @return an error code, UBASE_ERR_BUSY for EBUSY
*/
int umutex_pthread_trylock(struct umutex *umutex)
{
struct umutex_pthread *umutex_pthread = umutex_pthread_from_umutex(umutex);
int err = pthread_mutex_trylock(&umutex_pthread->mutex);
switch (err) {
case 0: return UBASE_ERR_NONE;
case EBUSY: return UBASE_ERR_BUSY;
default:
case EINVAL: return UBASE_ERR_INVALID;
}
}

/** @This unlocks a mutex.
*
* @param umutex pointer to a umutex structure
Expand Down
Loading