revert previous not-ready-for-primetime checkin.
This commit is contained in:
parent
71af2ed39e
commit
aafd8a545f
@ -41,7 +41,6 @@ class cygthread
|
|||||||
(void) CloseHandle (h);
|
(void) CloseHandle (h);
|
||||||
h = NULL;
|
h = NULL;
|
||||||
}
|
}
|
||||||
DWORD tid () const {return id;}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define cygself NULL
|
#define cygself NULL
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
#include "sigproc.h"
|
#include "sigproc.h"
|
||||||
#include "cygthread.h"
|
#include "cygthread.h"
|
||||||
#include "select.h"
|
#include "select.h"
|
||||||
#include "wininfo.h"
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern bool fdsock (cygheap_fdmanip& fd, const device *, SOCKET soc);
|
extern bool fdsock (cygheap_fdmanip& fd, const device *, SOCKET soc);
|
||||||
@ -1375,7 +1374,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case FIOASYNC:
|
case FIOASYNC:
|
||||||
res = WSAAsyncSelect (get_socket (), winmsg, WM_ASYNCIO,
|
res = WSAAsyncSelect (get_socket (), gethwnd (), WM_ASYNCIO,
|
||||||
*(int *) p ? ASYNC_MASK : 0);
|
*(int *) p ? ASYNC_MASK : 0);
|
||||||
syscall_printf ("Async I/O on socket %s",
|
syscall_printf ("Async I/O on socket %s",
|
||||||
*(int *) p ? "started" : "cancelled");
|
*(int *) p ? "started" : "cancelled");
|
||||||
@ -1391,7 +1390,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
|
|||||||
* blocking mode
|
* blocking mode
|
||||||
*/
|
*/
|
||||||
if (cmd == FIONBIO && *(int *) p == 0)
|
if (cmd == FIONBIO && *(int *) p == 0)
|
||||||
WSAAsyncSelect (get_socket (), winmsg, 0, 0);
|
WSAAsyncSelect (get_socket (), gethwnd (), 0, 0);
|
||||||
res = ioctlsocket (get_socket (), cmd, (unsigned long *) p);
|
res = ioctlsocket (get_socket (), cmd, (unsigned long *) p);
|
||||||
if (res == SOCKET_ERROR)
|
if (res == SOCKET_ERROR)
|
||||||
set_winsock_errno ();
|
set_winsock_errno ();
|
||||||
@ -1401,7 +1400,7 @@ fhandler_socket::ioctl (unsigned int cmd, void *p)
|
|||||||
*(int *) p ? "non" : "");
|
*(int *) p ? "non" : "");
|
||||||
/* Start AsyncSelect if async socket unblocked */
|
/* Start AsyncSelect if async socket unblocked */
|
||||||
if (*(int *) p && async_io ())
|
if (*(int *) p && async_io ())
|
||||||
WSAAsyncSelect (get_socket (), winmsg, WM_ASYNCIO, ASYNC_MASK);
|
WSAAsyncSelect (get_socket (), gethwnd (), WM_ASYNCIO, ASYNC_MASK);
|
||||||
|
|
||||||
set_nonblocking (*(int *) p);
|
set_nonblocking (*(int *) p);
|
||||||
}
|
}
|
||||||
|
@ -125,16 +125,6 @@ muto::release ()
|
|||||||
threads waiting for the lock, so trigger bruteforce. */
|
threads waiting for the lock, so trigger bruteforce. */
|
||||||
if (InterlockedDecrement (&waiters) >= 0)
|
if (InterlockedDecrement (&waiters) >= 0)
|
||||||
(void) SetEvent (bruteforce); /* Wake up one of the waiting threads */
|
(void) SetEvent (bruteforce); /* Wake up one of the waiting threads */
|
||||||
else if (*name == '!')
|
|
||||||
{
|
|
||||||
CloseHandle (bruteforce); /* If *name == '!' and there are no
|
|
||||||
other waiters, then this is the
|
|
||||||
last time this muto will ever be
|
|
||||||
used, so close the handle. */
|
|
||||||
#ifdef DEBUGGING
|
|
||||||
bruteforce = NULL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1; /* success. */
|
return 1; /* success. */
|
||||||
|
@ -38,6 +38,7 @@ public:
|
|||||||
/* Return true if caller thread owns the lock. */
|
/* Return true if caller thread owns the lock. */
|
||||||
int ismine () {return tid == GetCurrentThreadId ();}
|
int ismine () {return tid == GetCurrentThreadId ();}
|
||||||
DWORD owner () {return tid;}
|
DWORD owner () {return tid;}
|
||||||
|
int unstable () {return !tid && (sync || waiters >= 0);}
|
||||||
void reset () __attribute__ ((regparm (1)));
|
void reset () __attribute__ ((regparm (1)));
|
||||||
bool acquired ();
|
bool acquired ();
|
||||||
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
|
static void set_exiting_thread () {exiting_thread = GetCurrentThreadId ();}
|
||||||
@ -58,11 +59,4 @@ extern muto muto_start;
|
|||||||
static muto __storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \
|
static muto __storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \
|
||||||
__name = __storage.init (#__name); \
|
__name = __storage.init (#__name); \
|
||||||
})
|
})
|
||||||
|
|
||||||
/* Use a statically allocated buffer as the storage for a muto */
|
|
||||||
#define new_muto_name(__var, __name) \
|
|
||||||
({ \
|
|
||||||
static muto __var##_storage __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy1"))); \
|
|
||||||
__var = __var##_storage.init (__name); \
|
|
||||||
})
|
|
||||||
#endif /*_SYNC_H*/
|
#endif /*_SYNC_H*/
|
||||||
|
@ -24,21 +24,14 @@ details. */
|
|||||||
#include "perprocess.h"
|
#include "perprocess.h"
|
||||||
#include "security.h"
|
#include "security.h"
|
||||||
#include "cygthread.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;
|
static LRESULT CALLBACK
|
||||||
|
WndProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||||
wininfo::wininfo ()
|
|
||||||
{
|
|
||||||
new_muto_name (lock, "!winlock");
|
|
||||||
}
|
|
||||||
|
|
||||||
int __stdcall
|
|
||||||
wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
||||||
{
|
{
|
||||||
#ifndef NOSTRACE
|
#ifndef NOSTRACE
|
||||||
strace.wm (uMsg, wParam, lParam);
|
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;
|
itv.it_interval.tv_usec / 1000;
|
||||||
KillTimer (hwnd, timer_active);
|
KillTimer (hwnd, timer_active);
|
||||||
if (!elapse)
|
if (!elapse)
|
||||||
timer_active = 0;
|
{
|
||||||
|
timer_active = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
timer_active = SetTimer (hwnd, 1, elapse, NULL);
|
timer_active = SetTimer (hwnd, 1, elapse, NULL);
|
||||||
@ -78,15 +73,10 @@ wininfo::process (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static LRESULT CALLBACK
|
static HANDLE window_started;
|
||||||
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 */
|
|
||||||
static DWORD WINAPI
|
static DWORD WINAPI
|
||||||
winthread (VOID *arg)
|
Winmain (VOID *)
|
||||||
{
|
{
|
||||||
MSG msg;
|
MSG msg;
|
||||||
WNDCLASS wc;
|
WNDCLASS wc;
|
||||||
@ -95,7 +85,7 @@ winthread (VOID *arg)
|
|||||||
/* Register the window class for the main window. */
|
/* Register the window class for the main window. */
|
||||||
|
|
||||||
wc.style = 0;
|
wc.style = 0;
|
||||||
wc.lpfnWndProc = (WNDPROC) process_window_events;
|
wc.lpfnWndProc = (WNDPROC) WndProc;
|
||||||
wc.cbClsExtra = 0;
|
wc.cbClsExtra = 0;
|
||||||
wc.cbWndExtra = 0;
|
wc.cbWndExtra = 0;
|
||||||
wc.hInstance = user_data->hmodule;
|
wc.hInstance = user_data->hmodule;
|
||||||
@ -106,64 +96,60 @@ winthread (VOID *arg)
|
|||||||
wc.lpszClassName = classname;
|
wc.lpszClassName = classname;
|
||||||
|
|
||||||
if (!RegisterClass (&wc))
|
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. */
|
/* Create hidden window. */
|
||||||
wi->hwnd = CreateWindow (classname, classname, WS_POPUP, CW_USEDEFAULT,
|
ourhwnd = CreateWindow (classname, classname, WS_POPUP, CW_USEDEFAULT,
|
||||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
(HWND) NULL, (HMENU) NULL, user_data->hmodule,
|
(HWND) NULL, (HMENU) NULL, user_data->hmodule,
|
||||||
(LPVOID) NULL);
|
(LPVOID) NULL);
|
||||||
if (!wi->hwnd)
|
|
||||||
api_fatal ("couldn't create window, %E");
|
|
||||||
wi->lock->release ();
|
|
||||||
|
|
||||||
while (GetMessage (&msg, (HWND) arg, 0, 0) == TRUE)
|
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);
|
DispatchMessage (&msg);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wininfo::operator
|
HWND __stdcall
|
||||||
HWND ()
|
gethwnd ()
|
||||||
{
|
{
|
||||||
if (hwnd)
|
if (ourhwnd != NULL)
|
||||||
return hwnd;
|
return ourhwnd;
|
||||||
|
|
||||||
console_printf ("hwnd is NULL\n");
|
cygthread *h;
|
||||||
lock->acquire ();
|
|
||||||
if (hwnd)
|
|
||||||
{
|
|
||||||
console_printf ("hwnd acquired %p\n", hwnd);
|
|
||||||
lock->release ();
|
|
||||||
return hwnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
console_printf ("creating window\n");
|
window_started = CreateEvent (&sec_none_nih, TRUE, FALSE, NULL);
|
||||||
|
h = new cygthread (Winmain, NULL, "win");
|
||||||
cygthread *h = new cygthread (winthread, this, "win");
|
|
||||||
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
|
h->SetThreadPriority (THREAD_PRIORITY_HIGHEST);
|
||||||
|
WaitForSingleObject (window_started, INFINITE);
|
||||||
|
CloseHandle (window_started);
|
||||||
h->zap_h ();
|
h->zap_h ();
|
||||||
while (!hwnd)
|
return ourhwnd;
|
||||||
low_priority_sleep (0);
|
|
||||||
return hwnd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
setitimer (int which, const struct itimerval *value, struct itimerval *oldvalue)
|
setitimer (int which, const struct itimerval *value, struct itimerval *oldvalue)
|
||||||
{
|
{
|
||||||
|
UINT elapse;
|
||||||
|
|
||||||
if (which != ITIMER_REAL)
|
if (which != ITIMER_REAL)
|
||||||
{
|
{
|
||||||
set_errno (ENOSYS);
|
set_errno (ENOSYS);
|
||||||
return -1;
|
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 */
|
/* Check if we will wrap */
|
||||||
if (itv.it_value.tv_sec >= (long) (UINT_MAX / 1000))
|
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)
|
if (timer_active)
|
||||||
{
|
{
|
||||||
KillTimer (winmsg, timer_active);
|
KillTimer (gethwnd (), timer_active);
|
||||||
timer_active = 0;
|
timer_active = 0;
|
||||||
}
|
}
|
||||||
if (oldvalue)
|
if (oldvalue)
|
||||||
@ -183,13 +169,13 @@ wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
itv = *value;
|
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 (elapse == 0)
|
||||||
if (itv.it_value.tv_usec)
|
if (itv.it_value.tv_usec)
|
||||||
elapse = 1;
|
elapse = 1;
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
if (!(timer_active = SetTimer (winmsg, 1, elapse, NULL)))
|
if (!(timer_active = SetTimer (gethwnd (), 1, elapse, NULL)))
|
||||||
{
|
{
|
||||||
__seterrno ();
|
__seterrno ();
|
||||||
return -1;
|
return -1;
|
||||||
@ -201,6 +187,8 @@ wininfo::setitimer (const struct itimerval *value, struct itimerval *oldvalue)
|
|||||||
extern "C" int
|
extern "C" int
|
||||||
getitimer (int which, struct itimerval *value)
|
getitimer (int which, struct itimerval *value)
|
||||||
{
|
{
|
||||||
|
UINT elapse, val;
|
||||||
|
|
||||||
if (which != ITIMER_REAL)
|
if (which != ITIMER_REAL)
|
||||||
{
|
{
|
||||||
set_errno (EINVAL);
|
set_errno (EINVAL);
|
||||||
@ -211,13 +199,6 @@ getitimer (int which, struct itimerval *value)
|
|||||||
set_errno (EFAULT);
|
set_errno (EFAULT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return winmsg.getitimer (value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* FIXME: racy */
|
|
||||||
int __stdcall
|
|
||||||
wininfo::getitimer (struct itimerval *value)
|
|
||||||
{
|
|
||||||
*value = itv;
|
*value = itv;
|
||||||
if (!timer_active)
|
if (!timer_active)
|
||||||
{
|
{
|
||||||
@ -225,9 +206,6 @@ wininfo::getitimer (struct itimerval *value)
|
|||||||
value->it_value.tv_usec = 0;
|
value->it_value.tv_usec = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT elapse, val;
|
|
||||||
|
|
||||||
elapse = GetTickCount () - start_time;
|
elapse = GetTickCount () - start_time;
|
||||||
val = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
|
val = itv.it_value.tv_sec * 1000 + itv.it_value.tv_usec / 1000;
|
||||||
val -= elapse;
|
val -= elapse;
|
||||||
|
@ -217,6 +217,8 @@ void events_terminate (void);
|
|||||||
|
|
||||||
void __stdcall close_all_files ();
|
void __stdcall close_all_files ();
|
||||||
|
|
||||||
|
/* Invisible window initialization/termination. */
|
||||||
|
HWND __stdcall gethwnd (void);
|
||||||
/* Check if running in a visible window station. */
|
/* Check if running in a visible window station. */
|
||||||
extern bool has_visible_window_station (void);
|
extern bool has_visible_window_station (void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user