diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-05-23 17:15:23 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-05-23 17:15:23 +0000 |
commit | 62a7522f316acf205715a3585b9e4ce260062823 (patch) | |
tree | 98fa0486b684840d6e1aa29f3388bbcbaa38af9a /include | |
parent | 398097da5064c5b7fe408eb4ff4b5896df83d9f4 (diff) |
backport some mutex initialization and linked list handling fixes from trunk
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@29732 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include')
-rw-r--r-- | include/asterisk/linkedlists.h | 50 | ||||
-rw-r--r-- | include/asterisk/lock.h | 21 |
2 files changed, 56 insertions, 15 deletions
diff --git a/include/asterisk/linkedlists.h b/include/asterisk/linkedlists.h index 5f8a57b16..fec406f6e 100644 --- a/include/asterisk/linkedlists.h +++ b/include/asterisk/linkedlists.h @@ -101,6 +101,23 @@ struct name { \ } /*! + \brief Defines initial values for a declaration of AST_LIST_HEAD +*/ +#define AST_LIST_HEAD_INIT_VALUE { \ + .first = NULL, \ + .last = NULL, \ + .lock = AST_MUTEX_INIT_VALUE, \ + } + +/*! + \brief Defines initial values for a declaration of AST_LIST_HEAD_NOLOCK +*/ +#define AST_LIST_HEAD_NOLOCK_INIT_VALUE { \ + .first = NULL, \ + .last = NULL, \ + } + +/*! \brief Defines a structure to be used to hold a list of specified type, statically initialized. \param name This will be the name of the defined structure. \param type This is the type of each list entry. @@ -122,11 +139,18 @@ struct name { \ struct type *first; \ struct type *last; \ ast_mutex_t lock; \ -} name = { \ - .first = NULL, \ - .last = NULL, \ - .lock = AST_MUTEX_INIT_VALUE, \ -}; +} name = AST_LIST_HEAD_INIT_VALUE + +/*! + \brief Defines a structure to be used to hold a list of specified type, statically initialized. + + This is the same as AST_LIST_HEAD_STATIC, except without the lock included. +*/ +#define AST_LIST_HEAD_NOLOCK_STATIC(name, type) \ +struct name { \ + struct type *first; \ + struct type *last; \ +} name = AST_LIST_HEAD_NOLOCK_INIT_VALUE /*! \brief Initializes a list head structure with a specified first entry. @@ -184,6 +208,12 @@ struct { \ #define AST_LIST_FIRST(head) ((head)->first) /*! + \brief Returns the last entry contained in a list. + \param head This is a pointer to the list tail structure + */ +#define AST_LIST_LAST(head) ((head)->last) + +/*! \brief Returns the next entry in the list after the given entry. \param elm This is a pointer to the current entry. \param field This is the name of the field (declared using AST_LIST_ENTRY()) @@ -433,11 +463,13 @@ struct { \ (head)->last = NULL; \ } else { \ typeof(elm) curelm = (head)->first; \ - while (curelm->field.next != (elm)) \ + while (curelm && (curelm->field.next != (elm))) \ curelm = curelm->field.next; \ - curelm->field.next = (elm)->field.next; \ - if ((head)->last == (elm)) \ - (head)->last = curelm; \ + if (curelm) { \ + curelm->field.next = (elm)->field.next; \ + if ((head)->last == (elm)) \ + (head)->last = curelm; \ + } \ } \ (elm)->field.next = NULL; \ } while (0) diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index 38c4e64ac..cf9549751 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -97,6 +97,13 @@ typedef struct ast_mutex_info ast_mutex_t; typedef pthread_cond_t ast_cond_t; +static pthread_mutex_t empty_mutex; + +static void __attribute__((constructor)) init_empty_mutex(void) +{ + memset(&empty_mutex, 0, sizeof(empty_mutex)); +} + static inline int __ast_pthread_mutex_init_attr(const char *filename, int lineno, const char *func, const char *mutex_name, ast_mutex_t *t, pthread_mutexattr_t *attr) @@ -105,14 +112,16 @@ static inline int __ast_pthread_mutex_init_attr(const char *filename, int lineno int canlog = strcmp(filename, "logger.c"); if ((t->mutex) != ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)) { - __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is already initialized.\n", - filename, lineno, func, mutex_name); - __ast_mutex_logger("%s line %d (%s): Error: previously initialization of mutex '%s'.\n", - t->file, t->lineno, t->func, mutex_name); + if ((t->mutex) != (empty_mutex)) { + __ast_mutex_logger("%s line %d (%s): Error: mutex '%s' is already initialized.\n", + filename, lineno, func, mutex_name); + __ast_mutex_logger("%s line %d (%s): Error: previously initialization of mutex '%s'.\n", + t->file, t->lineno, t->func, mutex_name); #ifdef THREAD_CRASH - DO_THREAD_CRASH; + DO_THREAD_CRASH; #endif - return 0; + return 0; + } } #endif |