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