Cygwin: (mostly) drop NT4 and Samba < 3.0 support
[newlib-cygwin.git] / winsup / cygwin / local_includes / cygthread.h
blob241180f2b59eefb39bea4381dba461ba462b042a
1 /* cygthread.h
3 This software is a copyrighted work licensed under the terms of the
4 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
5 details. */
7 #ifndef _CYGTHREAD_H
8 #define _CYGTHREAD_H
10 typedef void (*LPVOID_THREAD_START_ROUTINE) (void *) __attribute__((noreturn)); // Input queue thread
12 class cygthread
14 LONG inuse;
15 DWORD id;
16 HANDLE h;
17 HANDLE ev;
18 HANDLE thread_sync;
19 void *stack_ptr;
20 const char *__name;
21 #ifdef DEBUGGING
22 const char *__oldname;
23 bool terminated;
24 #endif
25 LPTHREAD_START_ROUTINE func;
26 unsigned arglen;
27 VOID *arg;
28 bool is_freerange;
29 static bool exiting;
30 HANDLE notify_detached;
31 void create ();
32 static void CALLBACK async_create (ULONG_PTR);
33 public:
34 bool terminate_thread ();
35 static DWORD stub (VOID *);
36 static DWORD simplestub (VOID *);
37 static DWORD main_thread_id;
38 static const char *name (DWORD = 0);
39 void callfunc (bool) __attribute__ ((noinline, ));
40 void auto_release () {func = NULL;}
41 void release (bool);
42 cygthread (LPTHREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL)
43 : __name (name), func (start), arglen (n), arg (param),
44 notify_detached (notify)
46 create ();
48 cygthread (LPVOID_THREAD_START_ROUTINE start, LPVOID param, const char *name)
49 : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (0),
50 arg (param), notify_detached (NULL)
52 QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
54 cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL)
55 : __name (name), func (start), arglen (0), arg (param),
56 notify_detached (notify)
58 create ();
60 cygthread (LPVOID_THREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name)
61 : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (n),
62 arg (param), notify_detached (NULL)
64 QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
66 cygthread () {};
67 static void init ();
68 bool detach (HANDLE = NULL);
69 operator HANDLE ();
70 void * operator new (size_t);
71 static cygthread *freerange ();
72 static void terminate ();
73 HANDLE thread_handle () const {return h;}
74 bool SetThreadPriority (int nPriority) {return ::SetThreadPriority (h, nPriority);}
75 void zap_h ()
77 CloseHandle (h);
78 h = NULL;
82 #define cygself NULL
83 #endif /*_CYGTHREAD_H*/