diff options
author | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-04-09 18:08:20 +0000 |
---|---|---|
committer | tilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b> | 2009-04-09 18:08:20 +0000 |
commit | 5767f353c49c6995efe206378c0f5532209f9f48 (patch) | |
tree | 3b5ef6bff93ccde619c1efe0652a0c16a0fa8480 /include | |
parent | 07d8da88112b3b31ee52b6a1b383435c577227f9 (diff) |
Race condition between ast_cli_command() and 'module unload' could cause a deadlock.
Add lock timeouts to avoid this potential deadlock.
(closes issue #14705)
Reported by: jamessan
Patches:
20090320__bug14705.diff.txt uploaded by tilghman (license 14)
Tested by: jamessan
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@187428 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/lock.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index bcf802451..142ce5a11 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -993,6 +993,72 @@ static inline int _ast_rwlock_wrlock(ast_rwlock_t *lock, const char *name, return res; } +#define ast_rwlock_timedrdlock(a,b) \ + _ast_rwlock_timedrdlock(a, # a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__) + +static inline int _ast_rwlock_rdlock(ast_rwlock_t *lock, const char *name, + const struct timespec *abs_timeout, const char *file, int line, const char *func) +{ + int res; +#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS + int canlog = strcmp(file, "logger.c"); + + if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) { + /* Don't warn abount uninitialized lock. + * Simple try to initialize it. + * May be not needed in linux system. + */ + res = __ast_rwlock_init(file, line, func, name, lock); + if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) { + __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n", + file, line, func, name); + return res; + } + } +#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ + + ast_store_lock_info(AST_RDLOCK, file, line, func, name, lock); + res = pthread_rwlock_timedrdlock(lock, abs_timeout); + if (!res) + ast_mark_lock_acquired(lock); + else + ast_remove_lock_info(lock); + return res; +} + +#define ast_rwlock_timedwrlock(a,b) \ + _ast_rwlock_timedwrlock(a, # a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__) + +static inline int _ast_rwlock_timedwrlock(ast_rwlock_t *lock, const char *name, + const struct timespec *abs_timeout, const char *file, int line, const char *func) +{ + int res; +#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS + int canlog = strcmp(file, "logger.c"); + + if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) { + /* Don't warn abount uninitialized lock. + * Simple try to initialize it. + * May be not needed in linux system. + */ + res = __ast_rwlock_init(file, line, func, name, lock); + if (*lock == ((ast_rwlock_t) AST_RWLOCK_INIT_VALUE)) { + __ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n", + file, line, func, name); + return res; + } + } +#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ + + ast_store_lock_info(AST_WRLOCK, file, line, func, name, lock); + res = pthread_rwlock_timedwrlock(lock, abs_timeout); + if (!res) + ast_mark_lock_acquired(lock); + else + ast_remove_lock_info(lock); + return res; +} + #define ast_rwlock_tryrdlock(a) \ _ast_rwlock_tryrdlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__) @@ -1092,6 +1158,11 @@ static inline int ast_rwlock_rdlock(ast_rwlock_t *prwlock) return pthread_rwlock_rdlock(prwlock); } +static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) +{ + return pthread_rwlock_timedrdlock(prwlock, abs_timeout); +} + static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock) { return pthread_rwlock_tryrdlock(prwlock); @@ -1102,6 +1173,11 @@ static inline int ast_rwlock_wrlock(ast_rwlock_t *prwlock) return pthread_rwlock_wrlock(prwlock); } +static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout) +{ + return pthread_rwlock_timedwrlock(prwlock, abs_timeout); +} + static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock) { return pthread_rwlock_trywrlock(prwlock); |