pike.git / src / threads.h

version» Context lines:

pike.git/src/threads.h:1:   /* -  * $Id: threads.h,v 1.44 1998/07/05 13:48:58 grubba Exp $ +  * $Id: threads.h,v 1.45 1998/07/10 15:52:08 grubba Exp $    */   #ifndef THREADS_H   #define THREADS_H      #include "machine.h"   #include "interpret.h"   #include "object.h"   #include "error.h"   #ifdef HAVE_SYS_TYPES_H   /* Needed for pthread_t on OSF/1 */
pike.git/src/threads.h:224:         extern MUTEX_T interpreter_lock;      extern COND_T live_threads_change; /* Used by _disable_threads */   extern COND_T threads_disabled_change; /* Used by _disable_threads */      struct svalue;   struct frame;    + extern MUTEX_T interleave_lock; +  + struct interleave_mutex + { +  struct interleave_mutex *next; +  struct interleave_mutex *prev; +  MUTEX_T lock; + }; +  + #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) { \ +  THREADS_FPRINTF(0, (stderr, "Locking IMutex 0x%08p...\n", (im))); \ +  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) { \ +  THREADS_FPRINTF(0, (stderr, "Unlocking IMutex 0x%08p...\n", (im))); \ +  mt_unlock(&((im)->lock)); \ +  } \ +  } while(0) +    #define THREAD_NOT_STARTED -1   #define THREAD_RUNNING 0   #define THREAD_EXITED 1      struct thread_state {    char swapped;    char status;    COND_T status_change;    THREAD_T id;    struct thread_state *hashlink, **backlink;
pike.git/src/threads.h:265: Inside #if undefined(th_equal)
     #ifndef th_equal   #define th_equal(X,Y) (!MEMCMP(&(X),&(Y),sizeof(THREAD_T)))   #endif      #ifndef th_hash   #define th_hash(X) hashmem((unsigned char *)&(X),sizeof(THREAD_T), 16)   #endif      /* Define to get a debug-trace of some of the threads operations. */ - /* #define VERBOSE_THREADS_DEBUG */ + /* #define VERBOSE_THREADS_DEBUG 0 */ /* Some debug */ + /* #define VERBOSE_THREADS_DEBUG 1 */ /* Lots of debug */      #ifndef VERBOSE_THREADS_DEBUG - #define THREADS_FPRINTF(X) + #define THREADS_FPRINTF(L,X)   #else - #define THREADS_FPRINTF(X) fprintf X + #define THREADS_FPRINTF(L,X) do { \ +  if ((VERBOSE_THREADS_DEBUG + 0) >= (L)) fprintf X; \ +  } while(0)   #endif /* VERBOSE_THREADS_DEBUG */      #ifdef THREAD_TRACE   #define SWAP_OUT_TRACE(_tmp) do { extern int t_flag; (_tmp)->t_flag = t_flag; } while(0)   #define SWAP_IN_TRACE(_tmp) do { extern int t_flag; t_flag = (_tmp)->t_flag; } while(0)   #else /* !THREAD_TRACE */   #define SWAP_OUT_TRACE(_tmp)   #define SWAP_IN_TRACE(_tmp)   #endif /* THREAD_TRACE */   
