2002-08-02 00:20:31 +08:00
|
|
|
/* cygthread.h
|
|
|
|
|
2013-01-21 12:34:52 +08:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010, 2011 Red
|
|
|
|
Hat, Inc.
|
2002-08-02 00:20:31 +08:00
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2004-11-26 12:15:10 +08:00
|
|
|
#ifndef _CYGTHREAD_H
|
|
|
|
#define _CYGTHREAD_H
|
|
|
|
|
2010-07-31 02:04:22 +08:00
|
|
|
typedef void WINAPI (*LPVOID_THREAD_START_ROUTINE) (void *) __attribute__((noreturn)); // Input queue thread
|
|
|
|
|
2002-08-02 00:20:31 +08:00
|
|
|
class cygthread
|
|
|
|
{
|
2003-04-10 13:27:34 +08:00
|
|
|
LONG inuse;
|
2002-08-02 00:20:31 +08:00
|
|
|
DWORD id;
|
|
|
|
HANDLE h;
|
|
|
|
HANDLE ev;
|
2002-10-14 02:16:33 +08:00
|
|
|
HANDLE thread_sync;
|
2002-12-11 12:00:04 +08:00
|
|
|
void *stack_ptr;
|
2002-08-02 00:20:31 +08:00
|
|
|
const char *__name;
|
2004-12-23 02:12:30 +08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
const char *__oldname;
|
|
|
|
bool terminated;
|
|
|
|
#endif
|
2002-08-02 00:20:31 +08:00
|
|
|
LPTHREAD_START_ROUTINE func;
|
2005-10-18 07:27:00 +08:00
|
|
|
unsigned arglen;
|
2002-08-02 00:20:31 +08:00
|
|
|
VOID *arg;
|
2002-08-29 11:33:50 +08:00
|
|
|
bool is_freerange;
|
2002-10-23 04:16:31 +08:00
|
|
|
static bool exiting;
|
* wininfo.h (wininfo::timer_active): Delete.
(wininfo::itv): Ditto.
(wininfo::start_time): Ditto.
(wininfo::window_started): Ditto.
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(wininfo::wininfo): Ditto.
(wininfo::lock): New method.
(wininfo::release): Ditto.
* window.cc: Use new lock/acquire wininfo methods throughout.
(wininfo::wininfo): Delete
(wininfo::getitimer): Ditto.
(wininfo::setitimer): Ditto.
(getitimer): Ditto.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
(wininfo::lock): Define new function.
(wininfo::release): Ditto.
(wininfo::process): Delete WM_TIMER handling.
* timer.cc (struct timetracker): Delete it, flags. Add it_interval,
interval_us, sleepto_us, running, init_muto(), syncthread, and gettime().
(ttstart): Make NO_COPY.
(lock_timer_tracker): New class.
(timer_tracker::timer_tracker): Distinguish ttstart case.
(timer_tracker::~timer_tracker): New destructor. Clean out events, and reset
magic.
(timer_tracker::init_muto): New method.
(to_us): Round up as per POSIX.
(timer_thread): Reorganize to match timer_tracker::settime and
timer_tracker::gettime. Call sig_send without wait. Call auto_release.
(timer_tracker::settime): Reorganize logic to avoid race. Call gettime to
recover old value.
(timer_tracker::gettime): New method.
(timer_create): Properly set errno on invalid timerid. Use new
lock_timer_tracker method.
(timer_delete): Ditto. Simplify code slightly.
(timer_gettime): New function.
(fixup_timers_after_fork): Reinit ttstart.
(getitimer): New implementation.
(setitimer): Ditto.
(ualarm): Ditto.
(alarm): Ditto.
* cygwin.din: Export timer_gettime.
* winsup.h: Remove has has_visible_window_station declaration.
* Makefile.in (DLL_OFILES): Add lsearch.o.
* cygthread.h (cygthread::notify_detached): New element.
(cygthread::cygthread): Take optional fourth argument signifying event to
signal on thread completion.
* cygthread.cc (cygthread::stub): Signal notify_detached event, if it exists.
(cygthread::cygthread): Initialize notify_detached from fourth argument.
(cygthread::detach): Wait for notify_detached field is present.
* lsearch.cc: New file.
* search.h: Ditto.
* include/cygwin/version.h: Bump API minor number to 126.
* cygwin.din: Export lsearch, lfind.
2005-03-27 09:57:38 +08:00
|
|
|
HANDLE notify_detached;
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg1 create ();
|
2011-07-31 04:50:23 +08:00
|
|
|
static void CALLBACK async_create (ULONG_PTR);
|
2002-08-02 00:20:31 +08:00
|
|
|
public:
|
2005-02-06 13:04:34 +08:00
|
|
|
bool terminate_thread ();
|
2003-12-14 15:09:22 +08:00
|
|
|
static DWORD WINAPI stub (VOID *);
|
2004-01-14 23:45:37 +08:00
|
|
|
static DWORD WINAPI simplestub (VOID *);
|
2003-08-28 10:04:16 +08:00
|
|
|
static DWORD main_thread_id;
|
2011-12-13 12:11:48 +08:00
|
|
|
static const char *name (DWORD = 0);
|
2013-01-21 12:34:52 +08:00
|
|
|
void __reg2 callfunc (bool) __attribute__ ((noinline, ));
|
2004-12-23 22:57:08 +08:00
|
|
|
void auto_release () {func = NULL;}
|
2004-12-23 02:12:30 +08:00
|
|
|
void release (bool);
|
2010-07-31 02:04:22 +08:00
|
|
|
cygthread (LPTHREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL)
|
2010-09-12 23:49:30 +08:00
|
|
|
: __name (name), func (start), arglen (n), arg (param),
|
2011-07-31 04:50:23 +08:00
|
|
|
notify_detached (notify)
|
2010-09-02 02:24:11 +08:00
|
|
|
{
|
|
|
|
create ();
|
|
|
|
}
|
2011-07-31 04:50:23 +08:00
|
|
|
cygthread (LPVOID_THREAD_START_ROUTINE start, LPVOID param, const char *name)
|
2010-09-02 02:24:11 +08:00
|
|
|
: __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (0),
|
2011-07-31 04:50:23 +08:00
|
|
|
arg (param), notify_detached (NULL)
|
2010-09-02 02:24:11 +08:00
|
|
|
{
|
2011-07-31 04:50:23 +08:00
|
|
|
QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
|
2010-09-02 02:24:11 +08:00
|
|
|
}
|
|
|
|
cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL)
|
2010-09-12 23:49:30 +08:00
|
|
|
: __name (name), func (start), arglen (0), arg (param),
|
2011-07-31 04:50:23 +08:00
|
|
|
notify_detached (notify)
|
2010-07-31 02:04:22 +08:00
|
|
|
{
|
|
|
|
create ();
|
|
|
|
}
|
2011-07-31 04:50:23 +08:00
|
|
|
cygthread (LPVOID_THREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name)
|
2010-07-31 02:04:22 +08:00
|
|
|
: __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (n),
|
2011-07-31 04:50:23 +08:00
|
|
|
arg (param), notify_detached (NULL)
|
2010-07-31 02:04:22 +08:00
|
|
|
{
|
2011-07-31 04:50:23 +08:00
|
|
|
QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
|
2010-07-31 02:04:22 +08:00
|
|
|
}
|
2002-08-02 00:20:31 +08:00
|
|
|
cygthread () {};
|
|
|
|
static void init ();
|
2002-12-14 12:01:32 +08:00
|
|
|
bool detach (HANDLE = NULL);
|
2002-08-02 00:20:31 +08:00
|
|
|
operator HANDLE ();
|
|
|
|
void * operator new (size_t);
|
2002-10-23 04:16:31 +08:00
|
|
|
static cygthread *freerange ();
|
2002-09-29 10:19:35 +08:00
|
|
|
static void terminate ();
|
2010-09-20 04:18:36 +08:00
|
|
|
HANDLE thread_handle () const {return h;}
|
2002-10-09 13:55:40 +08:00
|
|
|
bool SetThreadPriority (int nPriority) {return ::SetThreadPriority (h, nPriority);}
|
|
|
|
void zap_h ()
|
|
|
|
{
|
2005-07-07 04:05:03 +08:00
|
|
|
CloseHandle (h);
|
2002-10-09 13:55:40 +08:00
|
|
|
h = NULL;
|
|
|
|
}
|
2002-08-02 00:20:31 +08:00
|
|
|
};
|
2002-08-06 13:08:55 +08:00
|
|
|
|
|
|
|
#define cygself NULL
|
2004-11-26 12:15:10 +08:00
|
|
|
#endif /*_CYGTHREAD_H*/
|