Remove ABI differences that occured when compiling with DEBUG_THREADS.

"Bad Things" would happen if Asterisk was compiled with DEBUG_THREADS, but a
loaded module was not (or vice versa).  This also immensely simplifies the
lock code, since there are no longer 2 separate versions of them.

Review: https://reviewboard.asterisk.org/r/508/


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@258557 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Jason Parker
2010-04-22 19:08:01 +00:00
parent a753e8878b
commit 9e3f5fa6fb
8 changed files with 1517 additions and 1632 deletions

View File

@@ -472,12 +472,8 @@ int __ao2_ref(void *o, int delta);
* \param a A pointer to the object we want to lock. * \param a A pointer to the object we want to lock.
* \return 0 on success, other values on error. * \return 0 on success, other values on error.
*/ */
#ifndef DEBUG_THREADS
int ao2_lock(void *a);
#else
#define ao2_lock(a) __ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_lock(void *a, const char *file, const char *func, int line, const char *var); int __ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
#endif #define ao2_lock(a) __ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
/*! \brief /*! \brief
* Unlock an object. * Unlock an object.
@@ -485,12 +481,8 @@ int __ao2_lock(void *a, const char *file, const char *func, int line, const char
* \param a A pointer to the object we want unlock. * \param a A pointer to the object we want unlock.
* \return 0 on success, other values on error. * \return 0 on success, other values on error.
*/ */
#ifndef DEBUG_THREADS
int ao2_unlock(void *a);
#else
#define ao2_unlock(a) __ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var); int __ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
#endif #define ao2_unlock(a) __ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
/*! \brief /*! \brief
* Try locking-- (don't block if fail) * Try locking-- (don't block if fail)
@@ -498,12 +490,8 @@ int __ao2_unlock(void *a, const char *file, const char *func, int line, const ch
* \param a A pointer to the object we want to lock. * \param a A pointer to the object we want to lock.
* \return 0 on success, other values on error. * \return 0 on success, other values on error.
*/ */
#ifndef DEBUG_THREADS
int ao2_trylock(void *a);
#else
#define ao2_trylock(a) __ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
int __ao2_trylock(void *a, const char *file, const char *func, int line, const char *var); int __ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
#endif #define ao2_trylock(a) __ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a)
/*! /*!
* \brief Return the lock address of an object * \brief Return the lock address of an object

View File

@@ -209,8 +209,6 @@ void *ast_heap_peek(struct ast_heap *h, unsigned int index);
*/ */
size_t ast_heap_size(struct ast_heap *h); size_t ast_heap_size(struct ast_heap *h);
#ifndef DEBUG_THREADS
/*! /*!
* \brief Write-Lock a heap * \brief Write-Lock a heap
* *
@@ -223,7 +221,7 @@ size_t ast_heap_size(struct ast_heap *h);
* \return see the documentation for pthread_rwlock_wrlock() * \return see the documentation for pthread_rwlock_wrlock()
* \since 1.6.1 * \since 1.6.1
*/ */
int ast_heap_wrlock(struct ast_heap *h); int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line);
/*! /*!
* \brief Read-Lock a heap * \brief Read-Lock a heap
@@ -237,7 +235,7 @@ int ast_heap_wrlock(struct ast_heap *h);
* \return see the documentation for pthread_rwlock_rdlock() * \return see the documentation for pthread_rwlock_rdlock()
* \since 1.6.1 * \since 1.6.1
*/ */
int ast_heap_rdlock(struct ast_heap *h); int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line);
/*! /*!
* \brief Unlock a heap * \brief Unlock a heap
@@ -247,18 +245,11 @@ int ast_heap_rdlock(struct ast_heap *h);
* \return see the documentation for pthread_rwlock_unlock() * \return see the documentation for pthread_rwlock_unlock()
* \since 1.6.1 * \since 1.6.1
*/ */
int ast_heap_unlock(struct ast_heap *h);
#else /* DEBUG_THREADS */
#define ast_heap_wrlock(h) __ast_heap_wrlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line);
#define ast_heap_rdlock(h) __ast_heap_rdlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line);
#define ast_heap_unlock(h) __ast_heap_unlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line); int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line);
#endif /* DEBUG_THREADS */ #define ast_heap_wrlock(h) __ast_heap_wrlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#define ast_heap_rdlock(h) __ast_heap_rdlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#define ast_heap_unlock(h) __ast_heap_unlock(h, __FILE__, __PRETTY_FUNCTION__, __LINE__)
/*! /*!
* \brief Verify that a heap has been properly constructed * \brief Verify that a heap has been properly constructed

File diff suppressed because it is too large Load Diff

View File

@@ -111,19 +111,11 @@ int ast_odbc_smart_execute(struct odbc_obj *obj, SQLHSTMT stmt) __attribute__((d
* thread which requests it. Note that all connections should be released * thread which requests it. Note that all connections should be released
* when the thread is done by calling odbc_release_obj(), below. * when the thread is done by calling odbc_release_obj(), below.
*/ */
#ifdef DEBUG_THREADS
struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags, const char *file, const char *function, int lineno); struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags, const char *file, const char *function, int lineno);
#define ast_odbc_request_obj2(a, b) _ast_odbc_request_obj2(a, b, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#else
struct odbc_obj *ast_odbc_request_obj2(const char *name, struct ast_flags flags);
#endif
#ifdef DEBUG_THREADS
struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno); struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno);
#define ast_odbc_request_obj2(a, b) _ast_odbc_request_obj2(a, b, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#define ast_odbc_request_obj(a, b) _ast_odbc_request_obj(a, b, __FILE__, __PRETTY_FUNCTION__, __LINE__) #define ast_odbc_request_obj(a, b) _ast_odbc_request_obj(a, b, __FILE__, __PRETTY_FUNCTION__, __LINE__)
#else
struct odbc_obj *ast_odbc_request_obj(const char *name, int check);
#endif
/*! /*!
* \brief Retrieve a stored ODBC object, if a transaction has been started. * \brief Retrieve a stored ODBC object, if a transaction has been started.

View File

@@ -143,11 +143,7 @@ static void *internal_ao2_callback(struct ao2_container *c,
char *tag, char *file, int line, const char *funcname); char *tag, char *file, int line, const char *funcname);
static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q); static void *internal_ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q);
#ifndef DEBUG_THREADS
int ao2_lock(void *user_data)
#else
int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var) int __ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{ {
struct astobj2 *p = INTERNAL_OBJ(user_data); struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -158,18 +154,10 @@ int __ao2_lock(void *user_data, const char *file, const char *func, int line, co
ast_atomic_fetchadd_int(&ao2.total_locked, 1); ast_atomic_fetchadd_int(&ao2.total_locked, 1);
#endif #endif
#ifndef DEBUG_THREADS
return ast_mutex_lock(&p->priv_data.lock);
#else
return __ast_pthread_mutex_lock(file, line, func, var, &p->priv_data.lock); return __ast_pthread_mutex_lock(file, line, func, var, &p->priv_data.lock);
#endif
} }
#ifndef DEBUG_THREADS
int ao2_unlock(void *user_data)
#else
int __ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var) int __ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{ {
struct astobj2 *p = INTERNAL_OBJ(user_data); struct astobj2 *p = INTERNAL_OBJ(user_data);
@@ -180,29 +168,17 @@ int __ao2_unlock(void *user_data, const char *file, const char *func, int line,
ast_atomic_fetchadd_int(&ao2.total_locked, -1); ast_atomic_fetchadd_int(&ao2.total_locked, -1);
#endif #endif
#ifndef DEBUG_THREADS
return ast_mutex_unlock(&p->priv_data.lock);
#else
return __ast_pthread_mutex_unlock(file, line, func, var, &p->priv_data.lock); return __ast_pthread_mutex_unlock(file, line, func, var, &p->priv_data.lock);
#endif
} }
#ifndef DEBUG_THREADS
int ao2_trylock(void *user_data)
#else
int __ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var) int __ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var)
#endif
{ {
struct astobj2 *p = INTERNAL_OBJ(user_data); struct astobj2 *p = INTERNAL_OBJ(user_data);
int ret; int ret;
if (p == NULL) if (p == NULL)
return -1; return -1;
#ifndef DEBUG_THREADS
ret = ast_mutex_trylock(&p->priv_data.lock);
#else
ret = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock); ret = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock);
#endif
#ifdef AO2_DEBUG #ifdef AO2_DEBUG
if (!ret) if (!ret)

View File

@@ -302,38 +302,17 @@ size_t ast_heap_size(struct ast_heap *h)
return h->cur_len; return h->cur_len;
} }
#ifndef DEBUG_THREADS
int ast_heap_wrlock(struct ast_heap *h)
{
return ast_rwlock_wrlock(&h->lock);
}
int ast_heap_rdlock(struct ast_heap *h)
{
return ast_rwlock_rdlock(&h->lock);
}
int ast_heap_unlock(struct ast_heap *h)
{
return ast_rwlock_unlock(&h->lock);
}
#else /* DEBUG_THREADS */
int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line) int __ast_heap_wrlock(struct ast_heap *h, const char *file, const char *func, int line)
{ {
return _ast_rwlock_wrlock(&h->lock, "&h->lock", file, line, func); return __ast_rwlock_wrlock(&h->lock, "&h->lock", file, line, func);
} }
int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line) int __ast_heap_rdlock(struct ast_heap *h, const char *file, const char *func, int line)
{ {
return _ast_rwlock_rdlock(&h->lock, "&h->lock", file, line, func); return __ast_rwlock_rdlock(&h->lock, "&h->lock", file, line, func);
} }
int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line) int __ast_heap_unlock(struct ast_heap *h, const char *file, const char *func, int line)
{ {
return _ast_rwlock_unlock(&h->lock, "&h->lock", file, line, func); return __ast_rwlock_unlock(&h->lock, "&h->lock", file, line, func);
} }
#endif /* DEBUG_THREADS */

