1
/* w32-pth.h - GNU Pth emulation for W32 (MS Windows).
2
* Copyright (c) 1999-2003 Ralf S. Engelschall <rse@engelschall.com>
3
* Copyright (C) 2004 g10 Code GmbH
5
* This file is part of GnuPG.
7
* GnuPG is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* GnuPG is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21
* ------------------------------------------------------------------
22
* This code is based on Ralf Engelschall's GNU Pth, a non-preemptive
23
* thread scheduling library which can be found at
24
* http://www.gnu.org/software/pth/.
27
/* Note that this header is usually used through a symlinked pth.h
28
file. This is needed so that we don't have a pth.h file here which
29
would conflict if a system really has pth available. */
33
#include <windows.h> /* We need this for sockaddr et al. FIXME: too
34
heavyweight - may be we should factor such
35
code out to a second header and adjust all
36
user files to include it only if required. */
38
#ifndef W32_PTH_HANDLE_INTERNAL
39
#define W32_PTH_HANDLE_INTERNAL int
43
/* Filedescriptor blocking modes. */
46
PTH_FDMODE_ERROR = -1,
54
#define PTH_MUTEX_INITIALIZED (1<<0)
55
#define PTH_MUTEX_LOCKED (1<<1)
57
/* Note: We can't do static initialization, thus we don't define the
58
initializer PTH_MUTEX_INIT. */
61
#define PTH_KEY_INIT (1<<0)
64
/* Event subject classes. */
65
#define PTH_EVENT_FD (1<<1)
66
#define PTH_EVENT_SELECT (1<<2)
67
#define PTH_EVENT_SIGS (1<<3)
68
#define PTH_EVENT_TIME (1<<4)
69
#define PTH_EVENT_MSG (1<<5)
70
#define PTH_EVENT_MUTEX (1<<6)
71
#define PTH_EVENT_COND (1<<7)
72
#define PTH_EVENT_TID (1<<8)
73
#define PTH_EVENT_FUNC (1<<9)
77
/* Event occurrence restrictions. */
78
#define PTH_UNTIL_OCCURRED (1<<11)
79
#define PTH_UNTIL_FD_READABLE (1<<12)
80
#define PTH_UNTIL_FD_WRITEABLE (1<<13)
81
#define PTH_UNTIL_FD_EXCEPTION (1<<14)
82
#define PTH_UNTIL_TID_NEW (1<<15)
83
#define PTH_UNTIL_TID_READY (1<<16)
84
#define PTH_UNTIL_TID_WAITING (1<<17)
85
#define PTH_UNTIL_TID_DEAD (1<<18)
88
/* Event structure handling modes. */
89
#define PTH_MODE_REUSE (1<<20)
90
#define PTH_MODE_CHAIN (1<<21)
91
#define PTH_MODE_STATIC (1<<22)
94
/* Attribute commands for pth_attr_get and pth_attr_set(). */
97
PTH_ATTR_PRIO, /* RW [int] Priority of thread. */
98
PTH_ATTR_NAME, /* RW [char *] Name of thread. */
99
PTH_ATTR_JOINABLE, /* RW [int] Thread detachment type. */
100
PTH_ATTR_CANCEL_STATE, /* RW [unsigned int] Thread cancellation state.*/
101
PTH_ATTR_STACK_SIZE, /* RW [unsigned int] Stack size. */
102
PTH_ATTR_STACK_ADDR, /* RW [char *] Stack lower address. */
103
PTH_ATTR_DISPATCHES, /* RO [int] Total number of
104
thread dispatches. */
105
PTH_ATTR_TIME_SPAWN, /* RO [pth_time_t] Time thread was spawned. */
106
PTH_ATTR_TIME_LAST, /* RO [pth_time_t] Time thread was
108
PTH_ATTR_TIME_RAN, /* RO [pth_time_t] Time thread was running. */
109
PTH_ATTR_START_FUNC, /* RO [void *(*)(void *)] Thread start function.*/
110
PTH_ATTR_START_ARG, /* RO [void *] Thread start argument. */
111
PTH_ATTR_STATE, /* RO [pth_state_t] Scheduling state. */
112
PTH_ATTR_EVENTS, /* RO [pth_event_t] Events the thread
114
PTH_ATTR_BOUND /* RO [int] Whether object is
120
/* Queries for pth_ctrl(). */
121
#define PTH_CTRL_GETAVLOAD (1<<1)
122
#define PTH_CTRL_GETPRIO (1<<2)
123
#define PTH_CTRL_GETNAME (1<<3)
124
#define PTH_CTRL_GETTHREADS_NEW (1<<4)
125
#define PTH_CTRL_GETTHREADS_READY (1<<5)
126
#define PTH_CTRL_GETTHREADS_RUNNING (1<<6)
127
#define PTH_CTRL_GETTHREADS_WAITING (1<<7)
128
#define PTH_CTRL_GETTHREADS_SUSPENDED (1<<8)
129
#define PTH_CTRL_GETTHREADS_DEAD (1<<9)
130
#define PTH_CTRL_DUMPSTATE (1<<10)
132
#define PTH_CTRL_GETTHREADS ( PTH_CTRL_GETTHREADS_NEW \
133
| PTH_CTRL_GETTHREADS_READY \
134
| PTH_CTRL_GETTHREADS_RUNNING \
135
| PTH_CTRL_GETTHREADS_WAITING \
136
| PTH_CTRL_GETTHREADS_SUSPENDED \
137
| PTH_CTRL_GETTHREADS_DEAD )
140
/* Event status codes. */
150
/* Event deallocation types. */
158
/* The Pth thread handle object. */
162
/* The Mutex object. */
163
typedef W32_PTH_HANDLE_INTERNAL pth_mutex_t;
166
/* The Event object. */
168
typedef struct pth_event_s *pth_event_t;
171
/* The Attribute object. */
173
typedef struct pth_attr_s *pth_attr_t;
176
/* The Key object. */
177
typedef int pth_key_t;
180
/* The Pth time object. */
181
typedef struct timeval pth_time_t;
184
/* Function prototypes. */
187
long pth_ctrl (unsigned long query, ...);
189
int pth_read_ev (int fd, void *buffer, size_t size, pth_event_t ev);
190
int pth_read (int fd, void *buffer, size_t size);
191
int pth_write_ev (int fd, const void *buffer, size_t size, pth_event_t ev);
192
int pth_write (int fd, const void *buffer, size_t size);
194
int pth_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds,
195
const struct timeval *timeout);
197
int pth_accept (int fd, struct sockaddr *addr, int *addrlen);
198
int pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen,
201
int pth_connect (int fd, struct sockaddr *name, int namelen);
204
int pth_mutex_release (pth_mutex_t *hd);
205
int pth_mutex_acquire(pth_mutex_t *hd, int try_only, pth_event_t ev_extra);
206
int pth_mutex_init (pth_mutex_t *hd);
209
pth_attr_t pth_attr_new (void);
210
int pth_attr_destroy (pth_attr_t hd);
211
int pth_attr_set (pth_attr_t hd, int field, ...);
213
pth_t pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg);
214
pth_t pth_self (void);
215
int pth_join (pth_t hd, void **value);
216
int pth_abort (pth_t hd);
217
void pth_exit (void *value);
219
unsigned int pth_waitpid (unsigned int, int *status, int options);
220
int pth_wait (pth_event_t hd);
222
int pth_sleep (int n);
223
pth_time_t pth_timeout (long sec, long usec);
227
pth_event_t pth_event_isolate (pth_event_t hd);
228
int pth_event_free (pth_event_t hd, int mode);
229
int pth_event_status (pth_event_t hd);
230
int pth_event_occurred (pth_event_t hd);
231
pth_event_t pth_event_concat (pth_event_t ev, ...);
232
pth_event_t pth_event (unsigned long spec, ...);
238
/* void sigemptyset (struct sigset_s * ss); */
240
/* int sigaddset (struct sigset_s * ss, int signo); */