* sched.cc: New file. Implement sched*.

* include/sched.h: New file.  User land includes for sched*.
* Makefile.in: Add sched.o
* cygwin.din: Add exports for sched*.
This commit is contained in:
Christopher Faylor 2001-03-21 02:17:58 +00:00
parent a1299ba54b
commit 9a08b2c02e
7 changed files with 1019 additions and 957 deletions

View File

@ -1,3 +1,10 @@
2001-03-21 Robert Collins <rbtcollins@hotmail.com>
* sched.cc: New file. Implement sched*.
* include/sched.h: New file. User land includes for sched*.
* Makefile.in: Add sched.o
* cygwin.din: Add exports for sched*.
Tue Mar 20 14:48:46 2001 Christopher Faylor <cgf@cygnus.com> Tue Mar 20 14:48:46 2001 Christopher Faylor <cgf@cygnus.com>
* dtable.cc: Guard against new winsock.h/winsock2.h warnings when * dtable.cc: Guard against new winsock.h/winsock2.h warnings when

View File

@ -121,13 +121,12 @@ DLL_OFILES:=assert.o autoload.o cygheap.o dcrt0.o debug.o delqueue.o dir.o \
fhandler_serial.o fhandler_socket.o fhandler_tape.o \ fhandler_serial.o fhandler_socket.o fhandler_tape.o \
fhandler_termios.o fhandler_tty.o fhandler_windows.o fhandler_zero.o \ fhandler_termios.o fhandler_tty.o fhandler_windows.o fhandler_zero.o \
fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o malloc.o \ fork.o glob.o grp.o heap.o init.o ioctl.o localtime.o malloc.o \
miscfuncs.o mmap.o \ miscfuncs.o mmap.o net.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o \
net.o ntea.o passwd.o path.o pinfo.o pipe.o poll.o pthread.o regexp.o \ pthread.o regexp.o regerror.o regsub.o registry.o resource.o scandir.o \
regerror.o regsub.o registry.o resource.o scandir.o security.o select.o \ sched.o security.o select.o shared.o shortcut.o signal.o sigproc.o \
shared.o \ smallprint.o spawn.o strace.o strsep.o sync.o syscalls.o sysconf.o \
shortcut.o signal.o sigproc.o smallprint.o spawn.o strace.o strsep.o \ syslog.o termios.o thread.o times.o tty.o uinfo.o uname.o wait.o \
sync.o syscalls.o sysconf.o syslog.o termios.o thread.o times.o tty.o \ window.o \
uinfo.o uname.o wait.o window.o \
$(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MT_SAFE_OBJECTS) $(EXTRA_DLL_OFILES) $(EXTRA_OFILES) $(MT_SAFE_OBJECTS)
GMON_OFILES:= gmon.o mcount.o profil.o GMON_OFILES:= gmon.o mcount.o profil.o

View File

