Skip to content

Commit

Permalink
threads: add support for pthread_mutex_trylock
Browse files Browse the repository at this point in the history
  • Loading branch information
t-8ch authored and sfan5 committed Oct 20, 2023
1 parent d05ef7f commit 2181159
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions osdep/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,13 @@ int mp_ptwrap_mutex_init(const char *file, int line, pthread_mutex_t *m,
pthread_mutexattr_destroy(&m_attr);
return res;
}

int mp_ptwrap_mutex_trylock(const char *file, int line, pthread_mutex_t *m)
{
int res = (pthread_mutex_trylock)(m);

if (res != EBUSY)
mp_ptwrap_check(file, line, res);

return res;
}
5 changes: 5 additions & 0 deletions osdep/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void mpthread_set_name(const char *name);
int mp_ptwrap_check(const char *file, int line, int res);
int mp_ptwrap_mutex_init(const char *file, int line, pthread_mutex_t *m,
const pthread_mutexattr_t *attr);
int mp_ptwrap_mutex_trylock(const char *file, int line, pthread_mutex_t *m);

#ifdef MP_PTHREAD_DEBUG

Expand Down Expand Up @@ -46,6 +47,7 @@ int mp_ptwrap_mutex_init(const char *file, int line, pthread_mutex_t *m,
#undef pthread_join
#undef pthread_mutex_destroy
#undef pthread_mutex_lock
#undef pthread_mutex_trylock
#undef pthread_mutex_unlock

#define pthread_cond_init(...) MP_PTWRAP(pthread_cond_init, __VA_ARGS__)
Expand All @@ -63,6 +65,9 @@ int mp_ptwrap_mutex_init(const char *file, int line, pthread_mutex_t *m,
#define pthread_mutex_init(...) \
mp_ptwrap_mutex_init(__FILE__, __LINE__, __VA_ARGS__)

#define pthread_mutex_trylock(...) \
mp_ptwrap_mutex_trylock(__FILE__, __LINE__, __VA_ARGS__)

#endif

#endif

0 comments on commit 2181159

Please sign in to comment.