pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.132 2000/07/07 01:24:14 hubbe Exp $"); + RCSID("$Id: threads.c,v 1.133 2000/07/28 17:16:55 hubbe Exp $");    - int num_threads = 1; - int threads_disabled = 0; + PMOD_EXPORT int num_threads = 1; + PMOD_EXPORT int threads_disabled = 0;      #ifdef _REENTRANT   #include "threads.h"   #include "array.h"   #include "mapping.h"   #include "object.h"   #include "pike_macros.h"   #include "callback.h"   #include "builtin_functions.h"   #include "constants.h"   #include "program.h"   #include "program_id.h"   #include "gc.h"   #include "main.h"   #include "module_support.h"   #include "pike_types.h"   #include "operators.h"      #include <errno.h>    - int live_threads = 0; - COND_T live_threads_change; - COND_T threads_disabled_change; - size_t thread_stack_size=1024 * 1204; + PMOD_EXPORT int live_threads = 0; + PMOD_EXPORT COND_T live_threads_change; + PMOD_EXPORT COND_T threads_disabled_change; + PMOD_EXPORT size_t thread_stack_size=1024 * 1204;      #ifndef HAVE_PTHREAD_ATFORK   #include "callback.h"      static struct callback_list atfork_prepare_callback;   static struct callback_list atfork_parent_callback;   static struct callback_list atfork_child_callback;      int th_atfork(void (*prepare)(void),void (*parent)(void),void (*child)(void))   {
pike.git/src/threads.c:96: Inside #if defined(__NT__) and #if defined(PIKE_DEBUG)
   }    }       __except (1) {    return 0;    }       return 1;   }    - HANDLE CheckValidHandle(HANDLE h) + PMOD_EXPORT HANDLE CheckValidHandle(HANDLE h)   {    if(!IsValidHandle(h))    fatal("Invalid handle!\n");    return h;   }      #endif      #endif      #ifdef SIMULATE_COND_WITH_EVENT - int co_wait(COND_T *c, MUTEX_T *m) + PMOD_EXPORT int co_wait(COND_T *c, MUTEX_T *m)   {    struct cond_t_queue me;    event_init(&me.event);    me.next=0;    mt_lock(& c->lock);       if(c->tail)    {    c->tail->next=&me;    c->tail=&me;
pike.git/src/threads.c:139: Inside #if defined(SIMULATE_COND_WITH_EVENT)
   /* Cancellation point?? */      #ifdef PIKE_DEBUG    if(me.next)    fatal("Wait on event return prematurely!!\n");   #endif       return 0;   }    - int co_signal(COND_T *c) + PMOD_EXPORT int co_signal(COND_T *c)   {    struct cond_t_queue *t;    mt_lock(& c->lock);    if((t=c->head))    {    c->head=t->next;    t->next=0;    if(!c->head) c->tail=0;    }    mt_unlock(& c->lock);    if(t)    event_signal(& t->event);    return 0;   }    - int co_broadcast(COND_T *c) + PMOD_EXPORT int co_broadcast(COND_T *c)   {    struct cond_t_queue *t,*n;    mt_lock(& c->lock);    n=c->head;    c->head=c->tail=0;    mt_unlock(& c->lock);       while((t=n))    {    n=t->next;    t->next=0;    event_signal(& t->event);    }       return 0;   }    - int co_destroy(COND_T *c) + PMOD_EXPORT int co_destroy(COND_T *c)   {    struct cond_t_queue *t;    mt_lock(& c->lock);    t=c->head;    mt_unlock(& c->lock);    if(t) return -1;    mt_destroy(& c->lock);    return 0;   }   
