diff options
| author | Greg Hudson <ghudson@mit.edu> | 2013-05-10 14:01:48 -0400 |
|---|---|---|
| committer | Greg Hudson <ghudson@mit.edu> | 2013-05-14 13:31:41 -0400 |
| commit | 6350fd0c909d84c00200885e722cc902049ada05 (patch) | |
| tree | a880eae4b875d2b94747048a7092f619c79d33c2 /src/include | |
| parent | 1799f7b5d9cf4390148248d603d99a3695ddfafe (diff) | |
| download | krb5-6350fd0c909d84c00200885e722cc902049ada05.tar.gz krb5-6350fd0c909d84c00200885e722cc902049ada05.tar.xz krb5-6350fd0c909d84c00200885e722cc902049ada05.zip | |
Assume mutex locking cannot fail
Locking and unlocking a non-recursive mutex is a simple memory
operation and should not fail on any reasonable platform with correct
usage. A pthread mutex can return EDEADLK on lock or EPERM on unlock,
or EINVAL if the mutex is uninitialized, but all of these conditions
would reflect serious bugs in the calling code.
Change the k5_mutex_lock and k5_mutex_unlock wrappers to return void
and adjust all call sites. Propagate this change through
k5_cc_mutex_lock and k5_cc_mutex_unlock as well.
Diffstat (limited to 'src/include')
| -rw-r--r-- | src/include/k5-thread.h | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h index 17ef69ee7..1b7fa6981 100644 --- a/src/include/k5-thread.h +++ b/src/include/k5-thread.h @@ -378,17 +378,17 @@ static inline int k5_mutex_finish_init(k5_mutex_t *m) #define k5_mutex_destroy(M) \ (k5_os_mutex_destroy(M)) -#if __GNUC__ >= 4 -static int k5_mutex_lock(k5_mutex_t *) - __attribute__((warn_unused_result)); -#endif -static inline int k5_mutex_lock(k5_mutex_t *m) +static inline void k5_mutex_lock(k5_mutex_t *m) { - return k5_os_mutex_lock(m); + int r = k5_os_mutex_lock(m); + assert(r == 0); } -#define k5_mutex_unlock(M) \ - (k5_os_mutex_unlock(M)) +static inline void k5_mutex_unlock(k5_mutex_t *m) +{ + int r = k5_os_mutex_unlock(m); + assert(r == 0); +} #define k5_mutex_assert_locked(M) ((void)(M)) #define k5_mutex_assert_unlocked(M) ((void)(M)) @@ -423,12 +423,8 @@ extern int k5_key_delete(k5_key_t); extern int KRB5_CALLCONV krb5int_mutex_alloc (k5_mutex_t **); extern void KRB5_CALLCONV krb5int_mutex_free (k5_mutex_t *); -extern int KRB5_CALLCONV krb5int_mutex_lock (k5_mutex_t *) -#if __GNUC__ >= 4 - __attribute__((warn_unused_result)) -#endif - ; -extern int KRB5_CALLCONV krb5int_mutex_unlock (k5_mutex_t *); +extern void KRB5_CALLCONV krb5int_mutex_lock (k5_mutex_t *); +extern void KRB5_CALLCONV krb5int_mutex_unlock (k5_mutex_t *); /* In time, many of the definitions above should move into the support library, and this file should be greatly simplified. For type |
