2002-08-01 09:20:31 -07:00
|
|
|
/* cygthread.h
|
|
|
|
|
2011-10-20 03:59:01 -07:00
|
|
|
Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2010,
|
|
|
|
2011 Red Hat, Inc.
|
2002-08-01 09:20:31 -07: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-25 20:15:10 -08:00
|
|
|
#ifndef _CYGTHREAD_H
|
|
|
|
#define _CYGTHREAD_H
|
|
|
|
|
2010-07-30 11:04:22 -07:00
|
|
|
typedef void WINAPI (*LPVOID_THREAD_START_ROUTINE) (void *) __attribute__((noreturn)); // Input queue thread
|
|
|
|
|
2002-08-01 09:20:31 -07:00
|
|
|
class cygthread
|
|
|
|
{
|
2003-04-09 22:27:34 -07:00
|
|
|
LONG inuse;
|
2002-08-01 09:20:31 -07:00
|
|
|
DWORD id;
|
|
|
|
HANDLE h;
|
|
|
|
HANDLE ev;
|
2002-10-13 11:16:33 -07:00
|
|
|
HANDLE thread_sync;
|
2002-12-10 20:00:04 -08:00
|
|
|
void *stack_ptr;
|
2002-08-01 09:20:31 -07:00
|
|
|
const char *__name;
|
2004-12-22 10:12:30 -08:00
|
|
|
#ifdef DEBUGGING
|
|
|
|
const char *__oldname;
|
|
|
|
bool terminated;
|
|
|
|
#endif
|
2002-08-01 09:20:31 -07:00
|
|
|
LPTHREAD_START_ROUTINE func;
|
2005-10-17 16:27:00 -07:00
|
|
|
unsigned arglen;
|
2002-08-01 09:20:31 -07:00
|
|
|
VOID *arg;
|
2002-08-28 20:33:50 -07:00
|
|
|
bool is_freerange;
|
2002-10-22 13:16:31 -07: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-26 17:57:38 -08:00
|
|
|
HANDLE notify_detached;
|
2011-07-30 13:50:23 -07:00
|
|
|
void create () __attribute__ ((regparm (1)));
|
|
|
|
static void CALLBACK async_create (ULONG_PTR);
|
2002-08-01 09:20:31 -07:00
|
|
|
public:
|
2005-02-05 21:04:34 -08:00
|
|
|
bool terminate_thread ();
|
2003-12-13 23:09:22 -08:00
|
|
|
static DWORD WINAPI stub (VOID *);
|
2004-01-14 07:45:37 -08:00
|
|
|
static DWORD WINAPI simplestub (VOID *);
|
2003-08-27 19:04:16 -07:00
|
|
|
static DWORD main_thread_id;
|
2011-12-12 20:11:48 -08:00
|
|
|
static const char *name (DWORD = 0);
|
2005-10-17 16:27:00 -07:00
|
|
|
void callfunc (bool) __attribute__ ((noinline, regparm (2)));
|
2004-12-23 06:57:08 -08:00
|
|
|
void auto_release () {func = NULL;}
|
2004-12-22 10:12:30 -08:00
|
|
|
void release (bool);
|
2010-07-30 11:04:22 -07:00
|
|
|
cygthread (LPTHREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name, HANDLE notify = NULL)
|
2010-09-12 08:49:30 -07:00
|
|
|
: __name (name), func (start), arglen (n), arg (param),
|
2011-07-30 13:50:23 -07:00
|
|
|
notify_detached (notify)
|
2010-09-01 11:24:11 -07:00
|
|
|
{
|
|
|
|
create ();
|
|
|
|
}
|
2011-07-30 13:50:23 -07:00
|
|
|
cygthread (LPVOID_THREAD_START_ROUTINE start, LPVOID param, const char *name)
|
2010-09-01 11:24:11 -07:00
|
|
|
: __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (0),
|
2011-07-30 13:50:23 -07:00
|
|
|
arg (param), notify_detached (NULL)
|
2010-09-01 11:24:11 -07:00
|
|
|
{
|
2011-07-30 13:50:23 -07:00
|
|
|
QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
|
2010-09-01 11:24:11 -07:00
|
|
|
}
|
|
|
|
cygthread (LPTHREAD_START_ROUTINE start, LPVOID param, const char *name, HANDLE notify = NULL)
|
2010-09-12 08:49:30 -07:00
|
|
|
: __name (name), func (start), arglen (0), arg (param),
|
2011-07-30 13:50:23 -07:00
|
|
|
notify_detached (notify)
|
2010-07-30 11:04:22 -07:00
|
|
|
{
|
|
|
|
create ();
|
|
|
|
}
|
2011-07-30 13:50:23 -07:00
|
|
|
cygthread (LPVOID_THREAD_START_ROUTINE start, unsigned n, LPVOID param, const char *name)
|
2010-07-30 11:04:22 -07:00
|
|
|
: __name (name), func ((LPTHREAD_START_ROUTINE) start), arglen (n),
|
2011-07-30 13:50:23 -07:00
|
|
|
arg (param), notify_detached (NULL)
|
2010-07-30 11:04:22 -07:00
|
|
|
{
|
2011-07-30 13:50:23 -07:00
|
|
|
QueueUserAPC (async_create, GetCurrentThread (), (ULONG_PTR) this);
|
2010-07-30 11:04:22 -07:00
|
|
|
}
|
2002-08-01 09:20:31 -07:00
|
|
|
cygthread () {};
|
|
|
|
static void init ();
|
2002-12-13 20:01:32 -08:00
|
|
|
bool detach (HANDLE = NULL);
|
2002-08-01 09:20:31 -07:00
|
|
|
operator HANDLE ();
|
|
|
|
void * operator new (size_t);
|
2002-10-22 13:16:31 -07:00
|
|
|
static cygthread *freerange ();
|
2002-09-28 19:19:35 -07:00
|
|
|
static void terminate ();
|
2010-09-19 13:18:36 -07:00
|
|
|
HANDLE thread_handle () const {return h;}
|
2002-10-08 22:55:40 -07:00
|
|
|
bool SetThreadPriority (int nPriority) {return ::SetThreadPriority (h, nPriority);}
|
|
|
|
void zap_h ()
|
|
|
|
{
|
2005-07-06 13:05:03 -07:00
|
|
|
CloseHandle (h);
|
2002-10-08 22:55:40 -07:00
|
|
|
h = NULL;
|
|
|
|
}
|
2002-08-01 09:20:31 -07:00
|
|
|
};
|
2002-08-05 22:08:55 -07:00
|
|
|
|
|
|
|
#define cygself NULL
|
2004-11-25 20:15:10 -08:00
|
|
|
#endif /*_CYGTHREAD_H*/
|