pike.git/src/threads.h:313:    recoveries=(_tmp)->recoveries;\    sp=(_tmp)->sp;\    thread_id=(_tmp)->thread_id;\    SWAP_IN_TRACE(_tmp); \    } while(0)      #define SWAP_OUT_CURRENT_THREAD() \    do {\    struct thread_state *_tmp=(struct thread_state *)thread_id->storage; \    SWAP_OUT_THREAD(_tmp); \ -  THREADS_FPRINTF((stderr, "SWAP_OUT_CURRENT_THREAD() %s:%d t:%08x\n", \ +  THREADS_FPRINTF(1, (stderr, "SWAP_OUT_CURRENT_THREAD() %s:%d t:%08x\n", \    __FILE__, __LINE__, (unsigned int)_tmp->thread_id)) \      #define SWAP_IN_CURRENT_THREAD() \ -  THREADS_FPRINTF((stderr, "SWAP_IN_CURRENT_THREAD() %s:%d ... t:%08x\n", \ +  THREADS_FPRINTF(1, (stderr, "SWAP_IN_CURRENT_THREAD() %s:%d ... t:%08x\n", \    __FILE__, __LINE__, (unsigned int)_tmp->thread_id)); \    SWAP_IN_THREAD(_tmp);\    } while(0)      #if defined(DEBUG) && ! defined(DONT_HIDE_GLOBALS)   /* Note that scalar types are used in place of pointers and vice versa    * below. This is intended to cause compiler warnings/errors if    * there is an attempt to use the global variables in an unsafe    * environment.    */   #define HIDE_GLOBAL_VARIABLES() do { \    int sp = 0, evaluator_stack = 0, mark_sp = 0, mark_stack = 0, fp = 0; \    void *evaluator_stack_malloced = NULL, *mark_stack_malloced = NULL; \    int recoveries = 0, thread_id = 0; \    int error = 0, xalloc = 0, low_my_putchar = 0, low_my_binary_strcat = 0; \    int low_make_buf_space = 0, pop_n_elems = 0; \ -  int push_sp_mark = 0, pop_sp_mark = 0 +  int push_sp_mark = 0, pop_sp_mark = 0, threads_disabled = 1      /* Note that the semi-colon below is needed to add an empty statement    * in case there is a label before the macro.    */   #define REVEAL_GLOBAL_VARIABLES() ; } while(0)   #else /* DEBUG */   #define HIDE_GLOBAL_VARIABLES()   #define REVEAL_GLOBAL_VARIABLES()   #endif /* DEBUG */         #define THREADS_ALLOW() do { \    struct thread_state *_tmp=(struct thread_state *)thread_id->storage; \    if(num_threads > 1 && !threads_disabled) { \    SWAP_OUT_THREAD(_tmp); \ -  THREADS_FPRINTF((stderr, "THREADS_ALLOW() %s:%d t:%08x(#%d)\n", \ +  THREADS_FPRINTF(1, (stderr, "THREADS_ALLOW() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp->thread_id, live_threads)); \    mt_unlock(& interpreter_lock); \    } else {} \    HIDE_GLOBAL_VARIABLES()      #define THREADS_DISALLOW() \    REVEAL_GLOBAL_VARIABLES(); \    if(_tmp->swapped) { \    mt_lock(& interpreter_lock); \ -  THREADS_FPRINTF((stderr, "THREADS_DISALLOW() %s:%d t:%08x(#%d)\n", \ +  THREADS_FPRINTF(1, (stderr, "THREADS_DISALLOW() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp->thread_id, live_threads)); \    while (threads_disabled) { \ -  THREADS_FPRINTF((stderr, "THREADS_DISALLOW(): Threads disabled\n")); \ +  THREADS_FPRINTF(1, (stderr, \ +  "THREADS_DISALLOW(): Threads disabled\n")); \    co_wait(&threads_disabled_change, &interpreter_lock); \    } \    SWAP_IN_THREAD(_tmp);\    } \    } while(0)      #define THREADS_ALLOW_UID() do { \    struct thread_state *_tmp_uid=(struct thread_state *)thread_id->storage; \    if(num_threads > 1 && !threads_disabled) { \    SWAP_OUT_THREAD(_tmp_uid); \    live_threads++; \ -  THREADS_FPRINTF((stderr, "THREADS_ALLOW_UID() %s:%d t:%08x(#%d)\n", \ +  THREADS_FPRINTF(1, (stderr, "THREADS_ALLOW_UID() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp_uid->thread_id, live_threads)); \    mt_unlock(& interpreter_lock); \    } else {} \    HIDE_GLOBAL_VARIABLES()      #define THREADS_DISALLOW_UID() \    REVEAL_GLOBAL_VARIABLES(); \    if(_tmp_uid->swapped) { \    mt_lock(& interpreter_lock); \    live_threads--; \ -  THREADS_FPRINTF((stderr, "THREADS_DISALLOW_UID() %s:%d t:%08x(#%d)\n", \ +  THREADS_FPRINTF(1, (stderr, \ +  "THREADS_DISALLOW_UID() %s:%d t:%08x(#%d)\n", \    __FILE__, __LINE__, \    (unsigned int)_tmp_uid->thread_id, live_threads)); \    co_broadcast(&live_threads_change); \    while (threads_disabled) { \ -  THREADS_FPRINTF((stderr, "THREADS_DISALLOW_UID(): Wait...\n")); \ +  THREADS_FPRINTF(1, (stderr, "THREADS_DISALLOW_UID(): Wait...\n")); \    co_wait(&threads_disabled_change, &interpreter_lock); \    } \    SWAP_IN_THREAD(_tmp_uid);\    } \    } while(0)      /* Prototypes begin here */   struct thread_starter;   void *new_thread_func(void * data);   void f_thread_create(INT32 args);
pike.git/src/threads.h:426:   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);   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);   void th_farm(void (*fun)(void *), void *);   void th_init(void); + void low_th_init(void);   void th_cleanup(void);   void thread_table_insert(struct object *o);   void thread_table_delete(struct object *o);   struct thread_state *thread_state_for_id(THREAD_T tid);   struct object *thread_for_id(THREAD_T tid);   void f_all_threads(INT32 args);      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); +    /* Prototypes end here */      #else   #define th_setconcurrency(X)   #define DEFINE_MUTEX(X) -  + #define DEFINE_IMUTEX(X) + #define init_interleave_mutex(X) + #define LOCK_IMUTEX(X) + #define UNLOCK_IMUTEX(X)   #define mt_init(X)   #define mt_lock(X)   #define mt_unlock(X)   #define mt_destroy(X)   #define THREADS_ALLOW()   #define THREADS_DISALLOW()   #define THREADS_ALLOW_UID()   #define THREADS_DISALLOW_UID()   #define HIDE_GLOBAL_VARIABLES()   #define REVEAL_GLOBAL_VARIABLES()   #define th_init() -  + #define low_th_init()   #define th_cleanup()   #define th_init_programs()   #define th_self() ((void*)0)   #define co_signal(X)   #define co_broadcast(X)      #define init_threads_disable(X)   #define exit_threads_disable(X)      #endif /* _REENTRANT */