blob: 81e101076f9e58bc4a987fe8e1912794d52139cb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (c) 1994, 1995. Netscape Communications Corporation. All
* rights reserved.
*
* Use of this software is governed by the terms of the license agreement for
* the Netscape Communications or Netscape Comemrce Server between the
* parties.
*/
/* ------------------------------------------------------------------------ */
/*
* systhr.h: Abstracted threading mechanisms
*
* Rob McCool
*/
#ifndef _SYSTHR_H
#define _SYSTHR_H
#include "netsite.h"
#include "systems.h"
#ifdef THREAD_ANY
#ifdef USE_NSPR
#include <nspr/prthread.h>
#include <nspr/prglobal.h>
typedef PRThread* SYS_THREAD;
#endif
#ifdef THREAD_WIN32
#include <nspr/prthread.h>
#include <nspr/prglobal.h>
#include <process.h>
typedef struct {
HANDLE hand;
DWORD id;
} sys_thread_s;
typedef sys_thread_s *SYS_THREAD;
#endif
/*
* systhread_start creates a thread with the given priority, will allocate
* a stack of stksz bytes, and calls fn with arg as its argument. stksz
* of zero will allocate a default stack size.
*
* XXX Priorities are system dependent
*/
SYS_THREAD systhread_start(int prio, int stksz, void (*fn)(void *), void *arg);
/*
* systhread_current returns a pointer to the current thread.
*/
#ifdef USE_NSPR
#define systhread_current() PR_CurrentThread()
#elif defined(THREAD_WIN32)
#define systhread_current() GetCurrentThreadId()
#endif
/*
* systhread_attach makes an existing thread an NSPR thread. Currently this
* is used only in NT.
*/
SYS_THREAD systhread_attach();
/*
* systhread_terminate terminates the thread that is passed in.
*/
void systhread_terminate(SYS_THREAD thr);
/*
* systhread_sleep puts the calling thread to sleep for the given number
* of milliseconds.
*/
void systhread_sleep(int milliseconds);
/*
* systhread_init initializes the threading system. name is a name for the
* program for debugging.
*/
void systhread_init(char *name);
/*
* systhread_timerset starts or re-sets the interrupt timer for a thread
* system. This should be considered a suggestion as most systems don't allow
* the timer interval to be changed.
*/
#ifdef THREAD_NSPR_USER
#define systhread_timerset(usec) PR_StartEvents(usec)
#elif defined(USE_NSPR)
#define systhread_timerset(usec) (void)(usec)
#elif defined(THREAD_WIN32)
#define systhread_timerset(usec) (void)(usec)
#endif
/*
* newkey allocates a new integer id for thread-private data. Use this
* key to identify a variable which you want to appear differently
* between threads, and then use setdata to associate a value with this
* key for each thread.
*/
int systhread_newkey(void);
/*
* Get data that has been previously associated with key in this thread.
* Returns NULL if setkey has not been called with this key by this
* thread previously, or the data that was previously used with setkey
* by this thread with this key.
*/
void *systhread_getdata(int key);
/*
* Associate data with the given key number in this thread.
*/
void systhread_setdata(int key, void *data);
#endif
#endif
|