e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
22549b2006-08-02Martin Stjernholm || $Id: threads.h,v 1.131 2006/08/02 15:02:40 mast Exp $
e576bb2002-10-11Martin Nilsson */
1b10db2002-10-08Martin Nilsson 
07513e1996-10-04Fredrik Hübinette (Hubbe) #ifndef THREADS_H #define THREADS_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 
f4a9952003-02-08Martin Stjernholm #include "pike_rusage.h"
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) 
9f85722003-03-31Henrik Grubbström (Grubba) /* Status values */
5740881998-01-01Fredrik Hübinette (Hubbe) #define THREAD_NOT_STARTED -1 #define THREAD_RUNNING 0 #define THREAD_EXITED 1
6542e82004-08-12Henrik Grubbström (Grubba) /* Thread flags */ #define THREAD_FLAG_TERM 1 /* Pending termination. */ #define THREAD_FLAG_INTR 2 /* Pending interrupt. */
286b312004-12-30Henrik Grubbström (Grubba) #define THREAD_FLAG_SIGNAL_MASK 3 /* All of the above. */
9f85722003-03-31Henrik Grubbström (Grubba) /* Debug flags */ #define THREAD_DEBUG_LOOSE 1 /* Thread is not bound to the interpreter. */
5923b12000-07-06Fredrik Hübinette (Hubbe) struct thread_state { struct Pike_interpreter state;
1d456f2003-02-20Henrik Grubbström (Grubba)  struct object *thread_obj; /* NOTE: Not ref-counted! */
9f85722003-03-31Henrik Grubbström (Grubba)  char swapped; /* Set if thread has been swapped out. */
6818b02003-02-20Henrik Grubbström (Grubba) #ifdef __CHAR_UNSIGNED__ signed char status; #else
5923b12000-07-06Fredrik Hübinette (Hubbe)  char status;
9f85722003-03-31Henrik Grubbström (Grubba) #endif
6542e82004-08-12Henrik Grubbström (Grubba)  unsigned short flags;
5923b12000-07-06Fredrik Hübinette (Hubbe)  COND_T status_change; THREAD_T id; struct mapping *thread_local; struct thread_state *hashlink, **backlink;
0431312003-02-15Henrik Grubbström (Grubba)  struct svalue result;
9699fc2003-02-10Martin Stjernholm #if CPU_TIME_IS_THREAD_LOCAL == PIKE_YES
f4a9952003-02-08Martin Stjernholm  cpu_time_t auto_gc_time; #endif
6542e82004-08-12Henrik Grubbström (Grubba) #ifdef PIKE_DEBUG char debug_flags; #endif
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 */
6e4c642002-09-11Marcus Comstedt int low_nt_create_thread(unsigned 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);
0431312003-02-15Henrik Grubbström (Grubba) PMOD_EXPORT void thread_table_insert(struct thread_state *s); PMOD_EXPORT void thread_table_delete(struct thread_state *s);
d6896c2000-12-16Marcus Comstedt 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 */