1371
main/lock.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1150,11 +1150,7 @@ static int aoro2_obj_cb(void *vobj, void *arg, int flags)
return 0; return 0;
} }
#ifdef DEBUG_THREADS
struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags, const char *file, const char *function, int lineno) struct odbc_obj *_ast_odbc_request_obj2(const char *name, struct ast_flags flags, const char *file, const char *function, int lineno)
#else
struct odbc_obj *ast_odbc_request_obj2(const char *name, struct ast_flags flags)
#endif
{ {
struct odbc_obj *obj = NULL; struct odbc_obj *obj = NULL;
struct odbc_class *class; struct odbc_class *class;
@@ -1325,18 +1321,10 @@ struct odbc_obj *ast_odbc_request_obj2(const char *name, struct ast_flags flags)
return obj; return obj;
} }
#ifdef DEBUG_THREADS
struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno) struct odbc_obj *_ast_odbc_request_obj(const char *name, int check, const char *file, const char *function, int lineno)
#else
struct odbc_obj *ast_odbc_request_obj(const char *name, int check)
#endif
{ {
struct ast_flags flags = { check ? RES_ODBC_SANITY_CHECK : 0 }; struct ast_flags flags = { check ? RES_ODBC_SANITY_CHECK : 0 };
#ifdef DEBUG_THREADS
return _ast_odbc_request_obj2(name, flags, file, function, lineno); return _ast_odbc_request_obj2(name, flags, file, function, lineno);
#else
return ast_odbc_request_obj2(name, flags);
#endif
} }
struct odbc_obj *ast_odbc_retrieve_transaction_obj(struct ast_channel *chan, const char *objname) struct odbc_obj *ast_odbc_retrieve_transaction_obj(struct ast_channel *chan, const char *objname)