whitespace only change - adjust indentation and add some

comments on the content of these two files.

utils.h (which is included in over 150 files) contains a lot of
unrelated functions which require the inclusion of a large number
of other headers.  At some point we should partition its content
in a better way.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89341 65c4cc65-6c06-0410-ace0-fbb531ad65f3
1.6.0
Luigi Rizzo 18 years ago
parent b6bd9155f3
commit 1f6dcae007

@ -17,7 +17,10 @@
*/ */
/*! \file /*! \file
* \brief General Asterisk channel locking definitions. * \brief Asterisk locking-related definitions:
* - ast_mutext_t, ast_rwlock_t and related functions;
* - atomic arithmetic instructions;
* - wrappers for channel locking.
* *
* - See \ref LockDef * - See \ref LockDef
*/ */
@ -46,8 +49,6 @@
#define _ASTERISK_LOCK_H #define _ASTERISK_LOCK_H
#include <pthread.h> #include <pthread.h>
// #include <netdb.h>
#include <time.h>
#include <sys/param.h> #include <sys/param.h>
#include "asterisk/logger.h" #include "asterisk/logger.h"
@ -88,6 +89,13 @@
#define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE #define AST_MUTEX_KIND PTHREAD_MUTEX_RECURSIVE
#endif /* PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */ #endif /* PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP */
/*
* Definition of ast_mutex_t, ast_cont_d and related functions with/without debugging
* (search for DEBUG_THREADS to find the start/end of the sections).
*
* The non-debug code contains just wrappers for the corresponding pthread functions.
* The debug code tracks usage and tries to identify deadlock situations.
*/
#ifdef DEBUG_THREADS #ifdef DEBUG_THREADS
#define __ast_mutex_logger(...) do { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); } while (0) #define __ast_mutex_logger(...) do { if (canlog) ast_log(LOG_ERROR, __VA_ARGS__); else fprintf(stderr, __VA_ARGS__); } while (0)
@ -662,8 +670,7 @@ static inline int __ast_cond_timedwait(const char *filename, int lineno, const c
typedef pthread_mutex_t ast_mutex_t; typedef pthread_mutex_t ast_mutex_t;
#define AST_MUTEX_INIT_VALUE ((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE) #define AST_MUTEX_INIT_VALUE ((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
#define AST_MUTEX_INIT_VALUE_NOTRACKING \ #define AST_MUTEX_INIT_VALUE_NOTRACKING ((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
((ast_mutex_t) PTHREAD_MUTEX_INIT_VALUE)
#define ast_mutex_init_notracking(m) ast_mutex_init(m) #define ast_mutex_init_notracking(m) ast_mutex_init(m)
@ -737,8 +744,10 @@ static inline int ast_cond_timedwait(ast_cond_t *cond, ast_mutex_t *t, const str
#endif /* !DEBUG_THREADS */ #endif /* !DEBUG_THREADS */
#if defined(AST_MUTEX_INIT_W_CONSTRUCTORS) #if defined(AST_MUTEX_INIT_W_CONSTRUCTORS)
/* If AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope /*
destructors to destroy mutexes and create it on the fly. */ * If AST_MUTEX_INIT_W_CONSTRUCTORS is defined, use file scope constructors
* and destructors to create/destroy global mutexes.
*/
#define __AST_MUTEX_DEFINE(scope, mutex, init_val, track) \ #define __AST_MUTEX_DEFINE(scope, mutex, init_val, track) \
scope ast_mutex_t mutex = init_val; \ scope ast_mutex_t mutex = init_val; \
static void __attribute__ ((constructor)) init_##mutex(void) \ static void __attribute__ ((constructor)) init_##mutex(void) \
@ -748,14 +757,14 @@ static void __attribute__ ((constructor)) init_##mutex(void) \
else \ else \
ast_mutex_init_notracking(&mutex); \ ast_mutex_init_notracking(&mutex); \
} \ } \
\
static void __attribute__ ((destructor)) fini_##mutex(void) \ static void __attribute__ ((destructor)) fini_##mutex(void) \
{ \ { \
ast_mutex_destroy(&mutex); \ ast_mutex_destroy(&mutex); \
} }
#else /* !AST_MUTEX_INIT_W_CONSTRUCTORS */ #else /* !AST_MUTEX_INIT_W_CONSTRUCTORS */
/* By default, use static initialization of mutexes. */ /* By default, use static initialization of mutexes. */
#define __AST_MUTEX_DEFINE(scope, mutex, init_val, track) \ #define __AST_MUTEX_DEFINE(scope, mutex, init_val, track) scope ast_mutex_t mutex = init_val
scope ast_mutex_t mutex = init_val
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */ #endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
#define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t #define pthread_mutex_t use_ast_mutex_t_instead_of_pthread_mutex_t
@ -783,6 +792,12 @@ static void __attribute__ ((destructor)) fini_##mutex(void) \
#define pthread_create __use_ast_pthread_create_instead__ #define pthread_create __use_ast_pthread_create_instead__
#endif #endif
/*
* Same as above, definitions of ast_rwlock_t for the various cases:
* simple wrappers for the pthread equivalent in the non-debug case,
* more sophisticated tracking in the debug case.
*/
typedef pthread_rwlock_t ast_rwlock_t; typedef pthread_rwlock_t ast_rwlock_t;
#ifdef HAVE_PTHREAD_RWLOCK_INITIALIZER #ifdef HAVE_PTHREAD_RWLOCK_INITIALIZER
@ -794,6 +809,12 @@ typedef pthread_rwlock_t ast_rwlock_t;
#ifdef DEBUG_THREADS #ifdef DEBUG_THREADS
#define ast_rwlock_init(rwlock) __ast_rwlock_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock) #define ast_rwlock_init(rwlock) __ast_rwlock_init(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
#define ast_rwlock_destroy(rwlock) __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
#define ast_rwlock_unlock(a) _ast_rwlock_unlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_rwlock_rdlock(a) _ast_rwlock_rdlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_rwlock_wrlock(a) _ast_rwlock_wrlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_rwlock_tryrdlock(a) _ast_rwlock_tryrdlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
#define ast_rwlock_trywrlock(a) _ast_rwlock_trywrlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int __ast_rwlock_init(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock) static inline int __ast_rwlock_init(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock)
@ -820,7 +841,6 @@ static inline int __ast_rwlock_init(const char *filename, int lineno, const char
return res; return res;
} }
#define ast_rwlock_destroy(rwlock) __ast_rwlock_destroy(__FILE__, __LINE__, __PRETTY_FUNCTION__, #rwlock, rwlock)
static inline int __ast_rwlock_destroy(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock) static inline int __ast_rwlock_destroy(const char *filename, int lineno, const char *func, const char *rwlock_name, ast_rwlock_t *prwlock)
{ {
@ -842,8 +862,6 @@ static inline int __ast_rwlock_destroy(const char *filename, int lineno, const c
return res; return res;
} }
#define ast_rwlock_unlock(a) \
_ast_rwlock_unlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int _ast_rwlock_unlock(ast_rwlock_t *lock, const char *name, static inline int _ast_rwlock_unlock(ast_rwlock_t *lock, const char *name,
const char *file, int line, const char *func) const char *file, int line, const char *func)
@ -869,8 +887,6 @@ static inline int _ast_rwlock_unlock(ast_rwlock_t *lock, const char *name,
return res; return res;
} }
#define ast_rwlock_rdlock(a) \
_ast_rwlock_rdlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int _ast_rwlock_rdlock(ast_rwlock_t *lock, const char *name, static inline int _ast_rwlock_rdlock(ast_rwlock_t *lock, const char *name,
const char *file, int line, const char *func) const char *file, int line, const char *func)
@ -902,8 +918,6 @@ static inline int _ast_rwlock_rdlock(ast_rwlock_t *lock, const char *name,
return res; return res;
} }
#define ast_rwlock_wrlock(a) \
_ast_rwlock_wrlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int _ast_rwlock_wrlock(ast_rwlock_t *lock, const char *name, static inline int _ast_rwlock_wrlock(ast_rwlock_t *lock, const char *name,
const char *file, int line, const char *func) const char *file, int line, const char *func)
@ -935,8 +949,6 @@ static inline int _ast_rwlock_wrlock(ast_rwlock_t *lock, const char *name,
return res; return res;
} }
#define ast_rwlock_tryrdlock(a) \
_ast_rwlock_tryrdlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *lock, const char *name, static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *lock, const char *name,
const char *file, int line, const char *func) const char *file, int line, const char *func)
@ -968,8 +980,6 @@ static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *lock, const char *name,
return res; return res;
} }
#define ast_rwlock_trywrlock(a) \
_ast_rwlock_trywrlock(a, # a, __FILE__, __LINE__, __PRETTY_FUNCTION__)
static inline int _ast_rwlock_trywrlock(ast_rwlock_t *lock, const char *name, static inline int _ast_rwlock_trywrlock(ast_rwlock_t *lock, const char *name,
const char *file, int line, const char *func) const char *file, int line, const char *func)
@ -1059,19 +1069,19 @@ static void __attribute__ ((constructor)) init_##rwlock(void) \
{ \ { \
ast_rwlock_init(&rwlock); \ ast_rwlock_init(&rwlock); \
} \ } \
\
static void __attribute__ ((destructor)) fini_##rwlock(void) \ static void __attribute__ ((destructor)) fini_##rwlock(void) \
{ \ { \
ast_rwlock_destroy(&rwlock); \ ast_rwlock_destroy(&rwlock); \
} }
#else #else
#define __AST_RWLOCK_DEFINE(scope, rwlock) \ #define __AST_RWLOCK_DEFINE(scope, rwlock) scope ast_rwlock_t rwlock = AST_RWLOCK_INIT_VALUE
scope ast_rwlock_t rwlock = AST_RWLOCK_INIT_VALUE
#endif #endif
#define AST_RWLOCK_DEFINE_STATIC(rwlock) __AST_RWLOCK_DEFINE(static, rwlock) #define AST_RWLOCK_DEFINE_STATIC(rwlock) __AST_RWLOCK_DEFINE(static, rwlock)
/* /*
* Initial support for atomic instructions. * Support for atomic instructions.
* For platforms that have it, use the native cpu instruction to * For platforms that have it, use the native cpu instruction to
* implement them. For other platforms, resort to a 'slow' version * implement them. For other platforms, resort to a 'slow' version
* (defined in utils.c) that protects the atomic instruction with * (defined in utils.c) that protects the atomic instruction with

@ -353,6 +353,10 @@ static force_inline int inaddrcmp(const struct sockaddr_in *sin1, const struct s
|| (sin1->sin_port != sin2->sin_port)); || (sin1->sin_port != sin2->sin_port));
} }
/*
* Thread management support (should be moved to lock.h or a different header)
*/
#define AST_STACKSIZE 240 * 1024 #define AST_STACKSIZE 240 * 1024
#if defined(LOW_MEMORY) #if defined(LOW_MEMORY)
@ -372,24 +376,25 @@ int ast_pthread_create_detached_stack(pthread_t *thread, pthread_attr_t *attr, v
void *data, size_t stacksize, const char *file, const char *caller, void *data, size_t stacksize, const char *file, const char *caller,
int line, const char *start_fn); int line, const char *start_fn);
#define ast_pthread_create(a, b, c, d) ast_pthread_create_stack(a, b, c, d, \ #define ast_pthread_create(a, b, c, d) \
0, \ ast_pthread_create_stack(a, b, c, d, \
__FILE__, __FUNCTION__, \ 0, __FILE__, __FUNCTION__, __LINE__, #c)
__LINE__, #c)
#define ast_pthread_create_detached(a, b, c, d) ast_pthread_create_detached_stack(a, b, c, d, \
0, \
__FILE__, __FUNCTION__, \
__LINE__, #c)
#define ast_pthread_create_background(a, b, c, d) ast_pthread_create_stack(a, b, c, d, \ #define ast_pthread_create_detached(a, b, c, d) \
ast_pthread_create_detached_stack(a, b, c, d, \
0, __FILE__, __FUNCTION__, __LINE__, #c)
#define ast_pthread_create_background(a, b, c, d) \
ast_pthread_create_stack(a, b, c, d, \
AST_BACKGROUND_STACKSIZE, \ AST_BACKGROUND_STACKSIZE, \
__FILE__, __FUNCTION__, \ __FILE__, __FUNCTION__, __LINE__, #c)
__LINE__, #c)
#define ast_pthread_create_detached_background(a, b, c, d) ast_pthread_create_detached_stack(a, b, c, d, \ #define ast_pthread_create_detached_background(a, b, c, d) \
ast_pthread_create_detached_stack(a, b, c, d, \
AST_BACKGROUND_STACKSIZE, \ AST_BACKGROUND_STACKSIZE, \
__FILE__, __FUNCTION__, \ __FILE__, __FUNCTION__, __LINE__, #c)
__LINE__, #c)
/* End of thread management support */
/*! /*!
\brief Process a string to find and replace characters \brief Process a string to find and replace characters

Loading…
Cancel
Save