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. */
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) 
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. */
18e21f2014-05-25Henrik Grubbström (Grubba) #define THREAD_FLAG_INHIBIT 4 /* Inhibit signals. */
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 {
d97eb72011-07-10Henrik Grubbström (Grubba)  struct Pike_interpreter_struct state;
1d456f2003-02-20Henrik Grubbström (Grubba)  struct object *thread_obj; /* NOTE: Not ref-counted! */
5923b12000-07-06Fredrik Hübinette (Hubbe)  struct mapping *thread_local; struct thread_state *hashlink, **backlink;
0431312003-02-15Henrik Grubbström (Grubba)  struct svalue result;
f625152008-08-05Martin Stjernholm  COND_T status_change; THREAD_T id;
247f732007-06-10Martin Stjernholm #ifdef CPU_TIME_MIGHT_BE_THREAD_LOCAL
f4a9952003-02-08Martin Stjernholm  cpu_time_t auto_gc_time; #endif
f625152008-08-05Martin Stjernholm  unsigned short waiting; /* Threads waiting on status_change. */ unsigned short flags; char swapped; /* Set if thread has been swapped out. */ signed char status;
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 */
35c3ae2010-10-30Martin Stjernholm PMOD_EXPORT int low_nt_create_thread(unsigned stack_size, 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);
a76b312010-09-28Henrik Grubbström (Grubba) PMOD_EXPORT void pike_thread_yield(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);
09a5732008-08-05Martin Stjernholm void cleanup_all_other_threads (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);
2b42cc2007-10-06Marcus Comstedt PMOD_EXPORT void call_with_interpreter(void (*func)(void *ctx), void *ctx); PMOD_EXPORT void enable_external_threads(void); PMOD_EXPORT void disable_external_threads(void);
84c9d92014-07-22Per Hedbor 
07513e1996-10-04Fredrik Hübinette (Hubbe) /* Prototypes end here */
e1118e2010-09-29Henrik Grubbström (Grubba) #else #define pike_thread_yield()
07513e1996-10-04Fredrik Hübinette (Hubbe) 
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 */