⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 my_pthread.h

📁 Linux snort-2.4.4源代码
💻 H
📖 第 1 页 / 共 2 页
字号:
#elseextern void my_pthread_attr_setprio(pthread_attr_t *attr, int priority);#endif#endif#if !defined(HAVE_PTHREAD_ATTR_SETSCOPE) || defined(HAVE_DEC_3_2_THREADS)#define pthread_attr_setscope(A,B)#undef	HAVE_GETHOSTBYADDR_R			/* No definition */#endif#if defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) && !defined(SAFE_MUTEX)extern int my_pthread_cond_timedwait(pthread_cond_t *cond,				     pthread_mutex_t *mutex,				     struct timespec *abstime);#define pthread_cond_timedwait(A,B,C) my_pthread_cond_timedwait((A),(B),(C))#endif#if defined(OS2)#define my_pthread_getspecific(T,A) ((T) &(A))#define pthread_setspecific(A,B) win_pthread_setspecific(&(A),(B),sizeof(A))#elif !defined( HAVE_NONPOSIX_PTHREAD_GETSPECIFIC)#define my_pthread_getspecific(A,B) ((A) pthread_getspecific(B))#else#define my_pthread_getspecific(A,B) ((A) my_pthread_getspecific_imp(B))void *my_pthread_getspecific_imp(pthread_key_t key);#endif /* OS2 */#ifndef HAVE_LOCALTIME_Rstruct tm *localtime_r(const time_t *clock, struct tm *res);#endif#ifndef HAVE_GMTIME_Rstruct tm *gmtime_r(const time_t *clock, struct tm *res);#endif#ifdef HAVE_PTHREAD_CONDATTR_CREATE/* DCE threads on HPUX 10.20 */#define pthread_condattr_init pthread_condattr_create#define pthread_condattr_destroy pthread_condattr_delete#endif/* FSU THREADS */#if !defined(HAVE_PTHREAD_KEY_DELETE) && !defined(pthread_key_delete)#define pthread_key_delete(A) pthread_dummy(0)#endif#ifdef HAVE_CTHREADS_WRAPPER			/* For MacOSX */#define pthread_cond_destroy(A) pthread_dummy(0)#define pthread_mutex_destroy(A) pthread_dummy(0)#define pthread_attr_delete(A) pthread_dummy(0)#define pthread_condattr_delete(A) pthread_dummy(0)#define pthread_attr_setstacksize(A,B) pthread_dummy(0)#define pthread_equal(A,B) ((A) == (B))#define pthread_cond_timedwait(a,b,c) pthread_cond_wait((a),(b))#define pthread_attr_init(A) pthread_attr_create(A)#define pthread_attr_destroy(A) pthread_attr_delete(A)#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))#define pthread_kill(A,B) pthread_dummy(0)#undef	pthread_detach_this_thread#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }#endif#ifdef HAVE_DARWIN_THREADS#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))#define pthread_kill(A,B) pthread_dummy(0)#define pthread_condattr_init(A) pthread_dummy(0)#define pthread_condattr_destroy(A) pthread_dummy(0)#define pthread_signal(A,B) pthread_dummy(0)#undef	pthread_detach_this_thread#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(tmp); }#undef sigset#define sigset(A,B) pthread_signal((A),(void (*)(int)) (B))#endif#if ((defined(HAVE_PTHREAD_ATTR_CREATE) && !defined(HAVE_SIGWAIT)) || defined(HAVE_DEC_3_2_THREADS)) && !defined(HAVE_CTHREADS_WRAPPER)/* This is set on AIX_3_2 and Siemens unix (and DEC OSF/1 3.2 too) */#define pthread_key_create(A,B) \		pthread_keycreate(A,(B) ?\				  (pthread_destructor_t) (B) :\				  (pthread_destructor_t) pthread_dummy)#define pthread_attr_init(A) pthread_attr_create(A)#define pthread_attr_destroy(A) pthread_attr_delete(A)#define pthread_attr_setdetachstate(A,B) pthread_dummy(0)#define pthread_create(A,B,C,D) pthread_create((A),*(B),(C),(D))#ifndef pthread_sigmask#define pthread_sigmask(A,B,C) sigprocmask((A),(B),(C))#endif#define pthread_kill(A,B) pthread_dummy(0)#undef	pthread_detach_this_thread#define pthread_detach_this_thread() { pthread_t tmp=pthread_self() ; pthread_detach(&tmp); }#elif !defined(__NETWARE__) /* HAVE_PTHREAD_ATTR_CREATE && !HAVE_SIGWAIT */#define HAVE_PTHREAD_KILL#endif#endif /* defined(__WIN__) */#if defined(HPUX10) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)#undef pthread_cond_timedwait#define pthread_cond_timedwait(a,b,c) my_pthread_cond_timedwait((a),(b),(c))int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,			      struct timespec *abstime);#endif#if defined(HPUX10)#define pthread_attr_getstacksize(A,B) my_pthread_attr_getstacksize(A,B)void my_pthread_attr_getstacksize(pthread_attr_t *attrib, size_t *size);#endif#if defined(HAVE_POSIX1003_4a_MUTEX) && !defined(DONT_REMAP_PTHREAD_FUNCTIONS)#undef pthread_mutex_trylock#define pthread_mutex_trylock(a) my_pthread_mutex_trylock((a))int my_pthread_mutex_trylock(pthread_mutex_t *mutex);#endif	/* safe_mutex adds checking to mutex for easier debugging */#if defined(__NETWARE__) && !defined(SAFE_MUTEX_DETECT_DESTROY)#define SAFE_MUTEX_DETECT_DESTROY#endiftypedef struct st_safe_mutex_t{  pthread_mutex_t global,mutex;  const char *file;  uint line,count;  pthread_t thread;#ifdef SAFE_MUTEX_DETECT_DESTROY  struct st_safe_mutex_info_t *info;	/* to track destroying of mutexes */#endif} safe_mutex_t;#ifdef SAFE_MUTEX_DETECT_DESTROY/*  Used to track the destroying of mutexes. This needs to be a seperate  structure because the safe_mutex_t structure could be freed before  the mutexes are destroyed.*/typedef struct st_safe_mutex_info_t{  struct st_safe_mutex_info_t *next;  struct st_safe_mutex_info_t *prev;  const char *init_file;  uint32 init_line;} safe_mutex_info_t;#endif /* SAFE_MUTEX_DETECT_DESTROY */int safe_mutex_init(safe_mutex_t *mp, const pthread_mutexattr_t *attr,                    const char *file, uint line);int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line);int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line);int safe_mutex_destroy(safe_mutex_t *mp,const char *file, uint line);int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp,const char *file,		   uint line);int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,			struct timespec *abstime, const char *file, uint line);void safe_mutex_global_init(void);void safe_mutex_end(FILE *file);	/* Wrappers if safe mutex is actually used */#ifdef SAFE_MUTEX#undef pthread_mutex_init#undef pthread_mutex_lock#undef pthread_mutex_unlock#undef pthread_mutex_destroy#undef pthread_mutex_wait#undef pthread_mutex_timedwait#undef pthread_mutex_t#undef pthread_cond_wait#undef pthread_cond_timedwait#undef pthread_mutex_trylock#define pthread_mutex_init(A,B) safe_mutex_init((A),(B),__FILE__,__LINE__)#define pthread_mutex_lock(A) safe_mutex_lock((A),__FILE__,__LINE__)#define pthread_mutex_unlock(A) safe_mutex_unlock((A),__FILE__,__LINE__)#define pthread_mutex_destroy(A) safe_mutex_destroy((A),__FILE__,__LINE__)#define pthread_cond_wait(A,B) safe_cond_wait((A),(B),__FILE__,__LINE__)#define pthread_cond_timedwait(A,B,C) safe_cond_timedwait((A),(B),(C),__FILE__,__LINE__)#define pthread_mutex_trylock(A) pthread_mutex_lock(A)#define pthread_mutex_t safe_mutex_t#define safe_mutex_assert_owner(mp) DBUG_ASSERT((mp)->count > 0 && pthread_equal(pthread_self(),(mp)->thread))#else#define safe_mutex_assert_owner(mp)#endif /* SAFE_MUTEX */	/* READ-WRITE thread locking */#ifdef HAVE_BROKEN_RWLOCK			/* For OpenUnix */#undef HAVE_PTHREAD_RWLOCK_RDLOCK#undef HAVE_RWLOCK_INIT#undef HAVE_RWLOCK_T#endif#if defined(USE_MUTEX_INSTEAD_OF_RW_LOCKS)/* use these defs for simple mutex locking */#define rw_lock_t pthread_mutex_t#define my_rwlock_init(A,B) pthread_mutex_init((A),(B))#define rw_rdlock(A) pthread_mutex_lock((A))#define rw_wrlock(A) pthread_mutex_lock((A))#define rw_tryrdlock(A) pthread_mutex_trylock((A))#define rw_trywrlock(A) pthread_mutex_trylock((A))#define rw_unlock(A) pthread_mutex_unlock((A))#define rwlock_destroy(A) pthread_mutex_destroy((A))#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK)#define rw_lock_t pthread_rwlock_t#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B))#define rw_rdlock(A) pthread_rwlock_rdlock(A)#define rw_wrlock(A) pthread_rwlock_wrlock(A)#define rw_tryrdlock(A) pthread_rwlock_tryrdlock((A))#define rw_trywrlock(A) pthread_rwlock_trywrlock((A))#define rw_unlock(A) pthread_rwlock_unlock(A)#define rwlock_destroy(A) pthread_rwlock_destroy(A)#elif defined(HAVE_RWLOCK_INIT)#ifdef HAVE_RWLOCK_T				/* For example Solaris 2.6-> */#define rw_lock_t rwlock_t#endif#define my_rwlock_init(A,B) rwlock_init((A),USYNC_THREAD,0)#else/* Use our own version of read/write locks */typedef struct _my_rw_lock_t {	pthread_mutex_t lock;		/* lock for structure		*/	pthread_cond_t	readers;	/* waiting readers		*/	pthread_cond_t	writers;	/* waiting writers		*/	int		state;		/* -1:writer,0:free,>0:readers	*/	int		waiters;	/* number of waiting writers	*/} my_rw_lock_t;#define rw_lock_t my_rw_lock_t#define rw_rdlock(A) my_rw_rdlock((A))#define rw_wrlock(A) my_rw_wrlock((A))#define rw_tryrdlock(A) my_rw_tryrdlock((A))#define rw_trywrlock(A) my_rw_trywrlock((A))#define rw_unlock(A) my_rw_unlock((A))#define rwlock_destroy(A) my_rwlock_destroy((A))extern int my_rwlock_init(my_rw_lock_t *, void *);extern int my_rwlock_destroy(my_rw_lock_t *);extern int my_rw_rdlock(my_rw_lock_t *);extern int my_rw_wrlock(my_rw_lock_t *);extern int my_rw_unlock(my_rw_lock_t *);extern int my_rw_tryrdlock(my_rw_lock_t *);extern int my_rw_trywrlock(my_rw_lock_t *);#endif /* USE_MUTEX_INSTEAD_OF_RW_LOCKS */#define GETHOSTBYADDR_BUFF_SIZE 2048#ifndef HAVE_THR_SETCONCURRENCY#define thr_setconcurrency(A) pthread_dummy(0)#endif#if !defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) && ! defined(pthread_attr_setstacksize)#define pthread_attr_setstacksize(A,B) pthread_dummy(0)#endif/* Define mutex types, see my_thr_init.c */#define MY_MUTEX_INIT_SLOW   NULL#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NPextern pthread_mutexattr_t my_fast_mutexattr;#define MY_MUTEX_INIT_FAST &my_fast_mutexattr#else#define MY_MUTEX_INIT_FAST   NULL#endif#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NPextern pthread_mutexattr_t my_errorcheck_mutexattr;#define MY_MUTEX_INIT_ERRCHK &my_errorcheck_mutexattr#else#define MY_MUTEX_INIT_ERRCHK   NULL#endifextern my_bool my_thread_global_init(void);extern void my_thread_global_end(void);extern my_bool my_thread_init(void);extern void my_thread_end(void);extern const char *my_thread_name(void);extern long my_thread_id(void);extern int pthread_no_free(void *);extern int pthread_dummy(int);/* All thread specific variables are in the following struct */#define THREAD_NAME_SIZE 10#ifndef DEFAULT_THREAD_STACK#if defined(__ia64__)/*  MySQL can survive with 32K, but some glibc libraries require > 128K stack  To resolve hostnames*/#define DEFAULT_THREAD_STACK	(256*1024L)#else#define DEFAULT_THREAD_STACK	(192*1024)#endif#endifstruct st_my_thread_var{  int thr_errno;  pthread_cond_t suspend;  pthread_mutex_t mutex;  pthread_mutex_t * volatile current_mutex;  pthread_cond_t * volatile current_cond;  pthread_t pthread_self;  long id;  int cmp_length;  int volatile abort;  my_bool init;  struct st_my_thread_var *next,**prev;  void *opt_info;#ifndef DBUG_OFF  gptr dbug;  char name[THREAD_NAME_SIZE+1];#endif};extern struct st_my_thread_var *_my_thread_var(void) __attribute__ ((const));#define my_thread_var (_my_thread_var())#define my_errno my_thread_var->thr_errno/*  Keep track of shutdown,signal, and main threads so that my_end() will not  report errors with them*/extern pthread_t shutdown_th, main_th, signal_th;	/* statistics_xxx functions are for not essential statistic */#ifndef thread_safe_increment#ifdef HAVE_ATOMIC_ADD#define thread_safe_increment(V,L) atomic_add(1,(atomic_t*) &V);#define thread_safe_add(V,C,L)     atomic_add((C),(atomic_t*) &V);#define thread_safe_sub(V,C,L)     atomic_sub((C),(atomic_t*) &V);#else#define thread_safe_increment(V,L) \	pthread_mutex_lock((L)); (V)++; pthread_mutex_unlock((L));#define thread_safe_add(V,C,L) \	pthread_mutex_lock((L)); (V)+=(C); pthread_mutex_unlock((L));#define thread_safe_sub(V,C,L) \	pthread_mutex_lock((L)); (V)-=(C); pthread_mutex_unlock((L));#endif /* HAVE_ATOMIC_ADD */#ifdef SAFE_STATISTICS#define statistic_increment(V,L)   thread_safe_increment((V),(L))#define statistic_add(V,C,L)       thread_safe_add((V),(C),(L))#else#define statistic_increment(V,L) (V)++#define statistic_add(V,C,L)     (V)+=(C)#endif /* SAFE_STATISTICS */#endif /* thread_safe_increment */#ifdef  __cplusplus}#endif#endif /* _my_ptread_h */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -