summaryrefslogtreecommitdiffstats
path: root/lib/libstdthreads
diff options
context:
space:
mode:
authored <ed@FreeBSD.org>2014-09-01 18:34:30 +0000
committered <ed@FreeBSD.org>2014-09-01 18:34:30 +0000
commit72b4dec586dbec62ce27c16a908955fb89c58235 (patch)
tree7bacf95573a248181c5695c81c668d0753fbfe08 /lib/libstdthreads
parentb51450dbbdf2d19842d1a554666b09373d8912c1 (diff)
downloadFreeBSD-src-72b4dec586dbec62ce27c16a908955fb89c58235.zip
FreeBSD-src-72b4dec586dbec62ce27c16a908955fb89c58235.tar.gz
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).
Diffstat (limited to 'lib/libstdthreads')
-rw-r--r--lib/libstdthreads/threads.h27
1 files changed, 18 insertions, 9 deletions
diff --git a/lib/libstdthreads/threads.h b/lib/libstdthreads/threads.h
index aba9ca1..6f322a5 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);
OpenPOWER on IntegriCloud