📄 thread.h,v
字号:
head 1.13;access;symbols libshout-2_0:1.12 libshout-2_0b3:1.12 libshout-2_0b2:1.11 libshout_2_0b1:1.11 libogg2-zerocopy:1.7.0.2 branch-beta2-rewrite:1.4.0.2 start:1.1.1.1 xiph:1.1.1;locks; strict;comment @ * @;1.13date 2003.07.14.02.17.52; author brendan; state Exp;branches;next 1.12;1.12date 2003.07.07.20.38.34; author brendan; state Exp;branches;next 1.11;1.11date 2003.03.15.02.10.18; author msmith; state Exp;branches;next 1.10;1.10date 2003.03.05.19.52.10; author brendan; state Exp;branches;next 1.9;1.9date 2003.03.04.15.31.34; author msmith; state Exp;branches;next 1.8;1.8date 2002.12.29.09.55.50; author msmith; state Exp;branches;next 1.7;1.7date 2002.09.24.07.09.08; author msmith; state Exp;branches;next 1.6;1.6date 2002.08.10.03.22.44; author msmith; state Exp;branches;next 1.5;1.5date 2002.08.05.14.48.04; author msmith; state Exp;branches;next 1.4;1.4date 2001.10.21.02.04.27; author jack; state Exp;branches;next 1.3;1.3date 2001.10.20.22.40.28; author jack; state Exp;branches;next 1.2;1.2date 2001.10.20.22.27.52; author jack; state Exp;branches;next 1.1;1.1date 2001.09.10.02.26.33; author jack; state Exp;branches 1.1.1.1;next ;1.1.1.1date 2001.09.10.02.26.33; author jack; state Exp;branches;next ;desc@@1.13log@Assign LGP to thread module@text@/* thread.h * - Thread Abstraction Function Headers * * Copyright (c) 1999, 2000 the icecast team <team@@icecast.org> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#ifndef __THREAD_H__#define __THREAD_H__#include <pthread.h>/* renamed from thread_t due to conflict on OS X */typedef struct { /* the local id for the thread, and it's name */ long thread_id; char *name; /* the time the thread was created */ time_t create_time; /* the file and line which created this thread */ char *file; int line; /* is the thread running detached? */ int detached; /* the system specific thread */ pthread_t sys_thread;} thread_type;typedef struct {#ifdef DEBUG_MUTEXES /* the local id and name of the mutex */ long mutex_id; char *name; /* the thread which is currently locking this mutex */ long thread_id; /* the file and line where the mutex was locked */ char *file; int line; #endif /* the system specific mutex */ pthread_mutex_t sys_mutex;} mutex_t;typedef struct {#ifdef THREAD_DEBUG long cond_id; char *name;#endif pthread_mutex_t cond_mutex; pthread_cond_t sys_cond;} cond_t;typedef struct {#ifdef THREAD_DEBUG long rwlock_id; char *name; /* information on which thread and where in the code ** this rwlock was write locked */ long thread_id; char *file; int line;#endif pthread_rwlock_t sys_rwlock;} rwlock_t;#define thread_create(n,x,y,z) thread_create_c(n,x,y,z,__LINE__,__FILE__)#define thread_mutex_create(x) thread_mutex_create_c(x,__LINE__,__FILE__)#define thread_mutex_lock(x) thread_mutex_lock_c(x,__LINE__,__FILE__)#define thread_mutex_unlock(x) thread_mutex_unlock_c(x,__LINE__,__FILE__)#define thread_cond_create(x) thread_cond_create_c(x,__LINE__,__FILE__)#define thread_cond_signal(x) thread_cond_signal_c(x,__LINE__,__FILE__)#define thread_cond_broadcast(x) thread_cond_broadcast_c(x,__LINE__,__FILE__)#define thread_cond_wait(x) thread_cond_wait_c(x,__LINE__,__FILE__)#define thread_cond_timedwait(x,t) thread_cond_wait_c(x,t,__LINE__,__FILE__)#define thread_rwlock_create(x) thread_rwlock_create_c(x,__LINE__,__FILE__)#define thread_rwlock_rlock(x) thread_rwlock_rlock_c(x,__LINE__,__FILE__)#define thread_rwlock_wlock(x) thread_rwlock_wlock_c(x,__LINE__,__FILE__)#define thread_rwlock_unlock(x) thread_rwlock_unlock_c(x,__LINE__,__FILE__)#define thread_exit(x) thread_exit_c(x,__LINE__,__FILE__)#define MUTEX_STATE_NOTLOCKED -1#define MUTEX_STATE_NEVERLOCKED -2#define MUTEX_STATE_UNINIT -3#define THREAD_DETACHED 1#define THREAD_ATTACHED 0#ifdef _mangle# define thread_initialize _mangle(thread_initialize)# define thread_initialize_with_log_id _mangle(thread_initialize_with_log_id)# define thread_shutdown _mangle(thread_shutdown)# define thread_create_c _mangle(thread_create_c)# define thread_mutex_create_c _mangle(thread_mutex_create)# define thread_mutex_lock_c _mangle(thread_mutex_lock_c)# define thread_mutex_unlock_c _mangle(thread_mutex_unlock_c)# define thread_mutex_destroy _mangle(thread_mutex_destroy)# define thread_cond_create_c _mangle(thread_cond_create_c)# define thread_cond_signal_c _mangle(thread_cond_signal_c)# define thread_cond_broadcast_c _mangle(thread_cond_broadcast_c)# define thread_cond_wait_c _mangle(thread_cond_wait_c)# define thread_cond_timedwait_c _mangle(thread_cond_timedwait_c)# define thread_cond_destroy _mangle(thread_cond_destroy)# define thread_rwlock_create_c _mangle(thread_rwlock_create_c)# define thread_rwlock_rlock_c _mangle(thread_rwlock_rlock_c)# define thread_rwlock_wlock_c _mangle(thread_rwlock_wlock_c)# define thread_rwlock_unlock_c _mangle(thread_rwlock_unlock_c)# define thread_rwlock_destroy _mangle(thread_rwlock_destroy)# define thread_exit_c _mangle(thread_exit_c)# define thread_sleep _mangle(thread_sleep)# define thread_library_lock _mangle(thread_library_lock)# define thread_library_unlock _mangle(thread_library_unlock)# define thread_self _mangle(thread_self)# define thread_rename _mangle(thread_rename)# define thread_join _mangle(thread_join)#endif/* init/shutdown of the library */void thread_initialize(void);void thread_initialize_with_log_id(int log_id);void thread_shutdown(void);/* creation, destruction, locking, unlocking, signalling and waiting */thread_type *thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file);void thread_mutex_create_c(mutex_t *mutex, int line, char *file);void thread_mutex_lock_c(mutex_t *mutex, int line, char *file);void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file);void thread_mutex_destroy(mutex_t *mutex);void thread_cond_create_c(cond_t *cond, int line, char *file);void thread_cond_signal_c(cond_t *cond, int line, char *file);void thread_cond_broadcast_c(cond_t *cond, int line, char *file);void thread_cond_wait_c(cond_t *cond, int line, char *file);void thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file);void thread_cond_destroy(cond_t *cond);void thread_rwlock_create_c(rwlock_t *rwlock, int line, char *file);void thread_rwlock_rlock_c(rwlock_t *rwlock, int line, char *file);void thread_rwlock_wlock_c(rwlock_t *rwlock, int line, char *file);void thread_rwlock_unlock_c(rwlock_t *rwlock, int line, char *file);void thread_rwlock_destroy(rwlock_t *rwlock);void thread_exit_c(int val, int line, char *file);/* sleeping */void thread_sleep(unsigned long len);/* for using library functions which aren't threadsafe */void thread_library_lock(void);void thread_library_unlock(void);#define PROTECT_CODE(code) { thread_library_lock(); code; thread_library_unlock(); }/* thread information functions */thread_type *thread_self(void);/* renames current thread */void thread_rename(const char *name);/* waits until thread_exit is called for another thread */void thread_join(thread_type *thread);#endif /* __THREAD_H__ */@1.12log@The last of the convenience lib cleanups. A little forethought in designinga keyboard macro made this one a lot easier.@text@d4 1a4 1 * Copyright (c) 1999, 2000 the icecast teamd6 4a9 13 * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.d11 8@1.11log@Brendan was getting pissed off about inconsistent indentation styles.Convert all tabs to 4 spaces. All code must now use 4 space indents.@text@d114 29a185 3@1.10log@Remove some namespace pollution@text@d30 10a39 10 /* the local id for the thread, and it's name */ long thread_id; char *name; /* the time the thread was created */ time_t create_time; /* the file and line which created this thread */ char *file; int line;d41 2a42 2 /* is the thread running detached? */ int detached;d44 2a45 2 /* the system specific thread */ pthread_t sys_thread;d50 10a59 10 /* the local id and name of the mutex */ long mutex_id; char *name; /* the thread which is currently locking this mutex */ long thread_id; /* the file and line where the mutex was locked */ char *file; int line; d63 2a64 2 /* the system specific mutex */ pthread_mutex_t sys_mutex;d69 2a70 2 long cond_id; char *name;d73 2a74 2 pthread_mutex_t cond_mutex; pthread_cond_t sys_cond;d79 2a80 2 long rwlock_id; char *name;d82 6a87 6 /* information on which thread and where in the code ** this rwlock was write locked */ long thread_id; char *file; int line;d90 1a90 1 pthread_rwlock_t sys_rwlock;@1.9log@Make various thread structures omit the bits only used in debug mode.Some of these are pretty heavily used, so saving 10-20 bytes each can bequite significant.No functional differences.@text@d29 1a29 1typedef struct thread_tag {d41 2a42 2 /* is the thread running detached? */ int detached;d48 1a48 1typedef struct mutex_tag {d67 1a67 1typedef struct cond_tag {d77 1a77 1typedef struct rwlock_tag {@1.8log@Rename thread_t to avoid problems on OS X@text@d49 1d61 2d68 1d71 1d78 1d88 1@1.7log@Bugfix: thread_join is often called after a thread has already exited, which itdoes using thread_exit(). thread_exit() was freeing the thread structure, sothread_join was using freed memory. Rearrange things so that if the threadis detached, the freeing happens in thread_join instead.@text@d27 2d46 1a46 1} thread_t;d113 2a114 1thread_t *thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file);d141 1a141 1thread_t *thread_self(void);d147 1a147 1void thread_join(thread_t *thread);@1.6log@Various cleanups@text@d39 3@1.5log@Cleaned up version of Ciaran Anscomb's relaying patch.@text@d108 1a108 1long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file);d141 1a141 1void thread_join(long thread);@1.4log@Revert the stacksize work. It's stupid.The original patch from Ben Laurie some years ago was needed becauseFreeBSD's default stack size was < 8k and this wasn't acceptable.Both Linux and Solaris had reasonable defaults for stacksize, or grew thestack as needed to a reasonable size.Testing today and consulting documentation shows that the default stacksizes on FreeBSD, Linux, and Solaris are all acceptable. Linux can growto 2MB, 32bit Solaris defaults to 1MB, 64bit Solaris defaults to 2MB, andFreeBSD defaults to 64k.In my opinion FreeBSD needs to get with the program and provide areasonable default. 64k is enough for us, but might not be for others.@text@d89 1d117 1@1.3log@Fix header definition.@text@a26 2#define THREAD_DEFAULT_STACKSIZE 8192d81 1a81 1#define thread_create(n,w,x,y,z) thread_create_c(n,w,x,y,z,__LINE__,__FILE__)d107 1a107 1long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int stacksize, int detached, int line, char *file);@1.2log@Stack size per thread needs to be configurable. Setting it on a globalbases is not enough. ices and icecast need this to be different, andif one is interested in tuning memory usage, one will want to alter thisper thread.@text@d109 1a109 1long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file);@1.1log@Initial revision@text@d27 2d83 1a83 1#define thread_create(n,x,y,z) thread_create_c(n,x,y,z,__LINE__,__FILE__)@1.1.1.1log@move to cvs@text@@
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -