newlib/winsup/cygwin/window.cc
Christopher Faylor ec98d19a08 * 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 01:57:38 +00:00

141 lines
2.9 KiB
C++

/* window.cc: hidden windows for signals/itimer support
Copyright 1997, 1998, 2000, 2001, 2002, 2003, 2004, 2005 Red Hat, Inc.
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. */
#include "winsup.h"
#include <sys/time.h>
#include <stdlib.h>
#include <signal.h>
#include <limits.h>
#include <wingdi.h>
#include <winuser.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
#include <unistd.h>
#include "cygerrno.h"
#include "perprocess.h"
#include "security.h"
#include "thread.h"
#include "cygtls.h"
#include "sync.h"
#include "wininfo.h"
wininfo NO_COPY winmsg;
muto NO_COPY *wininfo::_lock;
int __stdcall
wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
#ifndef NOSTRACE
strace.wm (uMsg, wParam, lParam);
#endif
switch (uMsg)
{
case WM_PAINT:
return 0;
case WM_DESTROY:
PostQuitMessage (0);
return 0;
case WM_ASYNCIO:
if (WSAGETSELECTEVENT (lParam) == FD_OOB)
raise (SIGURG);
else
raise (SIGIO);
return 0;
default:
return DefWindowProc (hwnd, uMsg, wParam, lParam);
}
}
static LRESULT CALLBACK
process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return winmsg.process (hwnd, uMsg, wParam, lParam);
}
/* Handle windows events. Inherits ownership of the wininfo lock */
DWORD WINAPI
wininfo::winthread ()
{
MSG msg;
WNDCLASS wc;
static NO_COPY char classname[] = "CygwinWndClass";
_lock->grab ();
/* Register the window class for the main window. */
wc.style = 0;
wc.lpfnWndProc = (WNDPROC) process_window_events;
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;
if (!RegisterClass (&wc))
api_fatal ("cannot register window class, %E");
/* Create hidden window. */
hwnd = CreateWindow (classname, classname, WS_POPUP, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
(HWND) NULL, (HMENU) NULL, user_data->hmodule,
(LPVOID) NULL);
if (!hwnd)
api_fatal ("couldn't create window, %E");
release ();
while (GetMessage (&msg, hwnd, 0, 0) == TRUE)
DispatchMessage (&msg);
return 0;
}
static DWORD WINAPI
winthread (VOID *arg)
{
return ((wininfo *) arg)->winthread ();
}
wininfo::operator
HWND ()
{
if (hwnd)
return hwnd;
lock ();
if (!hwnd)
{
_lock->upforgrabs ();
cygthread *h = new cygthread (::winthread, this, "win");
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
h->zap_h ();
lock ();
}
release ();
return hwnd;
}
void
wininfo::lock ()
{
new_muto (_lock)->acquire ();
}
void
wininfo::release ()
{
_lock->release ();
}