2000-02-18 03:38:33 +08:00
|
|
|
/* window.cc: hidden windows for signals/itimer support
|
|
|
|
|
2013-01-21 12:38:31 +08:00
|
|
|
Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2010, 2011
|
|
|
|
Red Hat, Inc.
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
Written by Sergey Okhapkin <sos@prospect.com.ru>
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2000-08-03 00:28:18 +08:00
|
|
|
#include "winsup.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
#include <sys/time.h>
|
2000-07-28 01:30:51 +08:00
|
|
|
#include <wingdi.h>
|
|
|
|
#include <winuser.h>
|
2002-01-06 17:28:13 +08:00
|
|
|
#define USE_SYS_TYPES_FD_SET
|
|
|
|
#include <winsock2.h>
|
2000-09-08 10:56:55 +08:00
|
|
|
#include "perprocess.h"
|
2004-05-16 12:18:50 +08:00
|
|
|
#include "cygtls.h"
|
|
|
|
#include "sync.h"
|
|
|
|
#include "wininfo.h"
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-05-16 12:18:50 +08:00
|
|
|
wininfo NO_COPY winmsg;
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-04-05 12:31:00 +08:00
|
|
|
muto NO_COPY wininfo::_lock;
|
2004-05-16 12:18:50 +08:00
|
|
|
|
2013-05-01 09:20:37 +08:00
|
|
|
int __reg3
|
2004-05-16 12:18:50 +08:00
|
|
|
wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
#ifndef NOSTRACE
|
2000-03-07 13:33:09 +08:00
|
|
|
strace.wm (uMsg, wParam, lParam);
|
2000-02-18 03:38:33 +08:00
|
|
|
#endif
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case WM_PAINT:
|
|
|
|
return 0;
|
|
|
|
case WM_DESTROY:
|
|
|
|
PostQuitMessage (0);
|
|
|
|
return 0;
|
|
|
|
case WM_ASYNCIO:
|
2002-09-23 08:31:31 +08:00
|
|
|
if (WSAGETSELECTEVENT (lParam) == FD_OOB)
|
2002-05-28 09:55:40 +08:00
|
|
|
raise (SIGURG);
|
2002-01-06 17:28:13 +08:00
|
|
|
else
|
|
|
|
raise (SIGIO);
|
2000-02-18 03:38:33 +08:00
|
|
|
return 0;
|
|
|
|
default:
|
2011-05-01 22:35:12 +08:00
|
|
|
return DefWindowProcW (hwnd, uMsg, wParam, lParam);
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-16 12:18:50 +08:00
|
|
|
static LRESULT CALLBACK
|
|
|
|
process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
return winmsg.process (hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2004-05-16 12:18:50 +08:00
|
|
|
/* Handle windows events. Inherits ownership of the wininfo lock */
|
2013-05-01 09:20:37 +08:00
|
|
|
DWORD __reg1 WINAPI
|
2004-05-16 12:18:50 +08:00
|
|
|
wininfo::winthread ()
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
|
|
|
MSG msg;
|
2011-05-01 22:35:12 +08:00
|
|
|
WNDCLASSW wc;
|
|
|
|
static NO_COPY WCHAR classname[] = L"CygwinWndClass";
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2005-04-05 12:31:00 +08:00
|
|
|
_lock.grab ();
|
2000-02-18 03:38:33 +08:00
|
|
|
/* Register the window class for the main window. */
|
|
|
|
|
|
|
|
wc.style = 0;
|
2004-05-16 12:18:50 +08:00
|
|
|
wc.lpfnWndProc = (WNDPROC) process_window_events;
|
2000-02-18 03:38:33 +08:00
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = user_data->hmodule;
|
|
|
|
wc.hIcon = NULL;
|
|
|
|
wc.hCursor = NULL;
|
|
|
|
wc.hbrBackground = NULL;
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = classname;
|
|
|
|
|
2011-05-01 22:35:12 +08:00
|
|
|
if (!RegisterClassW (&wc))
|
2004-05-16 12:18:50 +08:00
|
|
|
api_fatal ("cannot register window class, %E");
|
2000-02-18 03:38:33 +08:00
|
|
|
|
|
|
|
/* Create hidden window. */
|
2011-05-01 22:35:12 +08:00
|
|
|
hwnd = CreateWindowExW (0, classname, classname, WS_POPUP, CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
(HWND) NULL, (HMENU) NULL, user_data->hmodule,
|
|
|
|
(LPVOID) NULL);
|
2004-05-16 12:18:50 +08:00
|
|
|
if (!hwnd)
|
|
|
|
api_fatal ("couldn't create window, %E");
|
* 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
|
|
|
release ();
|
2004-05-16 00:10:41 +08:00
|
|
|
|
2011-05-01 22:35:12 +08:00
|
|
|
int ret;
|
|
|
|
while ((ret = (int) GetMessageW (&msg, hwnd, 0, 0)) > 0)
|
|
|
|
DispatchMessageW (&msg);
|
2000-02-18 03:38:33 +08:00
|
|
|
|
2003-12-14 15:09:22 +08:00
|
|
|
return 0;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
2004-05-16 12:18:50 +08:00
|
|
|
static DWORD WINAPI
|
|
|
|
winthread (VOID *arg)
|
2000-02-18 03:38:33 +08:00
|
|
|
{
|
2004-05-16 12:18:50 +08:00
|
|
|
return ((wininfo *) arg)->winthread ();
|
|
|
|
}
|
|
|
|
|
|
|
|
wininfo::operator
|
|
|
|
HWND ()
|
|
|
|
{
|
|
|
|
if (hwnd)
|
|
|
|
return hwnd;
|
|
|
|
|
* 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
|
|
|
lock ();
|
2004-05-16 12:18:50 +08:00
|
|
|
if (!hwnd)
|
|
|
|
{
|
2005-04-05 12:31:00 +08:00
|
|
|
_lock.upforgrabs ();
|
2010-09-02 02:24:11 +08:00
|
|
|
cygthread *h = new cygthread (::winthread, this, "win");
|
2004-05-16 12:18:50 +08:00
|
|
|
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
|
|
|
|
h->zap_h ();
|
* 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
|
|
|
lock ();
|
2004-05-16 12:18:50 +08:00
|
|
|
}
|
* 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
|
|
|
release ();
|
2004-05-16 12:18:50 +08:00
|
|
|
return hwnd;
|
2000-02-18 03:38:33 +08:00
|
|
|
}
|
|
|
|
|
* 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
|
|
|
void
|
|
|
|
wininfo::lock ()
|
2001-11-28 08:06:35 +08:00
|
|
|
{
|
2005-04-05 12:31:00 +08:00
|
|
|
_lock.init ("wininfo_lock")->acquire ();
|
2001-11-28 08:06:35 +08:00
|
|
|
}
|
|
|
|
|
* 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
|
|
|
void
|
|
|
|
wininfo::release ()
|
2003-10-14 17:21:55 +08:00
|
|
|
{
|
2005-04-05 12:31:00 +08:00
|
|
|
_lock.release ();
|
2003-10-14 17:21:55 +08:00
|
|
|
}
|