pike.git/src/threads.c:197:   #define THIS_THREAD ((struct thread_state *)CURRENT_STORAGE)      static struct callback *threads_evaluator_callback=0;   int thread_id_result_variable;      int th_running = 0;   #ifdef PIKE_DEBUG   int debug_interpreter_is_locked = 0;   THREAD_T debug_locking_thread;   #endif - MUTEX_T interpreter_lock, thread_table_lock, interleave_lock; + PMOD_EXPORT MUTEX_T interpreter_lock; + MUTEX_T thread_table_lock, interleave_lock;   struct program *mutex_key = 0;   struct program *thread_id_prog = 0;   struct program *thread_local_prog = 0;   #ifdef POSIX_THREADS   pthread_attr_t pattr;   pthread_attr_t small_pattr;   #endif - int thread_storage_offset; + PMOD_EXPORT int thread_storage_offset;      struct thread_starter   {    struct object *id;    struct array *args;   #ifdef HAVE_BROKEN_LINUX_THREAD_EUID    int euid, egid;   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */   };   
pike.git/src/threads.c:442:    struct thread_state *s = OBJ2THREAD(o);   /* dumpmem("thread_table_delete",&s->id, sizeof(THREAD_T)); */    mt_lock( & thread_table_lock );    num_pike_threads--;    if(s->hashlink != NULL)    s->hashlink->backlink = s->backlink;    *(s->backlink) = s->hashlink;    mt_unlock( & thread_table_lock );   }    - struct thread_state *thread_state_for_id(THREAD_T tid) + PMOD_EXPORT struct thread_state *thread_state_for_id(THREAD_T tid)   {    unsigned INT32 h = thread_table_hash(&tid);    struct thread_state *s = NULL;   #if 0    if(num_threads>1)    dumpmem("thread_state_for_id: ",&tid,sizeof(tid));   #endif   #ifdef PIKE_DEBUG    if(h>=THREAD_TABLE_SIZE)    fatal("thread_table_hash failed miserably!\n");
pike.git/src/threads.c:493: Inside #if 0
   mt_unlock( & thread_table_lock );   #if 0    if(num_threads>1 && s)    dumpmem("thread_state_for_id return value: ",&s->id,sizeof(tid));   #endif    return s;    /* NOTEZ BIEN: Return value only guaranteed to remain valid as long    as you have the interpreter lock, unless tid == th_self() */   }    - struct object *thread_for_id(THREAD_T tid) + PMOD_EXPORT struct object *thread_for_id(THREAD_T tid)   {    struct thread_state *s = thread_state_for_id(tid);    return (s == NULL? NULL : THREADSTATE2OBJ(s));    /* See NB in thread_state_for_id. Lifespan of result can be prolonged    by incrementing refcount though. */   }       - void f_all_threads(INT32 args) + PMOD_EXPORT void f_all_threads(INT32 args)   {    /* Return an unordered array containing all threads that was running    at the time this function was invoked */       INT32 x;    struct svalue *oldsp;    struct thread_state *s;       pop_n_elems(args);    oldsp = Pike_sp;
pike.git/src/threads.c:524:    for(x=0; x<THREAD_TABLE_SIZE; x++)    for(s=thread_table_chains[x]; s; s=s->hashlink) {    struct object *o = THREADSTATE2OBJ(s);    ref_push_object(o);    }    mt_unlock( & thread_table_lock );    f_aggregate(Pike_sp-oldsp);   }       - int count_pike_threads(void) + PMOD_EXPORT int count_pike_threads(void)   {    return num_pike_threads;   }      static void check_threads(struct callback *cb, void *arg, void * arg2)   {    static int div_;    if(div_++ & 255) return;      #ifdef DEBUG
pike.git/src/threads.c:1472: Inside #if defined(HAVE_BROKEN_LINUX_THREAD_EUID)
     #ifdef HAVE_BROKEN_LINUX_THREAD_EUID    me->euid = geteuid();    me->egid = getegid();   #endif /* HAVE_BROKEN_LINUX_THREAD_EUID */       th_create_small(&me->me, farm, me);    return me;   }    - void th_farm(void (*fun)(void *), void *here) + PMOD_EXPORT void th_farm(void (*fun)(void *), void *here)   {    if(!fun) fatal("The farmers don't known how to handle empty fields\n");    mt_lock( &rosie );    if(farmers)    {    struct farmer *f = farmers;    farmers = f->neighbour;    mt_unlock( &rosie );    f->field = here;    f->harvest = fun;    co_signal( &f->harvest_moon );    return;    }    mt_unlock( &rosie );    new_farmer( fun, here );   }   #endif