[Xorg-commit] xc/programs/Xserver/hw/xfree86/os-support/os2 os2_VTsw.c,1.1.4.2,1.1.4.3 os2_init.c,1.1.4.3,1.1.4.4 os2_io.c,1.1.4.2,1.1.4.3 os2_kbdEv.c,1.1.4.1,1.1.4.2 os2_select.c,1.1.4.2,1.1.4.3 os2_select.h,1.1.4.1,1.1.4.2
Kaleb Keithley
xorg-commit at pdx.freedesktop.org
Wed May 9 17:30:30 EEST 2007
Committed by: kaleb
Update of /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2
In directory pdx:/home/kaleb/xorg/xc.XORG-CURRENT/programs/Xserver/hw/xfree86/os-support/os2
Modified Files:
Tag: XORG-CURRENT
os2_VTsw.c os2_init.c os2_io.c os2_kbdEv.c os2_select.c
os2_select.h
Log Message:
merge most of XFree86 RC3 (4.3.99.903) from vendor branch.
bug #214
Index: os2_VTsw.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -d -r1.1.4.2 -r1.1.4.3
--- a/os2_VTsw.c 26 Nov 2003 22:49:02 -0000 1.1.4.2
+++ b/os2_VTsw.c 23 Feb 2004 21:37:05 -0000 1.1.4.3
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c,v 3.13 2003/06/10 17:03:54 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_VTsw.c,v 3.14 2004/02/14 00:10:17 dawes Exp $ */
/*
* Copyright 1993 by David Wexelblat <dwex at goblin.org>
* Modified 1996 by Sebastien Marineau <marineau at genie.uottawa.ca>
@@ -49,6 +49,7 @@
HEV hevSwitchRequested;
HEV hevErrorPopupDetected;
extern HEV hevPopupPending;
+extern HEV hSwitchToSem;
BOOL os2PopupErrorPending=FALSE;
/*
@@ -79,13 +80,15 @@
Bool xf86VTSwitchTo()
{
APIRET rc;
- ULONG drive;
+ ULONG drive,postCount;
- xf86Info.vtRequestsPending=FALSE;
- SwitchedToWPS=FALSE;
+ xf86Info.vtRequestsPending=FALSE;
+ SwitchedToWPS=FALSE;
+ rc = DosResetEventSem(hSwitchToSem,&postCount);
DosPostEventSem(hevSwitchRequested);
rc = DosQuerySysInfo(5,5,&drive,sizeof(drive));
rc = DosSuppressPopUps(0x0001L,drive+96); /* Disable popups */
+
/* We reset the state of the control key */
os2PostKbdEvent(KEY_LCtrl,1);
os2PostKbdEvent(KEY_LCtrl,0);
@@ -124,9 +127,12 @@
FirstTime=FALSE;
if(NotifyType==1) NotifyType=65535; /* In case a redraw is requested on first call */
}
-
-/* Sanity check */
+
if(NotifyType==1){
+/* Notify os2PseudoSelect() that we are back */
+ rc=DosPostEventSem(hSwitchToSem);
+ if (rc) xf86Msg(X_ERROR,"Post SwitchToSem returned %d\n");
+/* Sanity check */
if (!SwitchedToWPS) {
xf86Msg(X_ERROR,
"Abnormal switching back to server detected\n");
@@ -185,6 +191,7 @@
rc=VioModeWait(Indic,&NotifyType,(HVIO)0);
if(NotifyType==0){
os2PopupErrorPending=TRUE;
+ rc=DosPostEventSem(hSwitchToSem);
rc=DosResetEventSem(hevErrorPopupDetected,&postCount);
rc=DosWaitEventSem(hevErrorPopupDetected,20000L);
if(rc==ERROR_TIMEOUT) GiveUp(0); /* Shutdown on timeout of semaphore */
@@ -196,10 +203,10 @@
static BOOL is_redirected = FALSE;
-static void
-redirect_output(void)
+static void
+redirect_output(void)
{
- /* hv300996 create redirect file on boot drive, instead
+ /* hv300996 create redirect file on boot drive, instead
* anywhere you are just standing
*/
char buf[20],dr[3];
@@ -219,12 +226,12 @@
ErrorF("\nThis is the XFree86/OS2-4.0 server\n");
ErrorF("\nAll output from now on will be redirected to %s\n",buf);
- freopen(buf,"w",stderr);
+ freopen(buf,"w",stderr);
is_redirected = TRUE;
}
-void
+void
os2ServerVideoAccess()
{
APIRET rc;
@@ -235,7 +242,7 @@
/* Redirect output as early as possible */
/* redirect_output(); */
/* too many logfiles, server will log to /usr/adm */
-
+
/* Wait for screen access. This is called at server reset or at server startup */
/* Here we do some waiting until this session comes in the foreground before *
* going any further. This is because we may have been started in the bg */
@@ -262,6 +269,8 @@
void os2RecoverFromPopup()
{
int j;
+ ULONG postCount;
+
if (os2PopupErrorPending) {
#if 0
for (j = 0; j < screenInfo.numScreens; j++)
@@ -269,9 +278,11 @@
for (j = 0; j < screenInfo.numScreens; j++)
(XF86SCRNINFO(screenInfo.screens[j])->EnterLeaveVT)(ENTER, j);
#endif
+ DosResetEventSem(hSwitchToSem,&postCount);
+
for (j = 0; j < xf86NumScreens; j++) {
if (xf86Screens[j]->EnableDisableFBAccess)
- (*xf86Screens[j]->EnableDisableFBAccess)(j, FALSE);
+ (*xf86Screens[j]->EnableDisableFBAccess)(j, FALSE);
}
xf86EnterServerState(SETUP);
for (j = 0; j < xf86NumScreens; j++)
@@ -282,16 +293,16 @@
xf86EnterServerState(OPERATING);
for (j = 0; j < xf86NumScreens; j++) {
if (xf86Screens[j]->EnableDisableFBAccess)
- (*xf86Screens[j]->EnableDisableFBAccess)(j, TRUE);
+ (*xf86Screens[j]->EnableDisableFBAccess)(j, TRUE);
}
- /* We reset the state of the control key */
- os2PostKbdEvent(KEY_LCtrl,1);
- os2PostKbdEvent(KEY_LCtrl,0);
- os2PostKbdEvent(KEY_RCtrl,1);
- os2PostKbdEvent(KEY_RCtrl,0);
- os2PostKbdEvent(KEY_Alt,1);
- os2PostKbdEvent(KEY_Alt,0);
+ /* We reset the state of the control key */
+ os2PostKbdEvent(KEY_LCtrl,1);
+ os2PostKbdEvent(KEY_LCtrl,0);
+ os2PostKbdEvent(KEY_RCtrl,1);
+ os2PostKbdEvent(KEY_RCtrl,0);
+ os2PostKbdEvent(KEY_Alt,1);
+ os2PostKbdEvent(KEY_Alt,0);
/* Turn screen saver off when switching back */
SaveScreens(SCREEN_SAVER_FORCER,ScreenSaverReset);
Index: os2_init.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c,v
retrieving revision 1.1.4.3
retrieving revision 1.1.4.4
diff -u -d -r1.1.4.3 -r1.1.4.4
--- a/os2_init.c 6 Dec 2003 13:24:28 -0000 1.1.4.3
+++ b/os2_init.c 23 Feb 2004 21:37:05 -0000 1.1.4.4
@@ -1,5 +1,4 @@
-/* $XdotOrg$ */
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c,v 3.18 2003/11/29 01:48:31 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_init.c,v 3.19 2004/02/14 00:10:17 dawes Exp $ */
/*
* (c) Copyright 1994 by Holger Veit
* <Holger.Veit at gmd.de>
@@ -226,36 +225,16 @@
/* ARGSUSED */
-extern ULONG hrt_delay;
int xf86ProcessArgument (argc, argv, i)
int argc;
char *argv[];
int i;
{
- if (!strcmp(argv[i], "-os2HRTimer")) {
- os2HRTimerFlag = TRUE;
- if (++i < argc && argv[i]) {
- char *end;
- long val;
- val = strtoul(argv[i], &end, 0);
- if (*end == '\0') {
- hrt_delay = val;
- return 2;
- }
- else {
- hrt_delay = 12;
- }
- }
- return 1;
- }
return 0;
}
void xf86UseMsg()
{
- ErrorF("-os2HRTimer [n] ");
- ErrorF("use the OS/2 high-resolution timer driver (TIMER0.SYS)\n");
- ErrorF(" ");
- ErrorF("post semaphore every n milliseconds. Default: 12\n");
return;
}
+
Index: os2_io.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -d -r1.1.4.2 -r1.1.4.3
--- a/os2_io.c 26 Nov 2003 22:49:02 -0000 1.1.4.2
+++ b/os2_io.c 23 Feb 2004 21:37:05 -0000 1.1.4.3
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c,v 3.19 2003/11/17 22:20:41 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_io.c,v 3.20 2004/02/14 00:10:18 dawes Exp $ */
/*
* (c) Copyright 1994,1999 by Holger Veit
* <Holger.Veit at gmd.de>
@@ -38,6 +38,7 @@
#define INCL_DOSPROCESS
#define INCL_KBD
#define INCL_MOU
+#define INCL_DOSDEVIOCTL
#include "xf86.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
@@ -86,7 +87,42 @@
void xf86SetKbdRepeat(char rad)
{
+ int rc;
+ int delay = 250; /* Default delay */
+ int rate = 30; /* Default repeat rate */
+
+ struct {
+ USHORT Delay;
+ USHORT Rate;
+ } rateDelay;
+
+ ULONG rateDelaySize = sizeof(rateDelay);
+
/*notyet*/
+ return;
+
+ if (xf86Info.kbdRate >= 0)
+ rate = xf86Info.kbdRate;
+ if (xf86Info.kbdDelay >= 0)
+ delay = xf86Info.kbdDelay;
+
+ rateDelay.Delay = delay;
+ rateDelay.Rate = rate;
+
+ xf86Msg(X_INFO,"Setting typematic rate: Delay=%d, Rate=%d\n",delay,rate);
+
+ rc = DosDevIOCtl( (HFILE) xf86Info.consoleFd,
+ IOCTL_KEYBOARD,
+ KBD_SETTYPAMATICRATE,
+ &rateDelay,
+ rateDelaySize,
+ &rateDelaySize,
+ NULL,
+ 0,
+ NULL);
+ if (rc!=0) {
+ xf86Msg(X_ERROR,"xf86SetKbdRepeat: DosDevIOCtl returned %d\n",rc);
+ }
}
void xf86KbdInit()
Index: os2_kbdEv.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c,v
retrieving revision 1.1.4.1
retrieving revision 1.1.4.2
diff -u -d -r1.1.4.1 -r1.1.4.2
--- a/os2_kbdEv.c 17 Nov 2003 19:03:46 -0000 1.1.4.1
+++ b/os2_kbdEv.c 23 Feb 2004 21:37:05 -0000 1.1.4.2
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c,v 3.16 2002/05/31 18:46:01 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_kbdEv.c,v 3.17 2004/02/14 00:07:01 dawes Exp $ */
/*
* (c) Copyright 1994,1996,1999 by Holger Veit
* <Holger.Veit at gmd.de>
@@ -344,11 +344,6 @@
}
#endif /* not PC98 */
- /* check for an autorepeat-event */
- if ((down && KeyPressed(keycode)) &&
- (xf86Info.autoRepeat != AutoRepeatModeOn || keyc->modifierMap[keycode]))
- return;
-
/* normal, non-keypad keys */
if (scanCode < KEY_KP_7 || scanCode > KEY_KP_Decimal) {
/* magic ALT_L key on AT84 keyboards for multilingual support */
@@ -363,6 +358,12 @@
#ifdef XKB /* Warning: got position wrong first time */
}
#endif
+
+ /* check for an autorepeat-event */
+ if ((down && KeyPressed(keycode)) &&
+ (xf86Info.autoRepeat != AutoRepeatModeOn || keyc->modifierMap[keycode]))
+ return;
+
xf86Info.lastEventTime =
kevent.u.keyButtonPointer.time =
GetTimeInMillis();
Index: os2_select.c
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c,v
retrieving revision 1.1.4.2
retrieving revision 1.1.4.3
diff -u -d -r1.1.4.2 -r1.1.4.3
--- a/os2_select.c 26 Nov 2003 22:49:02 -0000 1.1.4.2
+++ b/os2_select.c 23 Feb 2004 21:37:05 -0000 1.1.4.3
@@ -3,31 +3,33 @@
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c,v 3.9 2003/03/25 04:18:24 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.c,v 3.10 2004/02/14 00:10:18 dawes Exp $ */
/*
* (c) Copyright 1996 by Sebastien Marineau
* <marineau at genie.uottawa.ca>
- * Modified 1999 by Holger.Veit at gmd.de
+ * Modified 1999 by Holger.Veit at gmd.de
+ * Modified 2004 by Frank Giessler
+ * <giessler at biomag.uni-jena.de>
*
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
- * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * HOLGER VEIT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
- *
+ *
* Except as contained in this notice, the name of Sebastien Marineau shall not be
* used in advertising or otherwise to promote the sale, use or other dealings
* in this Software without prior written authorization from Sebastien Marineau.
@@ -65,22 +67,25 @@
int os2KbdQueueQuery();
void os2RecoverFromPopup();
void os2CheckPopupPending();
-void os2HighResTimerThread();
+void os2SocketMonitorThread();
extern BOOL os2PopupErrorPending;
extern HEV hKbdSem;
extern HEV hMouseSem;
extern HEV hevServerHasFocus;
HEV hPipeSem;
-HEV hHRTSem;
+HEV hSocketSem;
+HEV hActivateSocketSem;
+HEV hSwitchToSem;
static HMUX hSelectWait;
-Bool os2HRTimerFlag=FALSE;
SEMRECORD SelectMuxRecord[5];
HMODULE hmod_so32dll;
+static struct select_data sd;
static int (*os2_tcp_select)(int *,int,int,int,long);
+static int (*os2_so_cancel)(int);
+static int (*os2_sock_errno)();
int os2_set_error(ULONG);
-ULONG os2_get_sys_millis();
extern int _files[];
@@ -92,11 +97,11 @@
/* This is still VERY messy */
-/* A few note on optimizations: this select has been tuned for maximum
-* performance, and thus has a different approach than a general-purpose
+/* A few note on optimizations: this select has been tuned for maximum
+* performance, and thus has a different approach than a general-purpose
* select. It should not be used in another app without modifications. Further,
-* it may need modifications if the Xserver os code is modified
-* Assumptions: this is never called with anything in exceptfds. This is
+* it may need modifications if the Xserver os code is modified
+* Assumptions: this is never called with anything in exceptfds. This is
* silently ignored. Further, if any pipes are specified in the write mask, it is
* because they have just been stuffed full by the xserver. There is not much
* in immediately returning with those bits set. Instead, we block on the
@@ -104,411 +109,385 @@
* to flush the pipe. */
int os2PseudoSelect(nfds,readfds,writefds,exceptfds,timeout)
-int nfds;
-fd_set *readfds,*writefds,*exceptfds;
-struct timeval *timeout;
+ int nfds;
+ fd_set *readfds,*writefds,*exceptfds;
+ struct timeval *timeout;
{
-static BOOL FirstTime=TRUE;
+ static BOOL FirstTime=TRUE;
-int i,j,n,ns,np;
-int ready_handles;
-ULONG timeout_ms;
-BOOL any_ready;
-ULONG semKey,postCount,start_millis,now_millis;
-APIRET rc;
-char faildata[16];
-struct timeval dummy_timeout;
-struct select_data sd;
-static int HRT_Tid;
+ int n,ns,np;
+ int ready_handles;
+ ULONG timeout_ms;
+ BOOL any_ready;
+ ULONG semKey,postCount;
+ APIRET rc;
+ char faildata[16];
+ static int Socket_Tid;
-sd.have_read=FALSE; sd.have_write=FALSE;
-sd.socket_nread=0; sd.socket_nwrite=0; sd.socket_ntotal=0;
-sd.max_fds=31; ready_handles=0; any_ready=FALSE;
-sd.pipe_ntotal=0; sd.pipe_have_write=FALSE;
+ sd.have_read=FALSE; sd.have_write=FALSE;
+ sd.socket_nread=0; sd.socket_nwrite=0; sd.socket_ntotal=0;
+ sd.max_fds=31; ready_handles=0; any_ready=FALSE;
+ sd.pipe_ntotal=0; sd.pipe_have_write=FALSE;
-/* Stuff we have to do the first time this is called to set up various parameters */
+ /* Stuff we have to do the first time this is called to set up various parameters */
-if(FirstTime){
- /* First load the so32dll.dll module and get a pointer to the SELECT fn */
+ if (FirstTime) {
+ /* First load the so32dll.dll module and get a pointer to the SELECT fn */
- if((rc=DosLoadModule(faildata,sizeof(faildata),"SO32DLL",&hmod_so32dll))!=0){
- FatalError("Could not load module so32dll.dll, rc = %d. Error note %s\n",rc,faildata);
- }
- if((rc = DosQueryProcAddr(hmod_so32dll, 0, "SELECT", (PPFN)&os2_tcp_select))!=0){
- FatalError("Could not query address of SELECT, rc = %d.\n",rc);
- }
- /* Call these a first time to set the semaphore */
- xf86OsMouseEvents();
- xf86KbdEvents();
+ if ((rc=DosLoadModule(faildata,sizeof(faildata),"SO32DLL",&hmod_so32dll))!=0) {
+ FatalError("Could not load module so32dll.dll, rc = %d. Error note %s\n",rc,faildata);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SELECT", (PPFN)&os2_tcp_select))!=0) {
+ FatalError("Could not query address of SELECT, rc = %d.\n",rc);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SO_CANCEL", (PPFN)&os2_so_cancel))!=0) {
+ FatalError("Could not query address of SO_CANCEL, rc = %d.\n",rc);
+ }
+ if ((rc = DosQueryProcAddr(hmod_so32dll, 0, "SOCK_ERRNO", (PPFN)&os2_sock_errno))!=0) {
+ FatalError("Could not query address of SOCK_ERRNO, rc = %d.\n",rc);
+ }
- DosCreateEventSem(NULL, &hHRTSem,DC_SEM_SHARED,FALSE);
- DosResetEventSem(hHRTSem,&postCount);
- if (os2HRTimerFlag) {
- HRT_Tid = _beginthread(os2HighResTimerThread, NULL, 0x2000,(void *) NULL);
- xf86Msg(X_INFO,
- "Started high-resolution timer thread, TID=%d\n",HRT_Tid);
- }
-
- SelectMuxRecord[0].hsemCur = (HSEM)hMouseSem;
- SelectMuxRecord[0].ulUser = MOUSE_SEM_KEY;
- SelectMuxRecord[1].hsemCur = (HSEM)hKbdSem;
- SelectMuxRecord[1].ulUser = KBD_SEM_KEY;
- SelectMuxRecord[2].hsemCur = (HSEM)hPipeSem;
- SelectMuxRecord[2].ulUser = PIPE_SEM_KEY;
- SelectMuxRecord[3].hsemCur = (HSEM)hHRTSem;
- SelectMuxRecord[3].ulUser = HRT_SEM_KEY;
- rc = DosCreateMuxWaitSem(NULL, &hSelectWait, 4, SelectMuxRecord,
+ /* Call these a first time to set the semaphore */
+ xf86OsMouseEvents();
+ xf86KbdEvents();
+
+ DosCreateEventSem(NULL, &hSocketSem,DC_SEM_SHARED,FALSE);
+ DosResetEventSem(hSocketSem,&postCount);
+
+ DosCreateEventSem(NULL, &hActivateSocketSem, DC_SEM_SHARED, FALSE);
+ DosResetEventSem(hActivateSocketSem, &postCount);
+
+ DosCreateEventSem(NULL, &hSwitchToSem, DC_SEM_SHARED, FALSE);
+ DosResetEventSem(hSwitchToSem, &postCount);
+
+ Socket_Tid = _beginthread(os2SocketMonitorThread, NULL, 0x2000,(void *) NULL);
+ xf86Msg(X_INFO,
+ "Started Socket monitor thread, TID=%d\n",Socket_Tid);
+
+ SelectMuxRecord[0].hsemCur = (HSEM)hMouseSem;
+ SelectMuxRecord[0].ulUser = MOUSE_SEM_KEY;
+ SelectMuxRecord[1].hsemCur = (HSEM)hKbdSem;
+ SelectMuxRecord[1].ulUser = KBD_SEM_KEY;
+ SelectMuxRecord[2].hsemCur = (HSEM)hPipeSem;
+ SelectMuxRecord[2].ulUser = PIPE_SEM_KEY;
+ SelectMuxRecord[3].hsemCur = (HSEM)hSocketSem;
+ SelectMuxRecord[3].ulUser = SOCKET_SEM_KEY;
+ SelectMuxRecord[4].hsemCur = (HSEM)hSwitchToSem;
+ SelectMuxRecord[4].ulUser = SWITCHTO_SEM_KEY;
+
+ rc = DosCreateMuxWaitSem(NULL, &hSelectWait, 5, SelectMuxRecord,
DC_SEM_SHARED | DCMW_WAIT_ANY);
- if(rc){
- xf86Msg(X_ERROR,"Could not create MuxWait semaphore, rc=%d\n",rc);
- }
- FirstTime = FALSE;
-}
+ if (rc) {
+ xf86Msg(X_ERROR,"Could not create MuxWait semaphore, rc=%d\n",rc);
+ }
+ FirstTime = FALSE;
+ }
-/* Set up the time delay structs */
+ rc = DosResetEventSem(hActivateSocketSem, &postCount);
+ /* Set up the time delay structs */
- if(timeout!=NULL) {
+ if (timeout!=NULL) {
timeout_ms=timeout->tv_sec*1000+timeout->tv_usec/1000;
+ } else {
+ timeout_ms=1000000; /* This should be large enough... */
}
- else { timeout_ms=1000000; } /* This should be large enough... */
- if(timeout_ms>0) start_millis=os2_get_sys_millis();
-/* Zero our local fd_masks */
- {FD_ZERO(&sd.read_copy);}
- {FD_ZERO(&sd.write_copy);}
+ /* Zero our local fd_masks */
+ {FD_ZERO(&sd.read_copy);}
+ {FD_ZERO(&sd.write_copy);}
-/* Copy the masks for later use */
- if(readfds!=NULL){ XFD_COPYSET(readfds,&sd.read_copy); sd.have_read=TRUE;}
- if(writefds!=NULL) {XFD_COPYSET(writefds,&sd.write_copy);sd.have_write=TRUE;}
+ /* Copy the masks for later use */
+ if (readfds!=NULL) { XFD_COPYSET(readfds,&sd.read_copy); sd.have_read=TRUE; }
+ if (writefds!=NULL) {XFD_COPYSET(writefds,&sd.write_copy); sd.have_write=TRUE; }
-/* And zero the original masks */
- if(sd.have_read){ FD_ZERO(readfds);}
- if(sd.have_write) {FD_ZERO(writefds);}
- if(exceptfds != NULL) {FD_ZERO(exceptfds);}
+ /* And zero the original masks */
+ if (sd.have_read){ FD_ZERO(readfds); }
+ if (sd.have_write) {FD_ZERO(writefds); }
+ if (exceptfds != NULL) {FD_ZERO(exceptfds); }
-/* Now we parse the fd_sets passed to select and separate pipe/sockets */
- n = os2_parse_select(&sd,nfds);
+ /* Now we parse the fd_sets passed to select and separate pipe/sockets */
+ n = os2_parse_select(&sd,nfds);
-/* Now check if we have sockets ready! */
+ /* Now check if we have sockets ready! */
- if (sd.socket_ntotal > 0){
- ns = os2_poll_sockets(&sd,readfds,writefds);
- if(ns>0){
- ready_handles+=ns;
- any_ready = TRUE;
- }
- else if (ns == -1) {return(-1);}
- }
-
-/* And pipes */
+ if (sd.socket_ntotal > 0) {
+ ns = os2_poll_sockets(&sd,readfds,writefds);
+ if (ns>0) {
+ ready_handles+=ns;
+ any_ready = TRUE;
+ } else if (ns == -1) {
+ return(-1);
+ }
+ }
- if(sd.pipe_ntotal > 0){
+ /* And pipes */
+
+ if (sd.pipe_ntotal > 0) {
np = os2_check_pipes(&sd,readfds,writefds);
- if(np > 0){
- ready_handles+=np;
- any_ready = TRUE;
- }
- else if (np == -1) { return(-1); }
- }
+ if (np > 0) {
+ ready_handles+=np;
+ any_ready = TRUE;
+ } else if (np == -1) {
+ return(-1);
+ }
+ }
-/* ... */
+ /* And finally poll input devices */
+ if(!os2MouseQueueQuery() || !os2KbdQueueQuery() ) any_ready = TRUE;
-/* And finally poll input devices */
- if(!os2MouseQueueQuery() || !os2KbdQueueQuery() ) any_ready = TRUE;
+ if (xf86Info.vtRequestsPending) any_ready=TRUE;
- while(!any_ready && timeout_ms){
- DosResetEventSem(hHRTSem,&postCount);
- rc = DosWaitMuxWaitSem(hSelectWait, 5, &semKey);
- if ((rc == 0) && (semKey != HRT_SEM_KEY) && (semKey != PIPE_SEM_KEY)){
- any_ready = TRUE;
- }
- if (os2PopupErrorPending) {
- os2RecoverFromPopup();
- any_ready=TRUE;
- }
- if(xf86Info.vtRequestsPending) any_ready=TRUE;
- if (sd.socket_ntotal > 0){
- ns = os2_poll_sockets(&sd,readfds,writefds,exceptfds);
- if(ns>0){
- ready_handles+=ns;
- any_ready = TRUE;
- }
- else if (ns == -1) {return(-1);}
- }
+ if (os2PopupErrorPending)
+ os2RecoverFromPopup();
- rc = DosQueryEventSem(hPipeSem,&postCount);
- if(postCount && (sd.pipe_ntotal > 0)){
- np = os2_check_pipes(&sd,readfds,writefds);
- if(np > 0){
- ready_handles+=np;
- any_ready = TRUE;
- }
- else if (np == -1) {
- return(-1); }
- }
+ if (!any_ready && timeout_ms) {
+ DosResetEventSem(hSocketSem,&postCount);
+ /* Activate the socket thread */
+ if (sd.socket_ntotal>0) {
+ rc = DosPostEventSem(hActivateSocketSem);
+ }
- if (i%8 == 0) {
- now_millis = os2_get_sys_millis();
- if((now_millis-start_millis) > timeout_ms) timeout_ms = 0;
- }
- i++;
- }
+ rc = DosWaitMuxWaitSem(hSelectWait, timeout_ms, &semKey);
-/* The polling of sockets/pipe automatically set the proper bits */
+ /* If our socket monitor thread is still blocked in os2_tcp_select()
+ * we have to wake it up by calling os2_so_cancel().
+ * After that, call os2_tcp_select() once more to get rid of
+ * error SOCEINTR (10004)
+ */
+ if (sd.socket_ntotal>0) {
+ rc = DosQueryEventSem(hSocketSem, &postCount);
-return (ready_handles);
+ if (postCount == 0) { /* os2_select still blocked */
+ int i,f,g;
+ struct select_data *sd_ptr=&sd;
+
+ if (sd.socket_nread > 0) {
+ for (i=0; i<sd.socket_nread; i++) {
+ f = g = sd_ptr->tcp_select_mask[i];
+ os2_so_cancel(f);
+ os2_tcp_select(&g, 1, 0, 0, 0); /* get rid of error 10004 */
+ }
+ }
+ if (sd.socket_nwrite > 0) {
+ for (i=sd.socket_nread;
+ i<sd.socket_nread+sd.socket_nwrite;
+ i++) {
+ f = g = sd_ptr->tcp_select_mask[i];
+ os2_so_cancel(f);
+ os2_tcp_select(&g, 0, 1, 0, 0); /* get rid of error 10004 */
+ }
+ }
+ } else { /* not blocked, something must be ready -> get it */
+ ns = os2_poll_sockets(&sd,readfds,writefds);
+ if (ns>0) {
+ ready_handles+=ns;
+ } else if (ns == -1) {
+ return(-1);
+ }
+ }
+ }
+ if (sd.pipe_ntotal > 0) {
+ rc = DosQueryEventSem(hPipeSem,&postCount);
+ if (postCount > 0) {
+ np = os2_check_pipes(&sd,readfds,writefds);
+ if (np > 0) {
+ ready_handles+=np;
+ } else if (np == -1) {
+ return(-1);
+ }
+ }
+ }
+ }
+ /* The polling of sockets/pipe automatically set the proper bits */
+ return (ready_handles);
}
int os2_parse_select(sd,nfds)
-struct select_data *sd;
-int nfds;
+ struct select_data *sd;
+ int nfds;
{
int i;
-/* First we determine up to which descriptor we need to check. */
-/* No need to check up to 256 if we don't have to (and usually we dont...)*/
-/* Note: stuff here is hardcoded for fd_sets which are int[8] as in EMX!!! */
-
-
- if(nfds > sd->max_fds){
- for(i=0;i<((FD_SETSIZE+31)/32);i++){
- if(sd->read_copy.fds_bits[i] ||
- sd->write_copy.fds_bits[i])
- sd->max_fds=(i*32) +32;
- }
- }
- else { sd->max_fds = nfds; }
-
-/* Check if this is greater than specified in select() call */
- if(sd->max_fds > nfds) sd->max_fds = nfds;
+ /* First we determine up to which descriptor we need to check. */
+ /* No need to check up to 256 if we don't have to (and usually we dont...)*/
+ /* Note: stuff here is hardcoded for fd_sets which are int[8] as in EMX!!! */
- if (sd->have_read)
- {
- for (i = 0; i < sd->max_fds; ++i) {
- if (FD_ISSET (i, &sd->read_copy)){
- if(_files[i] & F_SOCKET)
- {
- sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
- sd->tcp_emx_handles[sd->socket_ntotal]=i;
- sd->socket_ntotal++; sd->socket_nread++;
- }
- else if (_files[i] & F_PIPE)
- {
- sd -> pipe_ntotal++;
- }
- }
- }
- }
+ if (nfds > sd->max_fds) {
+ for (i=0;i<((FD_SETSIZE+31)/32);i++) {
+ if (sd->read_copy.fds_bits[i] ||
+ sd->write_copy.fds_bits[i])
+ sd->max_fds=(i*32) +32;
+ }
+ } else { sd->max_fds = nfds; }
- if (sd->have_write)
- {
- for (i = 0; i < sd->max_fds; ++i) {
- if (FD_ISSET (i, &sd->write_copy)){
- if(_files[i] & F_SOCKET)
- {
- sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
- sd->tcp_emx_handles[sd->socket_ntotal]=i;
- sd->socket_ntotal++; sd->socket_nwrite++;
- }
- else if (_files[i] & F_PIPE)
- {
- sd -> pipe_ntotal++;
- sd -> pipe_have_write=TRUE;
- }
- }
- }
- }
+ /* Check if this is greater than specified in select() call */
+ if(sd->max_fds > nfds) sd->max_fds = nfds;
-return(sd->socket_ntotal);
+ if (sd->have_read) {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->read_copy)) {
+ if(_files[i] & F_SOCKET) {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nread++;
+ } else if (_files[i] & F_PIPE) {
+ sd -> pipe_ntotal++;
+ }
+ }
+ }
+ }
+ if (sd->have_write) {
+ for (i = 0; i < sd->max_fds; ++i) {
+ if (FD_ISSET (i, &sd->write_copy)) {
+ if (_files[i] & F_SOCKET) {
+ sd->tcp_select_mask[sd->socket_ntotal]=_getsockhandle(i);
+ sd->tcp_emx_handles[sd->socket_ntotal]=i;
+ sd->socket_ntotal++; sd->socket_nwrite++;
+ } else if (_files[i] & F_PIPE) {
+ sd -> pipe_ntotal++;
+ sd -> pipe_have_write=TRUE;
+ }
+ }
+ }
+ }
+ return(sd->socket_ntotal);
}
int os2_poll_sockets(sd,readfds,writefds)
-struct select_data *sd;
-fd_set *readfds,*writefds;
+ struct select_data *sd;
+ fd_set *readfds,*writefds;
{
- int e,i;
- int j,n;
- memcpy(sd->tcp_select_copy,sd->tcp_select_mask,
- sd->socket_ntotal*sizeof(int));
-
- e = os2_tcp_select(sd->tcp_select_copy,sd->socket_nread,
- sd->socket_nwrite, 0, 0);
+ int e,i;
+ int j,n;
+
+ memcpy(sd->tcp_select_copy,sd->tcp_select_mask,
+ sd->socket_ntotal*sizeof(int));
+
+ e = os2_tcp_select(sd->tcp_select_copy,sd->socket_nread,
+ sd->socket_nwrite, 0, 0);
+
+ if (e == 0) return(e);
- if(e == 0) return(e);
/* We have something ready? */
- if(e>0){
- j = 0; n = 0;
- for (i = 0; i < sd->socket_nread; ++i, ++j)
- if (sd->tcp_select_copy[j] != -1)
- {
- FD_SET (sd->tcp_emx_handles[j], readfds);
- n ++;
- }
- for (i = 0; i < sd->socket_nwrite; ++i, ++j)
- if (sd->tcp_select_copy[j] != -1)
- {
- FD_SET (sd->tcp_emx_handles[j], writefds);
- n ++;
- }
- errno = 0;
-
- return n;
- }
- if(e<0){
- /*Error -- TODO */
- xf86Msg(X_ERROR,"Error in server select! e=%d\n",e);
- errno = EBADF;
- return (-1);
- }
- }
+ if (e>0) {
+ j = 0; n = 0;
+ for (i = 0; i < sd->socket_nread; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1) {
+ FD_SET (sd->tcp_emx_handles[j], readfds);
+ n ++;
+ }
+ for (i = 0; i < sd->socket_nwrite; ++i, ++j)
+ if (sd->tcp_select_copy[j] != -1) {
+ FD_SET (sd->tcp_emx_handles[j], writefds);
+ n ++;
+ }
+ errno = 0;
+
+ return n;
+ }
+ if (e<0) {
+ /*Error -- TODO */
+ xf86Msg(X_ERROR,"Error in server select! sock_errno = %d\n",os2_sock_errno());
+ errno = EBADF;
+ return (-1);
+ }
+}
/* Check to see if anything is ready on pipes */
int os2_check_pipes(sd,readfds,writefds)
-struct select_data *sd;
-fd_set *readfds,*writefds;
+ struct select_data *sd;
+ fd_set *readfds,*writefds;
{
int i,e;
ULONG ulPostCount;
PIPESEMSTATE pipeSemState[128];
APIRET rc;
- e = 0;
- rc = DosResetEventSem(hPipeSem,&ulPostCount);
- rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState,
- sizeof(pipeSemState));
- if(rc) xf86Msg(X_ERROR,"SELECT: rc from QueryNPipeSem: %d\n",rc);
- i=0;
- while (pipeSemState[i].fStatus != 0) {
+
+ e = 0;
+ rc = DosResetEventSem(hPipeSem,&ulPostCount);
+ rc = DosQueryNPipeSemState((HSEM) hPipeSem, (PPIPESEMSTATE)&pipeSemState,
+ sizeof(pipeSemState));
+ if(rc) xf86Msg(X_ERROR,"SELECT: rc from QueryNPipeSem: %d\n",rc);
+ i=0;
+ while (pipeSemState[i].fStatus != 0) {
/* xf86Msg(X_INFO,"SELECT: sem entry, stat=%d, flag=%d, key=%d,avail=%d\n",
pipeSemState[i].fStatus,pipeSemState[i].fFlag,pipeSemState[i].usKey,
pipeSemState[i].usAvail); */
- if((pipeSemState[i].fStatus == 1) &&
- (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy))){
- FD_SET(pipeSemState[i].usKey,readfds);
- e++;
- }
- else if((pipeSemState[i].fStatus == 2) &&
- (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy))){
- FD_SET(pipeSemState[i].usKey,writefds);
- e++;
- }
- else if( (pipeSemState[i].fStatus == 3) &&
- ( (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy)) ||
- (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy)) )){
- errno = EBADF;
- /* xf86Msg(X_ERROR,"Pipe has closed down, fd=%d\n",pipeSemState[i].usKey); */
- return (-1);
- }
- i++;
- } /* endwhile */
+ if ((pipeSemState[i].fStatus == 1) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->read_copy))) {
+ FD_SET(pipeSemState[i].usKey,readfds);
+ e++;
+ } else if ((pipeSemState[i].fStatus == 2) &&
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy))) {
+ FD_SET(pipeSemState[i].usKey,writefds);
+ e++;
+ } else if ((pipeSemState[i].fStatus == 3) &&
+ ((FD_ISSET(pipeSemState[i].usKey,&sd->read_copy)) ||
+ (FD_ISSET(pipeSemState[i].usKey,&sd->write_copy)) )) {
+ errno = EBADF;
+ /* xf86Msg(X_ERROR,"Pipe has closed down, fd=%d\n",pipeSemState[i].usKey); */
+ return (-1);
+ }
+ i++;
+ } /* endwhile */
errno = 0;
return(e);
}
-/* This thread runs with the high-res timer, timer0.sys */
-/* The semaphore hHRTSem gets posted every HRT_DELAY ms */
-/* Temptation may be strong to decrease this delay, but it already */
-/* consumes proportionally quite a bit of cpu and 12 ms seems quite good*/
-
-#define HRT_DELAY 12
-ULONG hrt_delay;
-
-void os2HighResTimerThread(void* arg)
+void os2SocketMonitorThread(void *arg)
{
- HFILE hTimer;
- ULONG ulDelay,ulAction,ulSize,ulPostCount;
- APIRET rc;
- char *fmt;
-
- if ((hrt_delay > 0) && (hrt_delay < 21)) {
- ulDelay = hrt_delay;
- }
- else {
- ulDelay = HRT_DELAY;
- }
-
- ulSize=sizeof(ulDelay);
-
-#if 0
- xf86Msg(X_INFO,"hrt_delay = %d\n", ulDelay);
-#endif
- rc = DosOpen("TIMER0$",&hTimer,&ulAction,
- 0,0,OPEN_ACTION_OPEN_IF_EXISTS,
- OPEN_FLAGS_FAIL_ON_ERROR | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
- NULL);
- if (rc) {
- fmt = "Open TIMER0.SYS failed, rc=%d. No High-resolution available\n";
- goto errexit2;
- }
- hTimer = _imphandle(hTimer);
- if (hTimer<0) {
- fmt = "Could not import handle from TIMER0.SYS, rc=%d.\n";
- goto errexit2;
- }
+ struct select_data *sd_ptr = &sd;
+ ULONG ulPostCount;
+ int e,rc;
- /* Make the thread time critical */
+ /* Make thread time critical */
DosSetPriority(2L,3L,0L,0L);
- while (1) {
- rc = DosDevIOCtl(hTimer,0x80,5,
- &ulDelay,ulSize,&ulSize,
- NULL,0,NULL);
- if (rc != 0) {
- fmt = "Bad return code from timer0.sys, rc=%d\n";
- goto errexit1;
- }
- rc = DosQueryEventSem(hHRTSem,&ulPostCount);
- if (rc != 0) {
- fmt = "Bad return code from QueryEventSem, rc=%d\n";
- goto errexit1;
- }
-
- if (ulPostCount == 0) rc = DosPostEventSem(hHRTSem);
- if (rc != 0 && rc != 299) {
- fmt = "Bad return code from PostEventSem, rc=%d\n";
- goto errexit1;
- }
+ while (1) {
+ rc = DosWaitEventSem(hActivateSocketSem, SEM_INDEFINITE_WAIT);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosWaitEventSem(hActivateSocketSem..) returned %d\n",rc);
- rc = DosQueryEventSem(hevServerHasFocus,&ulPostCount);
- if (rc != 0) {
- fmt = "Bad return code from QueryEventSem for server focus, rc=%d\n";
- goto errexit1;
- }
+ rc = DosResetEventSem(hActivateSocketSem,&ulPostCount);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosResetEventSem(&hActivateSocketSem..) returned %d\n",rc);
- /* Disable the HRT timer thread while switched away. */
- if (ulPostCount == 0)
- DosWaitEventSem(hevServerHasFocus, SEM_INDEFINITE_WAIT);
+ /* fg300104:
+ * The next line shouldn't be here, but the DosPostEventSem()
+ * below will return 299 from time to time under heavy load
+ */
+/* DosResetEventSem(hSocketSem,&ulPostCount);*/
- }
+ memcpy(sd_ptr->tcp_select_monitor,sd_ptr->tcp_select_mask,
+ sd_ptr->socket_ntotal*sizeof(int));
- /* XXX reached? */
- DosClose(hTimer);
- return;
+ /* call os2_select(), return only if either something is ready or
+ * os2_so_cancel() was called
+ */
+ e = os2_tcp_select(sd_ptr->tcp_select_monitor, sd_ptr->socket_nread,
+ sd_ptr->socket_nwrite, 0, -1);
- /* error catch blocks */
-errexit1:
- DosClose(hTimer);
-errexit2:
- xf86Msg(X_ERROR,fmt,rc);
- DosExitList(0l,0l);
-}
+ if (e>0) {
+ rc = DosPostEventSem(hSocketSem);
+ if (rc != 0 )
+ xf86Msg(X_ERROR,"Socket monitor: DosPostEventSem(hSocketSem..) returned %d\n",rc);
+ } else if (e<0) {
+ rc = os2_sock_errno();
+ if (rc != 10004)
+ xf86Msg(X_ERROR,"Socket monitor: os2_select: sock_errno = %d\n",rc);
+ }
-ULONG os2_get_sys_millis()
-{
- APIRET rc;
- ULONG milli;
+ rc = DosQueryEventSem(hevServerHasFocus, &ulPostCount);
- rc = DosQuerySysInfo(14, 14, &milli, sizeof(milli));
- if (rc) {
- xf86Msg(X_ERROR,
- "Bad return code querying the millisecond counter! rc=%d\n",
- rc);
- return 0;
+ /* no need to rush while switched away */
+ if ((rc==0) && (ulPostCount==0))
+ rc == DosWaitEventSem(hevServerHasFocus,31L);
}
- return milli;
}
+
Index: os2_select.h
===================================================================
RCS file: /cvs/xorg/xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h,v
retrieving revision 1.1.4.1
retrieving revision 1.1.4.2
diff -u -d -r1.1.4.1 -r1.1.4.2
--- a/os2_select.h 17 Nov 2003 19:03:46 -0000 1.1.4.1
+++ b/os2_select.h 23 Feb 2004 21:37:05 -0000 1.1.4.2
@@ -27,7 +27,7 @@
*
*/
-/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h,v 3.1 1996/12/27 07:04:31 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/os2/os2_select.h,v 3.2 2004/02/14 00:10:18 dawes Exp $ */
/* Header file for os2_select.c */
@@ -36,7 +36,8 @@
#define MOUSE_SEM_KEY 0x0F01
#define KBD_SEM_KEY 0x0F02
#define PIPE_SEM_KEY 0x0F03
-#define HRT_SEM_KEY 0x0F04
+#define SOCKET_SEM_KEY 0x0F04
+#define SWITCHTO_SEM_KEY 0x0F05
struct select_data
@@ -48,6 +49,7 @@
int tcp_select_mask[MAX_TCP];
int tcp_emx_handles[MAX_TCP];
int tcp_select_copy[MAX_TCP];
+ int tcp_select_monitor[MAX_TCP];
int socket_nread;
int socket_nwrite;
int socket_ntotal;
More information about the xorg-commit
mailing list