Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2004-05-15 20:10:41 +0400
committerChristopher Faylor <me@cgf.cx>2004-05-15 20:10:41 +0400
commitaafd8a545f7d9089d47ac28d890840f22dac6df4 (patch)
tree552dc673ad6ca9359114d2f9d080bcc27fc48c44 /winsup/cygwin/window.cc
parent71af2ed39e0c727eb8b9df6bdc1d9dbed762ad5d (diff)
revert previous not-ready-for-primetime checkin.
Diffstat (limited to 'winsup/cygwin/window.cc')
-rw-r--r--winsup/cygwin/window.cc120
1 files changed, 49 insertions, 71 deletions
diff --git a/winsup/cygwin/window.cc b/winsup/cygwin/window.cc
index 554be3a5e..d005ae69b 100644
--- a/winsup/cygwin/window.cc
+++ b/winsup/cygwin/window.cc
@@ -24,21 +24,14 @@ details. */
#include "perprocess.h"
#include "security.h"
#include "cygthread.h"
-#include "sync.h"
-static DWORD WINAPI winthread (VOID *);
-#include "wininfo.h"
-wininfo NO_COPY winmsg;
+static NO_COPY UINT timer_active = 0;
+static NO_COPY struct itimerval itv;
+static NO_COPY DWORD start_time;
+static NO_COPY HWND ourhwnd = NULL;
-muto NO_COPY *wininfo::lock;
-
-wininfo::wininfo ()
-{
- new_muto_name (lock, "!winlock");
-}
-
-int __stdcall
-wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
+static LRESULT CALLBACK
+WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
#ifndef NOSTRACE
strace.wm (uMsg, wParam, lParam);
@@ -57,7 +50,9 @@ wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
itv.it_interval.tv_usec / 1000;
KillTimer (hwnd, timer_active);
if (!elapse)
- timer_active = 0;
+ {
+ timer_active = 0;
+ }
else
{
timer_active = SetTimer (hwnd, 1, elapse, NULL);
@@ -78,15 +73,10 @@ wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
}
}
-static LRESULT CALLBACK
-process_window_events (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- return winmsg.process (hwnd, uMsg, wParam, lParam);
-}
+static HANDLE window_started;
-/* Handle windows events. Inherits ownership of the wininfo lock */
static DWORD WINAPI
-winthread (VOID *arg)
+Winmain (VOID *)
{
MSG msg;
WNDCLASS wc;
@@ -95,7 +85,7 @@ winthread (VOID *arg)
/* Register the window class for the main window. */
wc.style = 0;
- wc.lpfnWndProc = (WNDPROC) process_window_events;
+ wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = user_data->hmodule;
@@ -106,64 +96,60 @@ winthread (VOID *arg)
wc.lpszClassName = classname;
if (!RegisterClass (&wc))
- api_fatal ("cannot register window class, %E");
+ {
+ system_printf ("Cannot register window class, %E");
+ return FALSE;
+ }
- wininfo *wi = (wininfo *) arg;
/* Create hidden window. */
- wi->hwnd = CreateWindow (classname, classname, WS_POPUP, CW_USEDEFAULT,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- (HWND) NULL, (HMENU) NULL, user_data->hmodule,
- (LPVOID) NULL);
- if (!wi->hwnd)
- api_fatal ("couldn't create window, %E");
- wi->lock->release ();
-
- while (GetMessage (&msg, (HWND) arg, 0, 0) == TRUE)
+ ourhwnd = CreateWindow (classname, classname, WS_POPUP, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ (HWND) NULL, (HMENU) NULL, user_data->hmodule,
+ (LPVOID) NULL);
+
+ SetEvent (window_started);
+
+ if (!ourhwnd)
+ {
+ system_printf ("Cannot create window");
+ return FALSE;
+ }
+
+ /* Start the message loop. */
+
+ while (GetMessage (&msg, ourhwnd, 0, 0) == TRUE)
DispatchMessage (&msg);
return 0;
}
-wininfo::operator
-HWND ()
+HWND __stdcall
+gethwnd ()
{
- if (hwnd)
- return hwnd;
-
-console_printf ("hwnd is NULL\n");
- lock->acquire ();
- if (hwnd)
- {
-console_printf ("hwnd acquired %p\n", hwnd);
- lock->release ();
- return hwnd;
- }
+ if (ourhwnd != NULL)
+ return ourhwnd;
-console_printf ("creating window\n");
+ cygthread *h;
- cygthread *h = new cygthread (winthread, this, "win");
+ window_started = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
+ h = new cygthread (Winmain, NULL, "win");
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
+ WaitForSingleObject (window_started, INFINITE);
+ CloseHandle (window_started);
h->zap_h ();
- while (!hwnd)
- low_priority_sleep (0);
- return hwnd;
+ return ourhwnd;
}
extern "C" int
setitimer (int which, const struct itimerval *value, struct itimerval *oldvalue)
{
+ UINT elapse;
+
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))
{
@@ -172,7 +158,7 @@ wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
}
if (timer_active)
{
- KillTimer (winmsg, timer_active);
+ KillTimer (gethwnd (), timer_active);
timer_active = 0;
}
if (oldvalue)
@@ -183,13 +169,13 @@ wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
return -1;
}
itv = *value;
- UINT elapse = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
+ 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)))
+ if (!(timer_active = SetTimer (gethwnd (), 1, elapse, NULL)))
{
__seterrno ();
return -1;
@@ -201,6 +187,8 @@ wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
extern "C" int
getitimer (int which, struct itimerval *value)
{
+ UINT elapse, val;
+
if (which != ITIMER_REAL)
{
set_errno (EINVAL);
@@ -211,13 +199,6 @@ getitimer (int which, struct itimerval *value)
set_errno (EFAULT);
return -1;
}
- return winmsg.getitimer (value);
-}
-
-/* FIXME: racy */
-int __stdcall
-wininfo::getitimer (struct itimerval *value)
-{
*value = itv;
if (!timer_active)
{
@@ -225,9 +206,6 @@ wininfo::getitimer (struct itimerval *value)
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;