@ -21,7 +21,6 @@ extern "C"
{ {
#endif #endif
#define TFD(n) void*(*n)(void*)
/* Defines. (These are correctly defined here as per /* Defines. (These are correctly defined here as per
http://www.opengroup.org/onlinepubs/7908799/xsh/pthread.h.html */ http://www.opengroup.org/onlinepubs/7908799/xsh/pthread.h.html */
@ -32,94 +31,85 @@ extern "C"
#define PTHREAD_PROCESS_PRIVATE 0 #define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED 1 #define PTHREAD_PROCESS_SHARED 1
#define PTHREAD_DESTRUCTOR_ITERATIONS 1
/* Tls has 64 items for pre win2000 - and we don't want to use them all :]
* Before committing discuss this with the list
*/
#define PTHREAD_KEYS_MAX 32
#define PTHREAD_CREATE_DETACHED 1
/* the default : joinable */
#define PTHREAD_CREATE_JOINABLE 0
typedef int pthread_t;
typedef int pthread_mutex_t;
typedef int sem_t;
typedef struct pthread_key /* these shouldn't be defined here but in sys/types.
{ * defining in sys/types mught also allow us to override them for the internal functions
} * more easily (internal sys/types vs external sys/type - dev thoughts on this?
pthread_key_t; */
typedef void *pthread_t;
typedef void *pthread_mutex_t;
typedef struct pthread_attr typedef void *pthread_key_t;
{ typedef void *pthread_attr_t;
size_t stacksize; typedef void *pthread_mutexattr_t;
} typedef void *pthread_condattr_t;
pthread_attr_t; typedef void *pthread_cond_t;
typedef struct pthread_mutexattr
{
}
pthread_mutexattr_t;
typedef struct pthread_condattr
{
int shared;
int valid;
}
pthread_condattr_t;
typedef int pthread_cond_t;
/* ThreadCreation */ /* ThreadCreation */
int pthread_create (pthread_t * thread, const pthread_attr_t * attr, TFD (function), void *arg); int pthread_create (pthread_t * thread, const pthread_attr_t * attr,
int pthread_attr_init (pthread_attr_t * attr); void *(*)(void *), void *arg);
int pthread_attr_destroy (pthread_attr_t * attr); int pthread_attr_init (pthread_attr_t * attr);
int pthread_attr_setstacksize (pthread_attr_t * attr, size_t size); int pthread_attr_destroy (pthread_attr_t * attr);
int pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size); int pthread_attr_setdetachstate (pthread_attr_t *, int);
int pthread_attr_getdetachstate (const pthread_attr_t *, int *);
int pthread_attr_setstacksize (pthread_attr_t * attr, size_t size);
int pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size);
/* Condition variables */ /* Condition variables */
int pthread_cond_broadcast(pthread_cond_t *); int pthread_cond_broadcast (pthread_cond_t *);
int pthread_cond_destroy(pthread_cond_t *); int pthread_cond_destroy (pthread_cond_t *);
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *); int pthread_cond_init (pthread_cond_t *, const pthread_condattr_t *);
int pthread_cond_signal(pthread_cond_t *); int pthread_cond_signal (pthread_cond_t *);
int pthread_cond_timedwait(pthread_cond_t *, int pthread_cond_timedwait (pthread_cond_t *,
pthread_mutex_t *, const struct timespec *); pthread_mutex_t *, const struct timespec *);
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *); int pthread_cond_wait (pthread_cond_t *, pthread_mutex_t *);
int pthread_condattr_destroy(pthread_condattr_t *); int pthread_condattr_destroy (pthread_condattr_t *);
int pthread_condattr_getpshared(const pthread_condattr_t *, int *); int pthread_condattr_getpshared (const pthread_condattr_t *, int *);
int pthread_condattr_init(pthread_condattr_t *); int pthread_condattr_init (pthread_condattr_t *);
int pthread_condattr_setpshared(pthread_condattr_t *, int); int pthread_condattr_setpshared (pthread_condattr_t *, int);
/* Thread Control */ /* Thread Control */
int pthread_detach (pthread_t thread); int pthread_detach (pthread_t thread);
int pthread_join (pthread_t thread, void **value_ptr); int pthread_join (pthread_t thread, void **value_ptr);
/* Thread Exit */ /* Thread Exit */
int pthread_exit (void *value_ptr); void pthread_exit (void *value_ptr);
/* Thread SpecificData */ /* Thread SpecificData */
int pthread_key_create (pthread_key_t * key); int pthread_key_create (pthread_key_t *, void (*)(void *));
int pthread_key_delete (pthread_key_t * key); int pthread_key_delete (pthread_key_t * key);
int pthread_setspecific (pthread_key_t * key, const void *value); int pthread_setspecific (pthread_key_t key, const void *value);
void *pthread_getspecific (pthread_key_t * key); void *pthread_getspecific (pthread_key_t key);
/* Thread signal */ /* Thread signal (should be in signal.h) */
int pthread_kill (pthread_t * thread, int sig); int pthread_kill (pthread_t * thread, int sig);
int pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set); int pthread_sigmask (int operation, const sigset_t * set,
sigset_t * old_set);
/* ID */ /* ID */
pthread_t pthread_self (); pthread_t pthread_self ();
int pthread_equal (pthread_t t1, pthread_t t2); int pthread_equal (pthread_t t1, pthread_t t2);
/* Mutexes */ /* Mutexes */
int pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t *); int pthread_mutex_init (pthread_mutex_t * mutex,
int pthread_mutex_lock (pthread_mutex_t * mutext); const pthread_mutexattr_t *);
int pthread_mutex_trylock (pthread_mutex_t * mutext); int pthread_mutex_lock (pthread_mutex_t * mutext);
int pthread_mutex_unlock (pthread_mutex_t * mutext); int pthread_mutex_trylock (pthread_mutex_t * mutext);
int pthread_mutex_destroy (pthread_mutex_t * mutext); int pthread_mutex_unlock (pthread_mutex_t * mutext);
int pthread_mutex_destroy (pthread_mutex_t * mutext);
/* Solaris Semaphores */
int sem_init (sem_t * sem, int pshared, unsigned int value);
int sem_destroy (sem_t * sem);
int sem_wait (sem_t * sem);
int sem_trywait (sem_t * sem);
int sem_post (sem_t * sem);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif /* _PTHREAD_H */ #endif /* _PTHREAD_H */

View File

