pike.git / src / threads.c

version» Context lines:

pike.git/src/threads.c:1:   #include "global.h" - RCSID("$Id: threads.c,v 1.169 2001/10/05 01:30:14 hubbe Exp $"); + RCSID("$Id: threads.c,v 1.170 2001/10/28 18:02:49 nilsson Exp $");      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"
pike.git/src/threads.c:523:   }      /*! @module Thread    */      /*! @decl array(Thread.Thread) all_threads()    *!    *! This function returns an array with the thread ids of all threads.    *!    *! @seealso -  *! @[Thread.Thread()] +  *! @[Thread()]    */   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;   
pike.git/src/threads.c:723:    *! to the rest of the program. The new thread will call the function    *! @[f] with the arguments @[args]. When @[f] returns the thread will cease    *! to exist.    *!    *! All Pike functions are 'thread safe' meaning that running    *! a function at the same time from different threads will not corrupt    *! any internal data in the Pike process.    *!    *! @returns    *! The returned value will be the same as the return value of -  *! @[Thread.this_thread()] for the new thread. +  *! @[this_thread()] for the new thread.    *!    *! @note    *! This function is only available on systems with POSIX or UNIX or WIN32    *! threads support.    *!    *! @seealso    *! @[Mutex], @[Condition], @[this_thread()]    */   void f_thread_create(INT32 args)   {
pike.git/src/threads.c:779:    free((char *)arg);    Pike_error("Failed to create thread (errno = %d).\n",tmp);    }   }      /*! @endclass    */      #ifdef UNIX_THREADS   /*! @decl void thread_set_concurrency(int concurrency) +  *! +  *! @fixme +  *! Document this function    */   void f_thread_set_concurrency(INT32 args)   {    int c=1;    if(args) c=Pike_sp[-args].u.integer;    else Pike_error("No argument to thread_set_concurrency(int concurrency);\n");    pop_n_elems(args);    num_lwps=c;    th_setconcurrency(c);   }   #endif      /*! @decl Thread.Thread this_thread()    *!    *! This function returns the object that identifies this thread.    *!    *! @seealso -  *! @[Thread.Thread()] +  *! @[Thread()]    */   PMOD_EXPORT void f_this_thread(INT32 args)   {    pop_n_elems(args);    ref_push_object(Pike_interpreter.thread_id);   }      #define THIS_MUTEX ((struct mutex_storage *)(CURRENT_STORAGE))      
pike.git/src/threads.c:830:   {    struct mutex_storage *mut;    struct object *owner;    int initialized;   };      #define OB2KEY(X) ((struct key_storage *)((X)->storage))      /*! @class Mutex    *! -  *! @[Thread.Mutex] is a class that implements mutual exclusion locks. +  *! @[Mutex] is a class that implements mutual exclusion locks.    *! Mutex locks are used to prevent multiple threads from simultaneously    *! execute sections of code which access or change shared data. The basic    *! operations for a mutex is locking and unlocking. If a thread attempts    *! to lock an already locked mutex the thread will sleep until the mutex    *! is unlocked.    *!    *! @note    *! This class is simulated when Pike is compiled without thread support,    *! so it's always available.    *!
pike.git/src/threads.c:1021:    push_int(0);    }   }      /*! @decl Thread.Thread current_locking_thread()    *!    *! This mutex method returns the object that identifies the thread that    *! has locked the mutex. 0 is returned if the mutex isn't locked.    *!    *! @seealso -  *! @[Thread.Thread()] +  *! @[Thread()]    */   PMOD_EXPORT void f_mutex_locking_thread(INT32 args)   {    struct mutex_storage *m = THIS_MUTEX;       pop_n_elems(args);       if (m->key && OB2KEY(m->key)->owner)    ref_push_object(OB2KEY(m->key)->owner);    else    push_int(0);   }      /*! @decl Thread.Thread current_locking_key()    *!    *! This mutex method returns the key object currently governing    *! the lock on this mutex. 0 is returned if the mutex isn't locked.    *!    *! @seealso -  *! @[Thread.Thread()] +  *! @[Thread()]    */   PMOD_EXPORT void f_mutex_locking_key(INT32 args)   {    struct mutex_storage *m = THIS_MUTEX;       pop_n_elems(args);       if (m->key)    ref_push_object(m->key);    else
pike.git/src/threads.c:1124:    *!    *! Condition variables are used by threaded programs    *! to wait for events happening in other threads.    *!    *! @note    *! Condition variables are only available on systems with thread    *! support. The Condition class is not simulated otherwise, since that    *! can't be done accurately without continuations.    *!    *! @seealso -  *! @[Thread.Mutex] +  *! @[Mutex]    */      /*! @decl void wait()    *! @decl void wait(Thread.MutexKey mutex_key)    *!    *! Wait for contition.    *!    *! This function makes the current thread sleep until the condition    *! variable is signalled. The optional argument should be the 'key'    *! to a mutex lock. If present the mutex lock will be unlocked before    *! waiting for the condition in one atomic operation. After waiting    *! for the condition the mutex referenced by mutex_key will be re-locked.    *!    *! @seealso -  *! @[Thread.Mutex->lock()] +  *! @[Mutex->lock()]    */   void f_cond_wait(INT32 args)   {    COND_T *c;       if(threads_disabled)    Pike_error("Cannot wait for conditions when threads are disabled!\n");       if(args > 1) {    pop_n_elems(args - 1);
pike.git/src/threads.c:1384:    }   #endif   }      /*! @class Local    *!    *! Thread local variable storage.    *!    *! This class allows you to have variables which are separate for each    *! thread that uses it. It has two methods: @[get()] and @[set()]. A value -  *! stored in an instance of @[Thread.Local] can only be retrieved by that +  *! stored in an instance of @[Local] can only be retrieved by that    *! same thread.    *!    *! @note    *! This class is simulated when Pike is compiled without thread support,    *! so it's always available.    */      /* FIXME: Why not use an init callback()? */   void f_thread_local_create( INT32 args )   {
pike.git/src/threads.c:1413:   {    struct object *loc = clone_object(thread_local_prog,0);    pop_n_elems(args);    push_object(loc);   }      /*! @decl mixed get()    *!    *! Get the thread local value.    *! -  *! This returns the value prevoiusly stored in the @[Thread.Local] object by +  *! This returns the value prevoiusly stored in the @[Local] object by    *! the @[set()] method by this thread.    *!    *! @seealso    *! @[set()]    */   void f_thread_local_get(INT32 args)   {    struct svalue key;    struct mapping *m;    key.u.integer = ((struct thread_local *)CURRENT_STORAGE)->id;