2 * Copyright (c) 1994, 1995. Netscape Communications Corporation. All
5 * Use of this software is governed by the terms of the license agreement for
6 * the Netscape Communications or Netscape Comemrce Server between the
11 /* ------------------------------------------------------------------------ */
15 * systhr.h: Abstracted threading mechanisms
29 #include <nspr/prthread.h>
30 #include <nspr/prglobal.h>
32 typedef PRThread
* SYS_THREAD
;
36 #include <nspr/prthread.h>
37 #include <nspr/prglobal.h>
43 typedef sys_thread_s
*SYS_THREAD
;
47 * systhread_start creates a thread with the given priority, will allocate
48 * a stack of stksz bytes, and calls fn with arg as its argument. stksz
49 * of zero will allocate a default stack size.
51 * XXX Priorities are system dependent
54 SYS_THREAD
systhread_start(int prio
, int stksz
, void (*fn
)(void *), void *arg
);
57 * systhread_current returns a pointer to the current thread.
60 #define systhread_current() PR_CurrentThread()
61 #elif defined(THREAD_WIN32)
62 #define systhread_current() GetCurrentThreadId()
66 * systhread_attach makes an existing thread an NSPR thread. Currently this
70 SYS_THREAD
systhread_attach();
73 * systhread_terminate terminates the thread that is passed in.
75 void systhread_terminate(SYS_THREAD thr
);
79 * systhread_sleep puts the calling thread to sleep for the given number
82 void systhread_sleep(int milliseconds
);
85 * systhread_init initializes the threading system. name is a name for the
86 * program for debugging.
88 void systhread_init(char *name
);
91 * systhread_timerset starts or re-sets the interrupt timer for a thread
92 * system. This should be considered a suggestion as most systems don't allow
93 * the timer interval to be changed.
95 #ifdef THREAD_NSPR_USER
96 #define systhread_timerset(usec) PR_StartEvents(usec)
98 #elif defined(USE_NSPR)
99 #define systhread_timerset(usec) (void)(usec)
101 #elif defined(THREAD_WIN32)
102 #define systhread_timerset(usec) (void)(usec)
107 * newkey allocates a new integer id for thread-private data. Use this
108 * key to identify a variable which you want to appear differently
109 * between threads, and then use setdata to associate a value with this
110 * key for each thread.
112 int systhread_newkey();
115 * Get data that has been previously associated with key in this thread.
116 * Returns NULL if setkey has not been called with this key by this
117 * thread previously, or the data that was previously used with setkey
118 * by this thread with this key.
120 void *systhread_getdata(int key
);
123 * Associate data with the given key number in this thread.
125 void systhread_setdata(int key
, void *data
);