@ -116,13 +116,13 @@ public:
return thread2signal ? thread2signal->win32_obj_id : hMainThread; return thread2signal ? thread2signal->win32_obj_id : hMainThread;
} }
inline void setthread2signal (void *thr) {thread2signal = (ThreadItem *) thr;} inline void setthread2signal (void *thr) {thread2signal = (pthread *) thr;}
private: private:
struct sigaction sigs[NSIG]; struct sigaction sigs[NSIG];
sigset_t sig_mask; /* one set for everything to ignore. */ sigset_t sig_mask; /* one set for everything to ignore. */
LONG _sigtodo[NSIG + __SIGOFFSET]; LONG _sigtodo[NSIG + __SIGOFFSET];
ThreadItem *thread2signal; // NULL means means thread any other means a pthread pthread *thread2signal; // NULL means means thread any other means a pthread
}; };
class pinfo class pinfo

View File

@ -13,37 +13,48 @@
#include "winsup.h" #include "winsup.h"
#include "thread.h" #include "thread.h"
extern "C" { extern "C"
{
/* ThreadCreation */ /* ThreadCreation */
int int
pthread_create (pthread_t * thread, const pthread_attr_t * attr, void *(*start_routine) (void *), void *arg) pthread_create (pthread_t * thread, const pthread_attr_t * attr,
{ void *(*start_routine) (void *), void *arg)
return __pthread_create (thread, attr, start_routine, arg); {
} return __pthread_create (thread, attr, start_routine, arg);
}
int int pthread_attr_init (pthread_attr_t * attr)
pthread_attr_init (pthread_attr_t * attr) {
{ return __pthread_attr_init (attr);
return __pthread_attr_init (attr); }
}
int int pthread_attr_destroy (pthread_attr_t * attr)
pthread_attr_destroy (pthread_attr_t * attr) {
{ return __pthread_attr_destroy (attr);
return __pthread_attr_destroy (attr); }
}
int int pthread_attr_setdetachstate (pthread_attr_t * attr, int detachstate)
pthread_attr_setstacksize (pthread_attr_t * attr, size_t size) {
{ return __pthread_attr_setdetachstate (attr, detachstate);
return __pthread_attr_setstacksize (attr, size); }
}
int int
pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size) pthread_attr_getdetachstate (const pthread_attr_t * attr,
{ int *detachstate)
return __pthread_attr_getstacksize (attr, size); {
} return __pthread_attr_getdetachstate (attr, detachstate);
}
int pthread_attr_setstacksize (pthread_attr_t * attr, size_t size)
{
return __pthread_attr_setstacksize (attr, size);
}
int pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size)
{
return __pthread_attr_getstacksize (attr, size);
}
/* /*
@ -52,216 +63,190 @@ pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size)
*/ */
/* Thread Exit */ /* Thread Exit */
int void pthread_exit (void *value_ptr)
pthread_exit (void * value_ptr) {
{ return __pthread_exit (value_ptr);
return __pthread_exit (value_ptr); }
}
int int pthread_join (pthread_t thread, void **return_val)
pthread_join (pthread_t thread, void **return_val) {
{ return __pthread_join (&thread, (void **) return_val);
return __pthread_join (&thread, (void **)return_val); }
}
int int pthread_detach (pthread_t thread)
pthread_detach (pthread_t thread) {
{ return __pthread_detach (&thread);
return __pthread_detach (&thread); }
}
int int pthread_suspend (pthread_t thread)
pthread_suspend (pthread_t thread) {
{ return __pthread_suspend (&thread);
return __pthread_suspend (&thread); }
}
int int pthread_continue (pthread_t thread)
pthread_continue (pthread_t thread) {
{ return __pthread_continue (&thread);
return __pthread_continue (&thread); }
}
unsigned long unsigned long pthread_getsequence_np (pthread_t * thread)
pthread_getsequence_np (pthread_t * thread) {
{ return __pthread_getsequence_np (thread);
return __pthread_getsequence_np (thread); }
}
/* Thread SpecificData */ /* Thread SpecificData */
int int pthread_key_create (pthread_key_t * key, void (*destructor) (void *))
pthread_key_create (pthread_key_t * key) {
{ return __pthread_key_create (key, destructor);
return __pthread_key_create (key); }
}
int int pthread_key_delete (pthread_key_t * key)
pthread_key_delete (pthread_key_t * key) {
{ return __pthread_key_delete (key);
return __pthread_key_delete (key); }
}
int int pthread_setspecific (pthread_key_t key, const void *value)
pthread_setspecific (pthread_key_t * key, const void *value) {
{ return __pthread_setspecific (key, value);
return __pthread_setspecific (key, value); }
}
void * void *pthread_getspecific (pthread_key_t key)
pthread_getspecific (pthread_key_t * key) {
{ return (void *) __pthread_getspecific (key);
return (void *) __pthread_getspecific (key); }
}
/* Thread signal */ /* Thread signal */
int int pthread_kill (pthread_t * thread, int sig)
pthread_kill (pthread_t * thread, int sig) {
{ return __pthread_kill (thread, sig);
return __pthread_kill (thread, sig); }
}
int int
pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set) pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set)
{ {
return __pthread_sigmask (operation, set, old_set); return __pthread_sigmask (operation, set, old_set);
} }
/* ID */ /* ID */
pthread_t pthread_t pthread_self ()
pthread_self () {
{ return __pthread_self ();
return __pthread_self (); }
}
int int pthread_equal (pthread_t t1, pthread_t t2)
pthread_equal (pthread_t t1, pthread_t t2) {
{ return __pthread_equal (&t1, &t2);
return __pthread_equal (&t1, &t2); }
}
/* Mutexes */ /* Mutexes */
int int
pthread_mutex_init (pthread_mutex_t * mutex, const pthread_mutexattr_t * attr) pthread_mutex_init (pthread_mutex_t * mutex,
{ const pthread_mutexattr_t * attr)
return __pthread_mutex_init (mutex, attr); {
} return __pthread_mutex_init (mutex, attr);
}
int int pthread_mutex_lock (pthread_mutex_t * mutex)
pthread_mutex_lock (pthread_mutex_t * mutex) {
{ return __pthread_mutex_lock (mutex);
return __pthread_mutex_lock (mutex); }
}
int int pthread_mutex_trylock (pthread_mutex_t * mutex)
pthread_mutex_trylock (pthread_mutex_t * mutex) {
{ return __pthread_mutex_trylock (mutex);
return __pthread_mutex_trylock (mutex); }
}
int int pthread_mutex_unlock (pthread_mutex_t * mutex)
pthread_mutex_unlock (pthread_mutex_t * mutex) {
{ return __pthread_mutex_unlock (mutex);
return __pthread_mutex_unlock (mutex); }
}
int int pthread_mutex_destroy (pthread_mutex_t * mutex)
pthread_mutex_destroy (pthread_mutex_t * mutex) {
{ return __pthread_mutex_destroy (mutex);
return __pthread_mutex_destroy (mutex); }
}
/* Synchronisation */ /* Synchronisation */
int int pthread_cond_destroy (pthread_cond_t * cond)
pthread_cond_destroy (pthread_cond_t *cond) {
{ return __pthread_cond_destroy (cond);
return __pthread_cond_destroy (cond); }
}
int int
pthread_cond_init (pthread_cond_t *cond, const pthread_condattr_t *attr) pthread_cond_init (pthread_cond_t * cond, const pthread_condattr_t * attr)
{ {
return __pthread_cond_init (cond, attr); return __pthread_cond_init (cond, attr);
} }
int int pthread_cond_signal (pthread_cond_t * cond)
pthread_cond_signal (pthread_cond_t *cond) {
{ return __pthread_cond_signal (cond);
return __pthread_cond_signal (cond); }
}
int int pthread_cond_broadcast (pthread_cond_t * cond)
pthread_cond_broadcast (pthread_cond_t *cond) {
{ return __pthread_cond_broadcast (cond);
return __pthread_cond_broadcast (cond); }
}
int int
pthread_cond_timedwait (pthread_cond_t *cond, pthread_cond_timedwait (pthread_cond_t * cond,
pthread_mutex_t *mutex, const struct timespec *abstime) pthread_mutex_t * mutex,
{ const struct timespec *abstime)
return __pthread_cond_timedwait (cond, mutex, abstime); {
} return __pthread_cond_timedwait (cond, mutex, abstime);
}
int int pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex)
pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex) {
{ return __pthread_cond_wait (cond, mutex);
return __pthread_cond_wait (cond, mutex); }
}
int int pthread_condattr_init (pthread_condattr_t * condattr)
pthread_condattr_init (pthread_condattr_t *condattr) {
{ return __pthread_condattr_init (condattr);
return __pthread_condattr_init (condattr); }
}
int int pthread_condattr_destroy (pthread_condattr_t * condattr)
pthread_condattr_destroy (pthread_condattr_t *condattr) {
{ return __pthread_condattr_destroy (condattr);
return __pthread_condattr_destroy (condattr); }
}
int int
pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared) pthread_condattr_getpshared (const pthread_condattr_t * attr,
{ int *pshared)
return __pthread_condattr_getpshared (attr, pshared); {
} return __pthread_condattr_getpshared (attr, pshared);
}
int int pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared)
pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared) {
{ return __pthread_condattr_setpshared (attr, pshared);
return __pthread_condattr_setpshared (attr, pshared); }
}
/* Semaphores */ /* Semaphores */
int int sem_init (sem_t * sem, int pshared, unsigned int value)
sem_init (sem_t * sem, int pshared, unsigned int value) {
{ return __sem_init (sem, pshared, value);
return __sem_init (sem, pshared, value); }
}
int int sem_destroy (sem_t * sem)
sem_destroy (sem_t * sem) {
{ return __sem_destroy (sem);
return __sem_destroy (sem); }
}
int int sem_wait (sem_t * sem)
sem_wait (sem_t * sem) {
{ return __sem_wait (sem);
return __sem_wait (sem); }
}
int int sem_trywait (sem_t * sem)
sem_trywait (sem_t * sem) {
{ return __sem_trywait (sem);
return __sem_trywait (sem); }
}
int int sem_post (sem_t * sem)
sem_post (sem_t * sem) {
{ return __sem_post (sem);
return __sem_post (sem); }
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,9 +1,11 @@
/* thread.h: Locking and threading module definitions /* thread.h: Locking and threading module definitions
Copyright 1998, 1999, 2000 Cygnus Solutions. Copyright 1998, 1999, 2000 Cygnus Solutions.
Copyright 2001 Red Hat, Inc.
Written by Marco Fuykschot <marco@ddi.nl> Written by Marco Fuykschot <marco@ddi.nl>
Major update 2001 Robert Collins <rbtcollins@hotmail.com>
This file is part of Cygwin. This file is part of Cygwin.
This software is a copyrighted work licensed under the terms of the This software is a copyrighted work licensed under the terms of the
@ -17,10 +19,6 @@ details. */
#define LOCK_MEMORY_LIST 2 #define LOCK_MEMORY_LIST 2
#define LOCK_MMAP_LIST 3 #define LOCK_MMAP_LIST 3
#define LOCK_DLL_LIST 4 #define LOCK_DLL_LIST 4
#define LOCK_THREAD_LIST 5
#define LOCK_MUTEX_LIST 6
#define LOCK_SEM_LIST 7
#define LOCK_COND_LIST 8
#define WRITE_LOCK 1 #define WRITE_LOCK 1
#define READ_LOCK 2 #define READ_LOCK 2
@ -41,80 +39,97 @@ extern "C"
#else #else
#include <pthread.h> //#include <pthread.h>
/* FIXME: these are defined in pthread.h, but pthread.h defines symbols it shouldn't -
* all the types.
*/
#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED 1
#define PTHREAD_DESTRUCTOR_ITERATIONS 1
/* Tls has 64 items for pre win2000 - and we don't want to use them all :]
* Before committing discuss this with the list
*/
#define PTHREAD_KEYS_MAX 32
#define PTHREAD_CREATE_DETACHED 1
/* the default : joinable */
#define PTHREAD_CREATE_JOINABLE 0
#include <signal.h>
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#define _NOMNTENT_FUNCS #define _NOMNTENT_FUNCS
#include <mntent.h> #include <mntent.h>
extern "C" { extern "C"
struct _winsup_t
{ {
struct _winsup_t
{
/* /*
Needed for the group functions Needed for the group functions
*/ */
struct group _grp; struct group _grp;
char *_namearray[2]; char *_namearray[2];
char _linebuf[100]; char _linebuf[100];
int _grp_pos; int _grp_pos;
/* console.cc */ /* console.cc */
unsigned _rarg; unsigned _rarg;
/* dlfcn.cc */ /* dlfcn.cc */
int _dl_error; int _dl_error;
char _dl_buffer[256]; char _dl_buffer[256];
/* passwd.cc */ /* passwd.cc */
struct passwd _res; struct passwd _res;
char _tmpbuf[100]; char _tmpbuf[100];
char _pass[_PASSWORD_LEN]; char _pass[_PASSWORD_LEN];
int _pw_pos; int _pw_pos;
/* path.cc */ /* path.cc */
struct mntent _ret; struct mntent _ret;
int _iteration; int _iteration;
/* strerror */ /* strerror */
char _strerror_buf[20]; char _strerror_buf[20];
/* syscalls.cc */ /* syscalls.cc */
char _dacl_buf[1024]; char _dacl_buf[1024];
char _sacl_buf[1024]; char _sacl_buf[1024];
char _ownr_buf[1024]; char _ownr_buf[1024];
char _grp_buf[1024]; char _grp_buf[1024];
/* sysloc.cc */ /* sysloc.cc */
char *_process_ident; char *_process_ident;
int _process_logopt; int _process_logopt;
int _process_facility; int _process_facility;
int _process_logmask; int _process_logmask;
/* times.cc */ /* times.cc */
char _b[20]; char _b[20];
struct tm _localtime_buf; struct tm _localtime_buf;
char _buf1[33]; char _buf1[33];
char _buf2[33]; char _buf2[33];
/* uinfo.cc */ /* uinfo.cc */
char _username[MAX_USER_NAME]; char _username[MAX_USER_NAME];
}; };
struct __reent_t struct __reent_t
{ {
struct _reent *_clib; struct _reent *_clib;
struct _winsup_t *_winsup; struct _winsup_t *_winsup;
}; };
_reent *_reent_clib (); _reent *_reent_clib ();
_winsup_t *_reent_winsup (); _winsup_t *_reent_winsup ();
void SetResourceLock (int, int, const char *) __attribute__ ((regparm(3))); void SetResourceLock (int, int, const char *) __attribute__ ((regparm (3)));
void ReleaseResourceLock (int, int, const char *) __attribute__ ((regparm(3))); void ReleaseResourceLock (int, int, const char *)
__attribute__ ((regparm (3)));
#ifdef _CYG_THREAD_FAILSAFE #ifdef _CYG_THREAD_FAILSAFE
void AssertResourceOwner (int, int); void AssertResourceOwner (int, int);
#else #else
#define AssertResourceOwner(i,ii) #define AssertResourceOwner(i,ii)
#endif #endif
@ -126,7 +141,9 @@ class pinfo;
class ResourceLocks class ResourceLocks
{ {
public: public:
ResourceLocks () {}; ResourceLocks ()
{
};
LPCRITICAL_SECTION Lock (int); LPCRITICAL_SECTION Lock (int);
void Init (); void Init ();
void Delete (); void Delete ();
@ -134,196 +151,255 @@ public:
DWORD owner; DWORD owner;
DWORD count; DWORD count;
#endif #endif
private: private:
CRITICAL_SECTION lock; CRITICAL_SECTION lock;
bool inited; bool inited;
}; };
#define PTHREAD_MAGIC 0xdf0df045
#define PTHREAD_MUTEX_MAGIC PTHREAD_MAGIC+1
#define PTHREAD_KEY_MAGIC PTHREAD_MAGIC+2
#define PTHREAD_ATTR_MAGIC PTHREAD_MAGIC+3
#define PTHREAD_MUTEXATTR_MAGIC PTHREAD_MAGIC+4
#define PTHREAD_COND_MAGIC PTHREAD_MAGIC+5
#define PTHREAD_CONDATTR_MAGIC PTHREAD_MAGIC+6
#define SEM_MAGIC PTHREAD_MAGIC+7
#define MT_MAX_ITEMS 128 class verifyable_object
// thread classes\lists
class MTitem
{
public:
HANDLE win32_obj_id;
UINT return_value;
bool used;
char joinable; // for thread only
bool HandleOke () {return win32_obj_id;}
virtual void Destroy ();
virtual int Id () {return (int) win32_obj_id;}
};
class ThreadItem: public MTitem
{ {
public: public:
pthread_attr_t attr; long magic;
TFD (function);
verifyable_object (long);
~verifyable_object ();
};
int verifyable_object_isvalid (verifyable_object *, long);
class pthread_attr:public verifyable_object
{
public:
int joinable;
size_t stacksize;
pthread_attr ();
~pthread_attr ();
};
class pthread:public verifyable_object
{
public:
HANDLE win32_obj_id;
class pthread_attr attr;
void *(*function) (void *);
void *arg; void *arg;
void *return_ptr; void *return_ptr;
bool suspended; bool suspended;
DWORD thread_id; int joinable;
DWORD GetThreadId () {return thread_id;} DWORD GetThreadId ()
{
return thread_id;
}
void setThreadIdtoCurrent ()
{
thread_id = GetCurrentThreadId ();
}
/* signal handling */ /* signal handling */
struct sigaction *sigs; struct sigaction *sigs;
sigset_t *sigmask; sigset_t *sigmask;
LONG *sigtodo; LONG *sigtodo;
void create (void *(*)(void *), pthread_attr *, void *);
pthread ();
~pthread ();
private:
DWORD thread_id;
}; };
class MutexItem: public MTitem class pthread_mutexattr:public verifyable_object
{ {
public: public:
pthread_mutexattr ();
~pthread_mutexattr ();
};
class pthread_mutex:public verifyable_object
{
public:
HANDLE win32_obj_id;
LONG condwaits;
int Lock (); int Lock ();
int TryLock (); int TryLock ();
int UnLock (); int UnLock ();
pthread_mutex (pthread_mutexattr *);
~pthread_mutex ();
}; };
class SemaphoreItem: public MTitem class pthread_key:public verifyable_object
{
public:
DWORD dwTlsIndex;
int set (const void *);
void *get ();
pthread_key ();
~pthread_key ();
};
class pthread_condattr:public verifyable_object
{ {
public: public:
int shared; int shared;
int Wait ();
int Post (); pthread_condattr ();
int TryWait (); ~pthread_condattr ();
}; };
class CondItem: public MTitem class pthread_cond:public verifyable_object
{ {
public: public:
int shared; int shared;
LONG waiting; LONG waiting;
MutexItem *mutexitem; pthread_mutex *mutex;
int Wait (); HANDLE win32_obj_id;
int TimedWait (DWORD dwMilliseconds); int TimedWait (DWORD dwMilliseconds);
int BroadCast (); void BroadCast ();
int Signal (); void Signal ();
pthread_cond (pthread_condattr *);
~pthread_cond ();
}; };
typedef struct /* shouldn't be here */
class semaphore:public verifyable_object
{ {
MTitem *items[MT_MAX_ITEMS]; public:
int index; HANDLE win32_obj_id;
} MTList; int shared;
void Wait ();
void Post ();
int TryWait ();
semaphore (int, unsigned int);
~semaphore ();
};
typedef class pthread *pthread_t;
typedef class pthread_mutex *pthread_mutex_t;
/* sem routines belong in semaphore.cc */
typedef class semaphore *sem_t;
typedef class pthread_key *pthread_key_t;
typedef class pthread_attr *pthread_attr_t;
typedef class pthread_mutexattr *pthread_mutexattr_t;
typedef class pthread_condattr *pthread_condattr_t;
typedef class pthread_cond *pthread_cond_t;
class MTinterface class MTinterface
{ {
public: public:
// General // General
DWORD reent_index; DWORD reent_index;
DWORD thread_key; DWORD thread_self_dwTlsIndex;
/* we may get 0 for the Tls index.. grrr */
int indexallocated;
// Used for main thread data, and sigproc thread // Used for main thread data, and sigproc thread
struct __reent_t reents; struct __reent_t reents;
struct _winsup_t winsup_reent; struct _winsup_t winsup_reent;
ThreadItem mainthread; pthread mainthread;
void Init (int); void Init (int);
void ReleaseItem (MTitem *); MTinterface ():reent_index (0), indexallocated (0)
{
// Thread functions }
ThreadItem *CreateThread (pthread_t *, TFD (func), void *, pthread_attr_t);
ThreadItem *GetCallingThread ();
ThreadItem *GetThread (pthread_t *);
// Mutex functions
MutexItem *CreateMutex (pthread_mutex_t *);
MutexItem *GetMutex (pthread_mutex_t *);
// Semaphore functions
SemaphoreItem *CreateSemaphore (sem_t *, int, int);
SemaphoreItem *GetSemaphore (sem_t * t);
// Condition functions
CondItem *CreateCond (pthread_cond_t *, const pthread_condattr_t *);
CondItem *GetCond (pthread_cond_t *);
private:
// General Administration
MTitem * Find (void *, int (*compare) (void *, void *), int &, MTList *);
MTitem *GetItem (int, MTList *);
MTitem *SetItem (int, MTitem *, MTList *);
int Find (MTitem &, MTList *);
int FindNextUnused (MTList *);
MTList threadlist;
MTList mutexlist;
MTList semalist;
MTList condlist;
}; };
extern "C" extern "C"
{ {
void *thread_init_wrapper (void *); void *thread_init_wrapper (void *);
/* ThreadCreation */ /* ThreadCreation */
int __pthread_create (pthread_t * thread, const pthread_attr_t * attr, TFD (start_routine), void *arg); int __pthread_create (pthread_t * thread, const pthread_attr_t * attr,
int __pthread_attr_init (pthread_attr_t * attr); void *(*start_routine) (void *), void *arg);
int __pthread_attr_destroy (pthread_attr_t * attr); int __pthread_attr_init (pthread_attr_t * attr);
int __pthread_attr_setstacksize (pthread_attr_t * attr, size_t size); int __pthread_attr_destroy (pthread_attr_t * attr);
int __pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size); int __pthread_attr_setdetachstate (pthread_attr_t *, int);
int __pthread_attr_getdetachstate (const pthread_attr_t *, int *);
int __pthread_attr_setstacksize (pthread_attr_t * attr, size_t size);
int __pthread_attr_getstacksize (pthread_attr_t * attr, size_t * size);
/* /*
__pthread_attr_setstackaddr(...); __pthread_attr_setstackaddr(...);
__pthread_attr_getstackaddr(...); __pthread_attr_getstackaddr(...);
*/ */
/* Thread Exit */ /* Thread Exit */
int __pthread_exit (void *value_ptr); void __pthread_exit (void *value_ptr);
int __pthread_join(pthread_t *thread, void **return_val); int __pthread_join (pthread_t * thread, void **return_val);
int __pthread_detach(pthread_t *thread); int __pthread_detach (pthread_t * thread);
/* Thread suspend */ /* Thread suspend */
int __pthread_suspend(pthread_t *thread); int __pthread_suspend (pthread_t * thread);
int __pthread_continue(pthread_t *thread); int __pthread_continue (pthread_t * thread);
unsigned long __pthread_getsequence_np (pthread_t * thread); unsigned long __pthread_getsequence_np (pthread_t * thread);
/* Thread SpecificData */ /* Thread SpecificData */
int __pthread_key_create (pthread_key_t * key); int __pthread_key_create (pthread_key_t * key, void (*destructor) (void *));
int __pthread_key_delete (pthread_key_t * key); int __pthread_key_delete (pthread_key_t * key);
int __pthread_setspecific (pthread_key_t * key, const void *value); int __pthread_setspecific (pthread_key_t key, const void *value);
void *__pthread_getspecific (pthread_key_t * key); void *__pthread_getspecific (pthread_key_t key);
/* Thead synchroniation */ /* Thead synchroniation */
int __pthread_cond_destroy(pthread_cond_t *cond); int __pthread_cond_destroy (pthread_cond_t * cond);
int __pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr); int __pthread_cond_init (pthread_cond_t * cond,
int __pthread_cond_signal(pthread_cond_t *cond); const pthread_condattr_t * attr);
int __pthread_cond_broadcast(pthread_cond_t *cond); int __pthread_cond_signal (pthread_cond_t * cond);
int __pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, const struct timespec *abstime); int __pthread_cond_broadcast (pthread_cond_t * cond);
int __pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); int __pthread_cond_timedwait (pthread_cond_t * cond,
int __pthread_condattr_init (pthread_condattr_t * condattr); pthread_mutex_t * mutex,
int __pthread_condattr_destroy (pthread_condattr_t * condattr); const struct timespec *abstime);
int __pthread_condattr_getpshared (const pthread_condattr_t *attr, int *pshared); int __pthread_cond_wait (pthread_cond_t * cond, pthread_mutex_t * mutex);
int __pthread_condattr_setpshared (pthread_condattr_t *attr, int pshared); int __pthread_condattr_init (pthread_condattr_t * condattr);
int __pthread_condattr_destroy (pthread_condattr_t * condattr);
int __pthread_condattr_getpshared (const pthread_condattr_t * attr,
int *pshared);
int __pthread_condattr_setpshared (pthread_condattr_t * attr, int pshared);
/* Thread signal */ /* Thread signal */
int __pthread_kill (pthread_t * thread, int sig); int __pthread_kill (pthread_t * thread, int sig);
int __pthread_sigmask (int operation, const sigset_t * set, sigset_t * old_set); int __pthread_sigmask (int operation, const sigset_t * set,
sigset_t * old_set);
/* ID */ /* ID */
pthread_t __pthread_self (); pthread_t __pthread_self ();
int __pthread_equal (pthread_t * t1, pthread_t * t2); int __pthread_equal (pthread_t * t1, pthread_t * t2);
/* Mutexes */ /* Mutexes */
int __pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *); int __pthread_mutex_init (pthread_mutex_t *, const pthread_mutexattr_t *);
int __pthread_mutex_lock (pthread_mutex_t *); int __pthread_mutex_lock (pthread_mutex_t *);
int __pthread_mutex_trylock (pthread_mutex_t *); int __pthread_mutex_trylock (pthread_mutex_t *);
int __pthread_mutex_unlock (pthread_mutex_t *); int __pthread_mutex_unlock (pthread_mutex_t *);
int __pthread_mutex_destroy (pthread_mutex_t *); int __pthread_mutex_destroy (pthread_mutex_t *);
/* Semaphores */ /* Semaphores */
int __sem_init (sem_t * sem, int pshared, unsigned int value); int __sem_init (sem_t * sem, int pshared, unsigned int value);
int __sem_destroy (sem_t * sem); int __sem_destroy (sem_t * sem);
int __sem_wait (sem_t * sem); int __sem_wait (sem_t * sem);
int __sem_trywait (sem_t * sem); int __sem_trywait (sem_t * sem);
int __sem_post (sem_t * sem); int __sem_post (sem_t * sem);
}; };