~ubuntu-branches/ubuntu/dapper/gnupg2/dapper

« back to all changes in this revision

Viewing changes to jnlib/w32-pth.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Mueller
  • Date: 2005-03-29 10:30:32 UTC
  • Revision ID: james.westby@ubuntu.com-20050329103032-sj42n2ain3ipx310
Tags: upstream-1.9.15
ImportĀ upstreamĀ versionĀ 1.9.15

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
5
 * This file is part of GnuPG.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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 
 
20
 *
 
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/.
 
25
 */
 
26
 
 
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. */
 
30
#ifndef W32_PTH_H
 
31
#define W32_PTH_H
 
32
 
 
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. */ 
 
37
 
 
38
#ifndef W32_PTH_HANDLE_INTERNAL
 
39
#define W32_PTH_HANDLE_INTERNAL  int
 
40
#endif
 
41
 
 
42
 
 
43
/* Filedescriptor blocking modes.  */
 
44
enum
 
45
  {
 
46
    PTH_FDMODE_ERROR = -1,
 
47
    PTH_FDMODE_POLL  =  0,
 
48
    PTH_FDMODE_BLOCK,
 
49
    PTH_FDMODE_NONBLOCK
 
50
  };
 
51
 
 
52
 
 
53
/* Mutex values. */
 
54
#define PTH_MUTEX_INITIALIZED  (1<<0)
 
55
#define PTH_MUTEX_LOCKED       (1<<1)
 
56
 
 
57
/* Note: We can't do static initialization, thus we don't define the
 
58
   initializer PTH_MUTEX_INIT.  */
 
59
 
 
60
 
 
61
#define PTH_KEY_INIT           (1<<0)
 
62
 
 
63
 
 
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)
 
74
 
 
75
 
 
76
 
 
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)
 
86
 
 
87
 
 
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)
 
92
 
 
93
 
 
94
/* Attribute commands for pth_attr_get and pth_attr_set(). */
 
95
enum
 
96
  {
 
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
 
107
                                                   last dispatched.  */
 
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 
 
113
                                                   is waiting for.  */
 
114
    PTH_ATTR_BOUND           /* RO [int]           Whether object is 
 
115
                                                   bound to thread. */
 
116
  };
 
117
 
 
118
 
 
119
 
 
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)
 
131
 
 
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        )
 
138
 
 
139
 
 
140
/* Event status codes. */
 
141
typedef enum
 
142
  {
 
143
    PTH_STATUS_PENDING,
 
144
    PTH_STATUS_OCCURRED,
 
145
    PTH_STATUS_FAILED
 
146
  }
 
147
pth_status_t;
 
148
 
 
149
 
 
150
/* Event deallocation types. */
 
151
enum 
 
152
  {
 
153
    PTH_FREE_THIS,
 
154
    PTH_FREE_ALL 
 
155
  };
 
156
 
 
157
 
 
158
/* The Pth thread handle object.  */
 
159
typedef void *pth_t;
 
160
 
 
161
 
 
162
/* The Mutex object.  */
 
163
typedef W32_PTH_HANDLE_INTERNAL pth_mutex_t;
 
164
 
 
165
 
 
166
/* The Event object.  */
 
167
struct pth_event_s;
 
168
typedef struct pth_event_s *pth_event_t;
 
169
 
 
170
 
 
171
/* The Attribute object.  */
 
172
struct pth_attr_s;
 
173
typedef struct pth_attr_s *pth_attr_t;
 
174
 
 
175
 
 
176
/* The Key object.  */
 
177
typedef int pth_key_t;
 
178
 
 
179
 
 
180
/* The Pth time object.  */
 
181
typedef struct timeval pth_time_t;
 
182
 
 
183
 
 
184
/* Function prototypes. */
 
185
int pth_init (void);
 
186
int pth_kill (void);
 
187
long pth_ctrl (unsigned long query, ...);
 
188
 
 
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);
 
193
 
 
194
int pth_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds,
 
195
                const struct timeval *timeout);
 
196
 
 
197
int pth_accept (int fd, struct sockaddr *addr, int *addrlen);
 
198
int pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen,
 
199
                   pth_event_t hd);
 
200
 
 
201
int pth_connect (int fd, struct sockaddr *name, int namelen);
 
202
 
 
203
 
 
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);
 
207
 
 
208
 
 
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, ...);
 
212
 
 
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);
 
218
 
 
219
unsigned int pth_waitpid (unsigned int, int *status, int options);
 
220
int pth_wait (pth_event_t hd);
 
221
 
 
222
int pth_sleep (int n);
 
223
pth_time_t pth_timeout (long sec, long usec);
 
224
 
 
225
 
 
226
 
 
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, ...);
 
233
 
 
234
 
 
235
 
 
236
/*-- pth_util.c --*/
 
237
 
 
238
/* void sigemptyset (struct sigset_s * ss); */
 
239
 
 
240
/* int sigaddset (struct sigset_s * ss, int signo); */
 
241
 
 
242
 
 
243
 
 
244
#endif /*W32_PTH_H*/