summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/window.cc
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2005-03-27 01:57:38 +0000
committerChristopher Faylor <me@cgf.cx>2005-03-27 01:57:38 +0000
commitec98d19a08c2e4678e8a6f40fea0c9bbeaa4a2c7 (patch)
tree667b5bf4984c1caa5b3f7df1b2b296e16c394c73 /winsup/cygwin/window.cc
parent9eba97c0d5d723ce151b38d4bc78bd6fe097336c (diff)
downloadcygnal-ec98d19a08c2e4678e8a6f40fea0c9bbeaa4a2c7.tar.gz
cygnal-ec98d19a08c2e4678e8a6f40fea0c9bbeaa4a2c7.tar.bz2
cygnal-ec98d19a08c2e4678e8a6f40fea0c9bbeaa4a2c7.zip
* 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.
Diffstat (limited to 'winsup/cygwin/window.cc')
-rw-r--r--winsup/cygwin/window.cc179
1 files changed, 14 insertions, 165 deletions
diff --git a/winsup/cygwin/window.cc b/winsup/cygwin/window.cc
index 2c5fcce8a..335ce3339 100644
--- a/winsup/cygwin/window.cc
+++ b/winsup/cygwin/window.cc
@@ -1,6 +1,6 @@
/* window.cc: hidden windows for signals/itimer support
- Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004 Red Hat, Inc.
+ Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
Written by Sergey Okhapkin <sos@prospect.com.ru>
@@ -30,12 +30,7 @@ details. */
wininfo NO_COPY winmsg;
-muto NO_COPY *wininfo::lock;
-
-wininfo::wininfo ()
-{
- new_muto_name (lock, "!winlock");
-}
+muto NO_COPY *wininfo::_lock;
int __stdcall
wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
@@ -50,23 +45,6 @@ wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_DESTROY:
PostQuitMessage (0);
return 0;
- case WM_TIMER:
- if (wParam == timer_active)
- {
- UINT elapse = itv.it_interval.tv_sec * 1000 +
- itv.it_interval.tv_usec / 1000;
- KillTimer (hwnd, timer_active);
- if (!elapse)
- timer_active = 0;
- else
- {
- timer_active = SetTimer (hwnd, 1, elapse, NULL);
- start_time = GetTickCount ();
- itv.it_value = itv.it_interval;
- }
- raise (SIGALRM);
- }
- return 0;
case WM_ASYNCIO:
if (WSAGETSELECTEVENT (lParam) == FD_OOB)
raise (SIGURG);
@@ -92,7 +70,7 @@ wininfo::winthread ()
WNDCLASS wc;
static NO_COPY char classname[] = "CygwinWndClass";
- lock->grab ();
+ _lock->grab ();
/* Register the window class for the main window. */
wc.style = 0;
@@ -116,7 +94,7 @@ wininfo::winthread ()
(LPVOID) NULL);
if (!hwnd)
api_fatal ("couldn't create window, %E");
- lock->release ();
+ release ();
while (GetMessage (&msg, hwnd, 0, 0) == TRUE)
DispatchMessage (&msg);
@@ -136,156 +114,27 @@ HWND ()
if (hwnd)
return hwnd;
- lock->acquire ();
+ lock ();
if (!hwnd)
{
- lock->upforgrabs ();
+ _lock->upforgrabs ();
cygthread *h = new cygthread (::winthread, this, "win");
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
h->zap_h ();
- lock->acquire ();
+ lock ();
}
- lock->release ();
+ release ();
return hwnd;
}
-extern "C" int
-setitimer (int which, const struct itimerval *value, struct itimerval *oldvalue)
-{
- if (which != ITIMER_REAL)
- {
- set_errno (ENOSYS);
- return -1;
- }
- return winmsg.setitimer (value, oldvalue);
-}
-
-/* FIXME: Very racy */
-int __stdcall
-wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
-{
- /* Check if we will wrap */
- if (itv.it_value.tv_sec >= (long) (UINT_MAX / 1000))
- {
- set_errno (EINVAL);
- return -1;
- }
- if (timer_active)
- {
- KillTimer (winmsg, timer_active);
- timer_active = 0;
- }
- if (oldvalue)
- *oldvalue = itv;
- if (value == NULL)
- {
- set_errno (EFAULT);
- return -1;
- }
- itv = *value;
- UINT elapse = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
- if (elapse == 0)
- if (itv.it_value.tv_usec)
- elapse = 1;
- else
- return 0;
- if (!(timer_active = SetTimer (winmsg, 1, elapse, NULL)))
- {
- __seterrno ();
- return -1;
- }
- start_time = GetTickCount ();
- return 0;
-}
-
-extern "C" int
-getitimer (int which, struct itimerval *value)
-{
- if (which != ITIMER_REAL)
- {
- set_errno (EINVAL);
- return -1;
- }
- if (value == NULL)
- {
- set_errno (EFAULT);
- return -1;
- }
- return winmsg.getitimer (value);
-}
-
-/* FIXME: racy */
-int __stdcall
-wininfo::getitimer (struct itimerval *value)
-{
- *value = itv;
- if (!timer_active)
- {
- value->it_value.tv_sec = 0;
- value->it_value.tv_usec = 0;
- return 0;
- }
-
- UINT elapse, val;
-
- elapse = GetTickCount () - start_time;
- val = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
- val -= elapse;
- value->it_value.tv_sec = val / 1000;
- value->it_value.tv_usec = val % 1000;
- return 0;
-}
-
-extern "C" unsigned int
-alarm (unsigned int seconds)
-{
- int ret;
- struct itimerval newt, oldt;
-
- newt.it_value.tv_sec = seconds;
- newt.it_value.tv_usec = 0;
- newt.it_interval.tv_sec = 0;
- newt.it_interval.tv_usec = 0;
- setitimer (ITIMER_REAL, &newt, &oldt);
- ret = oldt.it_value.tv_sec;
- if (ret == 0 && oldt.it_value.tv_usec)
- ret = 1;
- return ret;
-}
-
-extern "C" useconds_t
-ualarm (useconds_t value, useconds_t interval)
+void
+wininfo::lock ()
{
- struct itimerval timer, otimer;
-
- timer.it_value.tv_sec = 0;
- timer.it_value.tv_usec = value;
- timer.it_interval.tv_sec = 0;
- timer.it_interval.tv_usec = interval;
-
- if (setitimer (ITIMER_REAL, &timer, &otimer) < 0)
- return (u_int)-1;
-
- return (otimer.it_value.tv_sec * 1000000) + otimer.it_value.tv_usec;
+ new_muto (_lock)->acquire ();
}
-bool
-has_visible_window_station (void)
+void
+wininfo::release ()
{
- HWINSTA station_hdl;
- USEROBJECTFLAGS uof;
- DWORD len;
-
- /* Check if the process is associated with a visible window station.
- These are processes running on the local desktop as well as processes
- running in terminal server sessions.
- Processes running in a service session not explicitely associated
- with the desktop (using the "Allow service to interact with desktop"
- property) are running in an invisible window station. */
- if ((station_hdl = GetProcessWindowStation ())
- && GetUserObjectInformationA (station_hdl, UOI_FLAGS, &uof,
- sizeof uof, &len)
- && (uof.dwFlags & WSF_VISIBLE))
- return true;
- return false;
+ _lock->release ();
}