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.13 date 2003.07.14.02.17.52; author brendan; state Exp; branches; next 1.12; 1.12 date 2003.07.07.20.38.34; author brendan; state Exp; branches; next 1.11; 1.11 date 2003.03.15.02.10.18; author msmith; state Exp; branches; next 1.10; 1.10 date 2003.03.05.19.52.10; author brendan; state Exp; branches; next 1.9; 1.9 date 2003.03.04.15.31.34; author msmith; state Exp; branches; next 1.8; 1.8 date 2002.12.29.09.55.50; author msmith; state Exp; branches; next 1.7; 1.7 date 2002.09.24.07.09.08; author msmith; state Exp; branches; next 1.6; 1.6 date 2002.08.10.03.22.44; author msmith; state Exp; branches; next 1.5; 1.5 date 2002.08.05.14.48.04; author msmith; state Exp; branches; next 1.4; 1.4 date 2001.10.21.02.04.27; author jack; state Exp; branches; next 1.3; 1.3 date 2001.10.20.22.40.28; author jack; state Exp; branches; next 1.2; 1.2 date 2001.10.20.22.27.52; author jack; state Exp; branches; next 1.1; 1.1 date 2001.09.10.02.26.33; author jack; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.09.10.02.26.33; author jack; state Exp; branches; next ; desc @@ 1.13 log @Assign LGP to thread module @ text @/* thread.h * - Thread Abstraction Function Headers * * Copyright (c) 1999, 2000 the icecast team * * 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 /* 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.12 log @The last of the convenience lib cleanups. A little forethought in designing a keyboard macro made this one a lot easier. @ text @d4 1 a4 1 * Copyright (c) 1999, 2000 the icecast team d6 4 a9 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.11 log @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 29 a185 3 @ 1.10 log @Remove some namespace pollution @ text @d30 10 a39 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 2 a42 2 /* is the thread running detached? */ int detached; d44 2 a45 2 /* the system specific thread */ pthread_t sys_thread; d50 10 a59 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 2 a64 2 /* the system specific mutex */ pthread_mutex_t sys_mutex; d69 2 a70 2 long cond_id; char *name; d73 2 a74 2 pthread_mutex_t cond_mutex; pthread_cond_t sys_cond; d79 2 a80 2 long rwlock_id; char *name; d82 6 a87 6 /* information on which thread and where in the code ** this rwlock was write locked */ long thread_id; char *file; int line; d90 1 a90 1 pthread_rwlock_t sys_rwlock; @ 1.9 log @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 be quite significant. No functional differences. @ text @d29 1 a29 1 typedef struct thread_tag { d41 2 a42 2 /* is the thread running detached? */ int detached; d48 1 a48 1 typedef struct mutex_tag { d67 1 a67 1 typedef struct cond_tag { d77 1 a77 1 typedef struct rwlock_tag { @ 1.8 log @Rename thread_t to avoid problems on OS X @ text @d49 1 d61 2 d68 1 d71 1 d78 1 d88 1 @ 1.7 log @Bugfix: thread_join is often called after a thread has already exited, which it does using thread_exit(). thread_exit() was freeing the thread structure, so thread_join was using freed memory. Rearrange things so that if the thread is detached, the freeing happens in thread_join instead. @ text @d27 2 d46 1 a46 1 } thread_t; d113 2 a114 1 thread_t *thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file); d141 1 a141 1 thread_t *thread_self(void); d147 1 a147 1 void thread_join(thread_t *thread); @ 1.6 log @Various cleanups @ text @d39 3 @ 1.5 log @Cleaned up version of Ciaran Anscomb's relaying patch. @ text @d108 1 a108 1 long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file); d141 1 a141 1 void thread_join(long thread); @ 1.4 log @Revert the stacksize work. It's stupid. The original patch from Ben Laurie some years ago was needed because FreeBSD's default stack size was < 8k and this wasn't acceptable. Both Linux and Solaris had reasonable defaults for stacksize, or grew the stack as needed to a reasonable size. Testing today and consulting documentation shows that the default stack sizes on FreeBSD, Linux, and Solaris are all acceptable. Linux can grow to 2MB, 32bit Solaris defaults to 1MB, 64bit Solaris defaults to 2MB, and FreeBSD defaults to 64k. In my opinion FreeBSD needs to get with the program and provide a reasonable default. 64k is enough for us, but might not be for others. @ text @d89 1 d117 1 @ 1.3 log @Fix header definition. @ text @a26 2 #define THREAD_DEFAULT_STACKSIZE 8192 d81 1 a81 1 #define thread_create(n,w,x,y,z) thread_create_c(n,w,x,y,z,__LINE__,__FILE__) d107 1 a107 1 long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int stacksize, int detached, int line, char *file); @ 1.2 log @Stack size per thread needs to be configurable. Setting it on a global bases is not enough. ices and icecast need this to be different, and if one is interested in tuning memory usage, one will want to alter this per thread. @ text @d109 1 a109 1 long thread_create_c(char *name, void *(*start_routine)(void *), void *arg, int detached, int line, char *file); @ 1.1 log @Initial revision @ text @d27 2 d83 1 a83 1 #define thread_create(n,x,y,z) thread_create_c(n,x,y,z,__LINE__,__FILE__) @ 1.1.1.1 log @move to cvs @ text @@