OSDN Git Service

2012-01-06 Chris Sutcliffe <ir0nh34d@users.sf.net>
[pf3gnuchains/pf3gnuchains4x.git] / winsup / cygwin / cygthread.h
1 /* cygthread.h
2
3    Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010,
4    2011 Red Hat, Inc.
5
6 This software is a copyrighted work licensed under the terms of the
7 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
8 details. */
9
10 #ifndef _CYGTHREAD_H
11 #define _CYGTHREAD_H
12
13 typedef void WINAPI (*LPVOID_THREAD_START_ROUTINE) (void *) __attribute__((noreturn));          // Input queue thread
14
15 class cygthread
16 {
17   LONG inuse;
18   DWORD id;
19   HANDLE h;
20   HANDLE ev;
21   HANDLE thread_sync;
22   void *stack_ptr;
23   const char *__name;
24 #ifdef DEBUGGING
25   const char *__oldname;
26   bool terminated;
27 #endif
28   LPTHREAD_START_ROUTINE func;
29   unsigned arglen;
30   VOID *arg;
31   bool is_freerange;
32   static bool exiting;
33   HANDLE notify_detached;
34   void create () __attribute__ ((regparm (1)));
35   static void CALLBACK async_create (ULONG_PTR);
36  public:
37   bool terminate_thread ();
38   static DWORD WINAPI stub (VOID *);
39   static DWORD WINAPI simplestub (VOID *);
40   static DWORD main_thread_id;
41   static const char *name (DWORD = 0);
42   void callfunc (bool) __attribute__ ((noinline, regparm (2)));
43   void auto_release () {func = NULL;}
44   void release (bool);
45   cygthread (LPTHREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL)
46   : __name (name), func (start), arglen (n), arg (param),
47   notify_detached (notify)
48   {
49     create ();
50   }
51   cygthread (LPVOID_THREAD_START_ROUTINE start, LPVOID param, const char *name)
52   : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (0),
53     arg (param), notify_detached (NULL)
54   {
55     QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
56   }
57   cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL)
58   : __name (name), func (start), arglen (0), arg (param),
59   notify_detached (notify)
60   {
61     create ();
62   }
63   cygthread (LPVOID_THREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name)
64   : __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (n),
65     arg (param), notify_detached (NULL)
66   {
67     QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
68   }
69   cygthread () {};
70   static void init ();
71   bool detach (HANDLE = NULL);
72   operator HANDLE ();
73   void * operator new (size_t);
74   static cygthread *freerange ();
75   static void terminate ();
76   HANDLE thread_handle () const {return h;}
77   bool SetThreadPriority (int nPriority) {return ::SetThreadPriority (h, nPriority);}
78   void zap_h ()
79   {
80     CloseHandle (h);
81     h = NULL;
82   }
83 };
84
85 #define cygself NULL
86 #endif /*_CYGTHREAD_H*/