diff options
author | Ed Schouten <ed@FreeBSD.org> | 2014-09-01 18:34:30 +0000 |
---|---|---|
committer | Ed Schouten <ed@FreeBSD.org> | 2014-09-01 18:34:30 +0000 |
commit | 49891e45d2411861e1d976964f281dd1baf37823 (patch) | |
tree | 7bacf95573a248181c5695c81c668d0753fbfe08 /lib/libstdthreads/threads.h | |
parent | e562d2dad700674b9c2c87a011f45008f62fdbf7 (diff) |
Add lock annotations to the header files of our threading libraries.
This change extends all of the functions present in the <pthread.h> and
<threads.h> headers to have lock annotations. This will allow Clang to
warn about the following:
- Locking a function twice,
- Unlocking a function without a mutex being locked,
- Forgetting to unlock a mutex before returning,
- Destroying or reinitializing a mutex that is currenty locked,
- Using an unlocked mutex in combination with a condition variable.
Enabling these annotations already allowed me to catch a bug in one of
our userspace tools (r270749).
Notes
Notes:
svn path=/head/; revision=270943
Diffstat (limited to 'lib/libstdthreads/threads.h')
-rw-r--r-- | lib/libstdthreads/threads.h | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/libstdthreads/threads.h b/lib/libstdthreads/threads.h index aba9ca13df3c..6f322a5af13e 100644 --- a/lib/libstdthreads/threads.h +++ b/lib/libstdthreads/threads.h @@ -79,15 +79,24 @@ int cnd_broadcast(cnd_t *); void cnd_destroy(cnd_t *); int cnd_init(cnd_t *); int cnd_signal(cnd_t *); -int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, - const struct timespec *__restrict); -int cnd_wait(cnd_t *, mtx_t *); -void mtx_destroy(mtx_t *); -int mtx_init(mtx_t *, int); -int mtx_lock(mtx_t *); -int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); -int mtx_trylock(mtx_t *); -int mtx_unlock(mtx_t *); +int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict __mtx, + const struct timespec *__restrict) + __requires_exclusive(*__mtx); +int cnd_wait(cnd_t *, mtx_t *__mtx) + __requires_exclusive(*__mtx); +void mtx_destroy(mtx_t *__mtx) + __requires_unlocked(*__mtx); +int mtx_init(mtx_t *__mtx, int) + __requires_unlocked(*__mtx); +int mtx_lock(mtx_t *__mtx) + __locks_exclusive(*__mtx); +int mtx_timedlock(mtx_t *__restrict __mtx, + const struct timespec *__restrict) + __trylocks_exclusive(thrd_success, *__mtx); +int mtx_trylock(mtx_t *__mtx) + __trylocks_exclusive(thrd_success, *__mtx); +int mtx_unlock(mtx_t *__mtx) + __unlocks(*__mtx); int thrd_create(thrd_t *, thrd_start_t, void *); thrd_t thrd_current(void); int thrd_detach(thrd_t); |