aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorEd Schouten <ed@FreeBSD.org>2014-09-01 18:34:30 +0000
committerEd Schouten <ed@FreeBSD.org>2014-09-01 18:34:30 +0000
commit49891e45d2411861e1d976964f281dd1baf37823 (patch)
tree7bacf95573a248181c5695c81c668d0753fbfe08 /include
parente562d2dad700674b9c2c87a011f45008f62fdbf7 (diff)
downloadsrc-49891e45d2411861e1d976964f281dd1baf37823.tar.gz
src-49891e45d2411861e1d976964f281dd1baf37823.zip
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 'include')
-rw-r--r--include/pthread.h76
1 files changed, 49 insertions, 27 deletions
diff --git a/include/pthread.h b/include/pthread.h
index 3b56dbdbf749..c6356dea32b3 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -193,8 +193,10 @@ int pthread_cond_init(pthread_cond_t *,
const pthread_condattr_t *);
int pthread_cond_signal(pthread_cond_t *);
int pthread_cond_timedwait(pthread_cond_t *,
- pthread_mutex_t *, const struct timespec *);
-int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
+ pthread_mutex_t *__mutex, const struct timespec *)
+ __requires_exclusive(*__mutex);
+int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *__mutex)
+ __requires_exclusive(*__mutex);
int pthread_create(pthread_t *, const pthread_attr_t *,
void *(*) (void *), void *);
int pthread_detach(pthread_t);
@@ -213,27 +215,42 @@ int pthread_mutexattr_getpshared(const pthread_mutexattr_t *,
int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *);
int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int);
-int pthread_mutex_destroy(pthread_mutex_t *);
-int pthread_mutex_init(pthread_mutex_t *,
- const pthread_mutexattr_t *);
-int pthread_mutex_lock(pthread_mutex_t *);
-int pthread_mutex_trylock(pthread_mutex_t *);
-int pthread_mutex_timedlock(pthread_mutex_t *,
- const struct timespec *);
-int pthread_mutex_unlock(pthread_mutex_t *);
+int pthread_mutex_destroy(pthread_mutex_t *__mutex)
+ __requires_unlocked(*__mutex);
+int pthread_mutex_init(pthread_mutex_t *__mutex,
+ const pthread_mutexattr_t *)
+ __requires_unlocked(*__mutex);
+int pthread_mutex_lock(pthread_mutex_t *__mutex)
+ __locks_exclusive(*__mutex);
+int pthread_mutex_trylock(pthread_mutex_t *__mutex)
+ __trylocks_exclusive(0, *__mutex);
+int pthread_mutex_timedlock(pthread_mutex_t *__mutex,
+ const struct timespec *)
+ __trylocks_exclusive(0, *__mutex);
+int pthread_mutex_unlock(pthread_mutex_t *__mutex)
+ __unlocks(*__mutex);
int pthread_once(pthread_once_t *, void (*) (void));
-int pthread_rwlock_destroy(pthread_rwlock_t *);
-int pthread_rwlock_init(pthread_rwlock_t *,
- const pthread_rwlockattr_t *);
-int pthread_rwlock_rdlock(pthread_rwlock_t *);
-int pthread_rwlock_timedrdlock(pthread_rwlock_t *,
- const struct timespec *);
-int pthread_rwlock_timedwrlock(pthread_rwlock_t *,
- const struct timespec *);
-int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
-int pthread_rwlock_trywrlock(pthread_rwlock_t *);
-int pthread_rwlock_unlock(pthread_rwlock_t *);
-int pthread_rwlock_wrlock(pthread_rwlock_t *);
+int pthread_rwlock_destroy(pthread_rwlock_t *__rwlock)
+ __requires_unlocked(*__rwlock);
+int pthread_rwlock_init(pthread_rwlock_t *__rwlock,
+ const pthread_rwlockattr_t *)
+ __requires_unlocked(*__rwlock);
+int pthread_rwlock_rdlock(pthread_rwlock_t *__rwlock)
+ __locks_shared(*__rwlock);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t *__rwlock,
+ const struct timespec *)
+ __trylocks_shared(0, *__rwlock);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t *__rwlock,
+ const struct timespec *)
+ __trylocks_exclusive(0, *__rwlock);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t *__rwlock)
+ __trylocks_shared(0, *__rwlock);
+int pthread_rwlock_trywrlock(pthread_rwlock_t *__rwlock)
+ __trylocks_exclusive(0, *__rwlock);
+int pthread_rwlock_unlock(pthread_rwlock_t *__rwlock)
+ __unlocks(*__rwlock);
+int pthread_rwlock_wrlock(pthread_rwlock_t *__rwlock)
+ __locks_exclusive(*__rwlock);
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
int pthread_rwlockattr_getkind_np(const pthread_rwlockattr_t *,
int *);
@@ -245,11 +262,16 @@ int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
pthread_t pthread_self(void);
int pthread_setspecific(pthread_key_t, const void *);
-int pthread_spin_init(pthread_spinlock_t *, int);
-int pthread_spin_destroy(pthread_spinlock_t *);
-int pthread_spin_lock(pthread_spinlock_t *);
-int pthread_spin_trylock(pthread_spinlock_t *);
-int pthread_spin_unlock(pthread_spinlock_t *);
+int pthread_spin_init(pthread_spinlock_t *__spin, int)
+ __requires_unlocked(*__spin);
+int pthread_spin_destroy(pthread_spinlock_t *__spin)
+ __requires_unlocked(*__spin);
+int pthread_spin_lock(pthread_spinlock_t *__spin)
+ __locks_exclusive(*__spin);
+int pthread_spin_trylock(pthread_spinlock_t *__spin)
+ __trylocks_exclusive(0, *__spin);
+int pthread_spin_unlock(pthread_spinlock_t *__spin)
+ __unlocks(*__spin);
int pthread_cancel(pthread_t);
int pthread_setcancelstate(int, int *);
int pthread_setcanceltype(int, int *);