Added real code written by Timo Schulz.

Not finished, though.
This commit is contained in:
Werner Koch 2004-12-13 09:05:31 +00:00
parent 98f0a18e77
commit 907c91960e
3 changed files with 1270 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2004-12-13 Werner Koch <wk@g10code.com>
* w32-pth.c, w32-pth.h: Added real code written by Timo Schulz.
Not finished, though.
2004-12-07 Werner Koch <wk@g10code.com>
* w32-pth.c, w32-pth.h: New.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
/* w32-pth.h - GNU Pth emulation for W32 (MS Windows).
* Copyright (C) 2004 g10 Code GmbH
* Copyright (c) 1999-2003 Ralf S. Engelschall <rse@engelschall.com>
* Copyright (C) 2004 g10 Code GmbH
*
* This file is part of GnuPG.
*
@ -16,6 +17,11 @@
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
* ------------------------------------------------------------------
* This code is based on Ralf Engelschall's GNU Pth, a non-preemptive
* thread scheduling library which can be found at
* http://www.gnu.org/software/pth/.
*/
/* Note that this header is usually used through a symlinked pth.h
@ -24,6 +30,217 @@
#ifndef W32_PTH_H
#define W32_PTH_H
#include <windows.h> /* We need this for sockaddr et al. FIXME: too
heavyweight - may be we should factor such
code out to a second header and adjust all
user files to include it only if required. */
#ifndef W32_PTH_HANDLE_INTERNAL
#define W32_PTH_HANDLE_INTERNAL int
#endif
/* Filedescriptor blocking modes. */
enum
{
PTH_FDMODE_ERROR = -1,
PTH_FDMODE_POLL = 0,
PTH_FDMODE_BLOCK,
PTH_FDMODE_NONBLOCK
};
/* Mutex values. */
#define PTH_MUTEX_INITIALIZED (1<<0)
#define PTH_MUTEX_LOCKED (1<<1)
#define PTH_MUTEX_INIT {{NULL, NULL}, PTH_MUTEX_INITIALIZED, NULL, 0}
#define PTH_KEY_INIT (1<<0)
/* Event subject classes. */
#define PTH_EVENT_FD (1<<1)
#define PTH_EVENT_SELECT (1<<2)
#define PTH_EVENT_SIGS (1<<3)
#define PTH_EVENT_TIME (1<<4)
#define PTH_EVENT_MSG (1<<5)
#define PTH_EVENT_MUTEX (1<<6)
#define PTH_EVENT_COND (1<<7)
#define PTH_EVENT_TID (1<<8)
#define PTH_EVENT_FUNC (1<<9)
/* Event occurrence restrictions. */
#define PTH_UNTIL_OCCURRED (1<<11)
#define PTH_UNTIL_FD_READABLE (1<<12)
#define PTH_UNTIL_FD_WRITEABLE (1<<13)
#define PTH_UNTIL_FD_EXCEPTION (1<<14)
#define PTH_UNTIL_TID_NEW (1<<15)
#define PTH_UNTIL_TID_READY (1<<16)
#define PTH_UNTIL_TID_WAITING (1<<17)
#define PTH_UNTIL_TID_DEAD (1<<18)
/* Event structure handling modes. */
#define PTH_MODE_REUSE (1<<20)
#define PTH_MODE_CHAIN (1<<21)
#define PTH_MODE_STATIC (1<<22)
/* Attribute commands for pth_attr_get and pth_attr_set(). */
enum
{
PTH_ATTR_PRIO, /* RW [int] Priority of thread. */
PTH_ATTR_NAME, /* RW [char *] Name of thread. */
PTH_ATTR_JOINABLE, /* RW [int] Thread detachment type. */
PTH_ATTR_CANCEL_STATE, /* RW [unsigned int] Thread cancellation state.*/
PTH_ATTR_STACK_SIZE, /* RW [unsigned int] Stack size. */
PTH_ATTR_STACK_ADDR, /* RW [char *] Stack lower address. */
PTH_ATTR_DISPATCHES, /* RO [int] Total number of
thread dispatches. */
PTH_ATTR_TIME_SPAWN, /* RO [pth_time_t] Time thread was spawned. */
PTH_ATTR_TIME_LAST, /* RO [pth_time_t] Time thread was
last dispatched. */
PTH_ATTR_TIME_RAN, /* RO [pth_time_t] Time thread was running. */
PTH_ATTR_START_FUNC, /* RO [void *(*)(void *)] Thread start function.*/
PTH_ATTR_START_ARG, /* RO [void *] Thread start argument. */
PTH_ATTR_STATE, /* RO [pth_state_t] Scheduling state. */
PTH_ATTR_EVENTS, /* RO [pth_event_t] Events the thread
is waiting for. */
PTH_ATTR_BOUND /* RO [int] Whether object is
bound to thread. */
};
/* Queries for pth_ctrl(). */
#define PTH_CTRL_GETAVLOAD (1<<1)
#define PTH_CTRL_GETPRIO (1<<2)
#define PTH_CTRL_GETNAME (1<<3)
#define PTH_CTRL_GETTHREADS_NEW (1<<4)
#define PTH_CTRL_GETTHREADS_READY (1<<5)
#define PTH_CTRL_GETTHREADS_RUNNING (1<<6)
#define PTH_CTRL_GETTHREADS_WAITING (1<<7)
#define PTH_CTRL_GETTHREADS_SUSPENDED (1<<8)
#define PTH_CTRL_GETTHREADS_DEAD (1<<9)
#define PTH_CTRL_DUMPSTATE (1<<10)
#define PTH_CTRL_GETTHREADS ( PTH_CTRL_GETTHREADS_NEW \
| PTH_CTRL_GETTHREADS_READY \
| PTH_CTRL_GETTHREADS_RUNNING \
| PTH_CTRL_GETTHREADS_WAITING \
| PTH_CTRL_GETTHREADS_SUSPENDED \
| PTH_CTRL_GETTHREADS_DEAD )
/* Event status codes. */
typedef enum
{
PTH_STATUS_PENDING,
PTH_STATUS_OCCURRED,
PTH_STATUS_FAILED
}
pth_status_t;
/* Event deallocation types. */
enum
{
PTH_FREE_THIS,
PTH_FREE_ALL
};
/* The Pth thread handle object. */
typedef void *pth_t;
/* The Mutex object. */
struct pth_mutex_s
{
unsigned mx_state;
W32_PTH_HANDLE_INTERNAL mx;
};
typedef struct pth_mutex_s pth_mutex_t;
/* The Event object. */
struct pth_event_s;
typedef struct pth_event_s *pth_event_t;
/* The Attribute object. */
struct pth_attr_s;
typedef struct pth_attr_s *pth_attr_t;
/* The Key object. */
typedef int pth_key_t;
/* The Pth time object. */
typedef struct timeval pth_time_t;
/* Function prototypes. */
int pth_init (void);
int pth_kill (void);
long pth_ctrl (unsigned long query, ...);
int pth_read_ev (int fd, void *buffer, size_t size, pth_event_t ev);
int pth_read (int fd, void *buffer, size_t size);
int pth_write_ev (int fd, const void *buffer, size_t size, pth_event_t ev);
int pth_write (int fd, const void *buffer, size_t size);
int pth_select (int nfds, fd_set *rfds, fd_set *wfds, fd_set *efds,
const struct timeval *timeout);
int pth_accept (int fd, struct sockaddr *addr, int *addrlen);
int pth_accept_ev (int fd, struct sockaddr *addr, int *addrlen,
pth_event_t hd);
int pth_connect (int fd, struct sockaddr *name, int namelen);
int pth_mutex_release (pth_mutex_t *hd);
int pth_mutex_acquire(pth_mutex_t *hd, int try_only, pth_event_t ev_extra);
int pth_mutex_init (pth_mutex_t *hd);
pth_attr_t pth_attr_new (void);
int pth_attr_destroy (pth_attr_t hd);
int pth_attr_set (pth_attr_t hd, int field, ...);
pth_t pth_spawn (pth_attr_t hd, void *(*func)(void *), void *arg);
int pth_join (pth_t hd, void **value);
int pth_abort (pth_t hd);
void pth_exit (void *value);
unsigned int pth_waitpid (unsigned int, int *status, int options);
int pth_wait (pth_event_t hd);
int pth_sleep (int n);
pth_time_t pth_timeout (long sec, long usec);
pth_event_t pth_event_isolate (pth_event_t hd);
int pth_event_free (pth_event_t hd, int mode);
int pth_event_status (pth_event_t hd);
int pth_event_occured (pth_event_t hd);
pth_event_t pth_event_concat (pth_event_t ev, ...);
pth_event_t pth_event (unsigned long spec, ...);
/*-- pth_util.c --*/
/* void sigemptyset (struct sigset_s * ss); */
/* int sigaddset (struct sigset_s * ss, int signo); */
#endif /*W32_PTH_H*/