24ddc71998-03-28Henrik Grubbström (Grubba) /*
95c8152001-11-01Martin Stjernholm  * $Id: threads.h,v 1.117 2001/11/01 18:40:12 mast Exp $
24ddc71998-03-28Henrik Grubbström (Grubba)  */
07513e1996-10-04Fredrik Hübinette (Hubbe) #ifndef THREADS_H #define THREADS_H #include "machine.h"
a7fef41997-09-03Per Hedbor #include "object.h"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
5923b12000-07-06Fredrik Hübinette (Hubbe) #include "interpret.h"
45637c2001-04-07Fredrik Hübinette (Hubbe) #include "pike_threadlib.h"
d978c02000-02-04Henrik Grubbström (Grubba) 
f3c7152001-04-14Fredrik Hübinette (Hubbe) #ifdef PIKE_THREADS
c91f892000-04-19Martin Stjernholm 
07513e1996-10-04Fredrik Hübinette (Hubbe) struct svalue;
4218011999-01-31Fredrik Hübinette (Hubbe) struct pike_frame;
07513e1996-10-04Fredrik Hübinette (Hubbe) 
0542ef1999-11-17Fredrik Hübinette (Hubbe) extern PIKE_MUTEX_T interleave_lock;
a91ca01998-07-10Henrik Grubbström (Grubba)  struct interleave_mutex { struct interleave_mutex *next; struct interleave_mutex *prev;
0542ef1999-11-17Fredrik Hübinette (Hubbe)  PIKE_MUTEX_T lock;
a91ca01998-07-10Henrik Grubbström (Grubba) }; #define IMUTEX_T struct interleave_mutex #define DEFINE_IMUTEX(name) IMUTEX_T name /* If threads are disabled, we already hold the lock. */ #define LOCK_IMUTEX(im) do { \ if (!threads_disabled) { \
95c8152001-11-01Martin Stjernholm  THREADS_FPRINTF(0, (stderr, "Locking IMutex 0x%p...\n", (im))); \
a91ca01998-07-10Henrik Grubbström (Grubba)  THREADS_ALLOW(); \ mt_lock(&((im)->lock)); \ THREADS_DISALLOW(); \ } \ } while(0) /* If threads are disabled, the lock will be released later. */ #define UNLOCK_IMUTEX(im) do { \ if (!threads_disabled) { \
95c8152001-11-01Martin Stjernholm  THREADS_FPRINTF(0, (stderr, "Unlocking IMutex 0x%p...\n", (im))); \
a91ca01998-07-10Henrik Grubbström (Grubba)  mt_unlock(&((im)->lock)); \ } \ } while(0)
5740881998-01-01Fredrik Hübinette (Hubbe) #define THREAD_NOT_STARTED -1 #define THREAD_RUNNING 0 #define THREAD_EXITED 1
5923b12000-07-06Fredrik Hübinette (Hubbe) struct thread_state { struct Pike_interpreter state; char swapped; char status; COND_T status_change; THREAD_T id; struct mapping *thread_local; struct thread_state *hashlink, **backlink;
b377d72000-07-07Henrik Grubbström (Grubba) #ifdef PROFILING
0877a82001-08-29Martin Stjernholm #if SIZEOF_LONG_LONG - 0 != 0
b377d72000-07-07Henrik Grubbström (Grubba)  long long time_base;
0877a82001-08-29Martin Stjernholm #else long time_base; #endif
b377d72000-07-07Henrik Grubbström (Grubba) #endif /* PROFILING */
5923b12000-07-06Fredrik Hübinette (Hubbe) };
e132001998-11-19Fredrik Hübinette (Hubbe) 
db40ab1999-04-15Fredrik Hübinette (Hubbe) 
07513e1996-10-04Fredrik Hübinette (Hubbe) /* Prototypes begin here */
a2ad152000-02-16Fredrik Hübinette (Hubbe) int low_nt_create_thread(unsigned Pike_stack_size,
cd67ac1999-05-11Fredrik Hübinette (Hubbe)  unsigned (TH_STDCALL *func)(void *), void *arg, unsigned *id);
6d1a5e1996-10-07Fredrik Hübinette (Hubbe) struct thread_starter;
cd67ac1999-05-11Fredrik Hübinette (Hubbe) struct thread_local; void low_init_threads_disable(void); void init_threads_disable(struct object *o); void exit_threads_disable(struct object *o); void init_interleave_mutex(IMUTEX_T *im); void exit_interleave_mutex(IMUTEX_T *im); void thread_table_init(void); unsigned INT32 thread_table_hash(THREAD_T *tid);
d6896c2000-12-16Marcus Comstedt PMOD_EXPORT void thread_table_insert(struct object *o); PMOD_EXPORT void thread_table_delete(struct object *o); PMOD_EXPORT struct thread_state *thread_state_for_id(THREAD_T tid); PMOD_EXPORT struct object *thread_for_id(THREAD_T tid); PMOD_EXPORT void f_all_threads(INT32 args); PMOD_EXPORT int count_pike_threads(void);
26cd941999-05-07Fredrik Hübinette (Hubbe) TH_RETURN_TYPE new_thread_func(void * data);
07513e1996-10-04Fredrik Hübinette (Hubbe) void f_thread_create(INT32 args);
dc7cc91998-01-14Fredrik Hübinette (Hubbe) void f_thread_set_concurrency(INT32 args);
d6896c2000-12-16Marcus Comstedt PMOD_EXPORT void f_this_thread(INT32 args);
6d1a5e1996-10-07Fredrik Hübinette (Hubbe) struct mutex_storage; struct key_storage;
07513e1996-10-04Fredrik Hübinette (Hubbe) void f_mutex_lock(INT32 args); void f_mutex_trylock(INT32 args); void init_mutex_obj(struct object *o); void exit_mutex_obj(struct object *o); void init_mutex_key_obj(struct object *o); void exit_mutex_key_obj(struct object *o); void f_cond_wait(INT32 args); void f_cond_signal(INT32 args); void f_cond_broadcast(INT32 args); void init_cond_obj(struct object *o); void exit_cond_obj(struct object *o);
dc7cc91998-01-14Fredrik Hübinette (Hubbe) void f_thread_backtrace(INT32 args); void f_thread_id_status(INT32 args); void init_thread_obj(struct object *o); void exit_thread_obj(struct object *o);
d6896c2000-12-16Marcus Comstedt PMOD_EXPORT void f_thread_local(INT32 args);
cd67ac1999-05-11Fredrik Hübinette (Hubbe) void f_thread_local_get(INT32 args); void f_thread_local_set(INT32 args);
a91ca01998-07-10Henrik Grubbström (Grubba) void low_th_init(void);
cd67ac1999-05-11Fredrik Hübinette (Hubbe) void th_init(void);
be478c1997-08-30Henrik Grubbström (Grubba) void th_cleanup(void);
cd67ac1999-05-11Fredrik Hübinette (Hubbe) int th_num_idle_farmers(void);
99a5a62000-08-06David Hedbor int th_num_farmers(void);
d6896c2000-12-16Marcus Comstedt PMOD_EXPORT void th_farm(void (*fun)(void *), void *here);
07513e1996-10-04Fredrik Hübinette (Hubbe) /* Prototypes end here */
d3015d2000-04-18Jonas Wallden #endif
ec2bab2000-06-24Fredrik Hübinette (Hubbe) /* for compatibility */ #include "interpret.h"
d3015d2000-04-18Jonas Wallden 
5377b91997-02-01Henrik Grubbström (Grubba) #endif /* THREADS_H */
7965d72001-01-24Fredrik Hübinette (Hubbe)