From bff860c4b101a40c2856a03b6edc562a89084d3a Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 18 Sep 2003 04:39:13 +0000 Subject: [PATCH] Moved synchronization and syslevel routines to dlls/kernel. --- dlls/kernel/Makefile.in | 1 + dlls/kernel/kernel_private.h | 2 + dlls/kernel/relay16.c | 2 +- dlls/kernel/sync.c | 160 ++++++++++++++++++++++ {scheduler => dlls/kernel}/syslevel.c | 9 +- dlls/kernel/task.c | 2 +- dlls/kernel/wowthunk.c | 2 +- dlls/ntdll/Makefile.in | 2 - dlls/ntdll/signal_i386.c | 4 +- include/syslevel.h | 33 ----- scheduler/synchro.c | 190 -------------------------- 11 files changed, 174 insertions(+), 233 deletions(-) rename {scheduler => dlls/kernel}/syslevel.c (97%) delete mode 100644 include/syslevel.h delete mode 100644 scheduler/synchro.c diff --git a/dlls/kernel/Makefile.in b/dlls/kernel/Makefile.in index 6717a95dcf5..776152e70b3 100644 --- a/dlls/kernel/Makefile.in +++ b/dlls/kernel/Makefile.in @@ -52,6 +52,7 @@ C_SRCS = \ stress.c \ string.c \ sync.c \ + syslevel.c \ system.c \ tape.c \ task.c \ diff --git a/dlls/kernel/kernel_private.h b/dlls/kernel/kernel_private.h index 33acbe885bd..71f3db34438 100644 --- a/dlls/kernel/kernel_private.h +++ b/dlls/kernel/kernel_private.h @@ -51,4 +51,6 @@ void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing ); extern BOOL WOWTHUNK_Init(void); +extern VOID SYSLEVEL_CheckNotLevel( INT level ); + #endif diff --git a/dlls/kernel/relay16.c b/dlls/kernel/relay16.c index 5bc972b2262..1ba774330dd 100644 --- a/dlls/kernel/relay16.c +++ b/dlls/kernel/relay16.c @@ -33,7 +33,7 @@ #include "stackframe.h" #include "selectors.h" #include "builtin16.h" -#include "syslevel.h" +#include "kernel_private.h" #include "wine/library.h" #include "wine/debug.h" diff --git a/dlls/kernel/sync.c b/dlls/kernel/sync.c index e3ca7e42062..6be9c01cecc 100644 --- a/dlls/kernel/sync.c +++ b/dlls/kernel/sync.c @@ -43,6 +43,7 @@ #include "wine/server.h" #include "wine/unicode.h" +#include "kernel_private.h" #include "file.h" #include "wine/debug.h" @@ -56,6 +57,165 @@ inline static int is_version_nt(void) } +/*********************************************************************** + * Sleep (KERNEL32.@) + */ +VOID WINAPI Sleep( DWORD timeout ) +{ + SleepEx( timeout, FALSE ); +} + +/****************************************************************************** + * SleepEx (KERNEL32.@) + */ +DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable ) +{ + NTSTATUS status; + + if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL ); + else + { + LARGE_INTEGER time; + + time.QuadPart = timeout * (ULONGLONG)10000; + time.QuadPart = -time.QuadPart; + status = NtDelayExecution( alertable, &time ); + } + if (status != STATUS_USER_APC) status = STATUS_SUCCESS; + return status; +} + + +/*********************************************************************** + * WaitForSingleObject (KERNEL32.@) + */ +DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout ) +{ + return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE ); +} + + +/*********************************************************************** + * WaitForSingleObjectEx (KERNEL32.@) + */ +DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout, + BOOL alertable ) +{ + return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable ); +} + + +/*********************************************************************** + * WaitForMultipleObjects (KERNEL32.@) + */ +DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles, + BOOL wait_all, DWORD timeout ) +{ + return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE ); +} + + +/*********************************************************************** + * WaitForMultipleObjectsEx (KERNEL32.@) + */ +DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, + BOOL wait_all, DWORD timeout, + BOOL alertable ) +{ + NTSTATUS status; + HANDLE hloc[MAXIMUM_WAIT_OBJECTS]; + int i; + + if (count >= MAXIMUM_WAIT_OBJECTS) + { + SetLastError(ERROR_INVALID_PARAMETER); + return WAIT_FAILED; + } + for (i = 0; i < count; i++) + { + if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) || + (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) || + (handles[i] == (HANDLE)STD_ERROR_HANDLE)) + hloc[i] = GetStdHandle( (DWORD)handles[i] ); + else + hloc[i] = handles[i]; + + /* yes, even screen buffer console handles are waitable, and are + * handled as a handle to the console itself !! + */ + if (is_console_handle(hloc[i])) + { + if (!VerifyConsoleIoHandle(hloc[i])) + { + return FALSE; + } + hloc[i] = GetConsoleInputWaitHandle(); + } + } + + if (timeout == INFINITE) + { + status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL ); + } + else + { + LARGE_INTEGER time; + + time.QuadPart = timeout * (ULONGLONG)10000; + time.QuadPart = -time.QuadPart; + status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time ); + } + + if (HIWORD(status)) /* is it an error code? */ + { + SetLastError( RtlNtStatusToDosError(status) ); + status = WAIT_FAILED; + } + return status; +} + + +/*********************************************************************** + * WaitForSingleObject (KERNEL.460) + */ +DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout ) +{ + DWORD retval, mutex_count; + + ReleaseThunkLock( &mutex_count ); + retval = WaitForSingleObject( handle, timeout ); + RestoreThunkLock( mutex_count ); + return retval; +} + +/*********************************************************************** + * WaitForMultipleObjects (KERNEL.461) + */ +DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles, + BOOL wait_all, DWORD timeout ) +{ + DWORD retval, mutex_count; + + ReleaseThunkLock( &mutex_count ); + retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE ); + RestoreThunkLock( mutex_count ); + return retval; +} + +/*********************************************************************** + * WaitForMultipleObjectsEx (KERNEL.495) + */ +DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles, + BOOL wait_all, DWORD timeout, BOOL alertable ) +{ + DWORD retval, mutex_count; + + ReleaseThunkLock( &mutex_count ); + retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable ); + RestoreThunkLock( mutex_count ); + return retval; +} + /*********************************************************************** * InitializeCriticalSection (KERNEL32.@) * diff --git a/scheduler/syslevel.c b/dlls/kernel/syslevel.c similarity index 97% rename from scheduler/syslevel.c rename to dlls/kernel/syslevel.c index 9ad2f51b1e1..565378481ed 100644 --- a/scheduler/syslevel.c +++ b/dlls/kernel/syslevel.c @@ -30,8 +30,8 @@ #include "winreg.h" #include "winternl.h" #include "wine/winbase16.h" -#include "syslevel.h" #include "thread.h" +#include "kernel_private.h" #include "wine/library.h" #include "wine/debug.h" @@ -47,7 +47,7 @@ static CRITICAL_SECTION_DEBUG critsect_debug = static SYSLEVEL Win16Mutex = { { &critsect_debug, -1, 0, 0, 0, 0 }, 1 }; /* Global variable to save current TEB while in 16-bit code */ -WORD SYSLEVEL_Win16CurrentTeb = 0; +extern WORD SYSLEVEL_Win16CurrentTeb; /************************************************************************ @@ -113,8 +113,9 @@ VOID WINAPI _EnterSysLevel(SYSLEVEL *lock) TRACE("(%p, level %d): thread %lx count after %ld\n", lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] ); - if (lock == &Win16Mutex) - SYSLEVEL_Win16CurrentTeb = wine_get_fs(); +#ifdef __i386__ + if (lock == &Win16Mutex) SYSLEVEL_Win16CurrentTeb = wine_get_fs(); +#endif } /************************************************************************ diff --git a/dlls/kernel/task.c b/dlls/kernel/task.c index eafc404683d..2fb01f34b2f 100644 --- a/dlls/kernel/task.c +++ b/dlls/kernel/task.c @@ -45,11 +45,11 @@ #include "winternl.h" #include "selectors.h" #include "wine/server.h" -#include "syslevel.h" #include "stackframe.h" #include "task.h" #include "thread.h" #include "toolhelp.h" +#include "kernel_private.h" #include "wine/debug.h" diff --git a/dlls/kernel/wowthunk.c b/dlls/kernel/wowthunk.c index 0d4fcfa6d2c..1dc70ad90c2 100644 --- a/dlls/kernel/wowthunk.c +++ b/dlls/kernel/wowthunk.c @@ -32,11 +32,11 @@ #include "excpt.h" #include "winreg.h" #include "winternl.h" -#include "syslevel.h" #include "file.h" #include "task.h" #include "miscemu.h" #include "stackframe.h" +#include "kernel_private.h" #include "wine/exception.h" #include "wine/debug.h" diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index b89161fe39b..6b5ada3563e 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -37,8 +37,6 @@ C_SRCS = \ $(TOPOBJDIR)/scheduler/handle.c \ $(TOPOBJDIR)/scheduler/process.c \ $(TOPOBJDIR)/scheduler/pthread.c \ - $(TOPOBJDIR)/scheduler/synchro.c \ - $(TOPOBJDIR)/scheduler/syslevel.c \ $(TOPOBJDIR)/scheduler/thread.c \ $(TOPOBJDIR)/win32/device.c \ $(TOPOBJDIR)/win32/newfns.c \ diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index 54d265deafe..37d7d84018c 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -407,7 +407,6 @@ typedef struct #include "wine/exception.h" #include "global.h" -#include "syslevel.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(seh); @@ -418,6 +417,9 @@ static wine_signal_handler handlers[256]; extern void WINAPI EXC_RtlRaiseException( PEXCEPTION_RECORD, PCONTEXT ); +/* Global variable to save current TEB while in 16-bit code (FIXME) */ +WORD SYSLEVEL_Win16CurrentTeb = 0; + /*********************************************************************** * dispatch_signal */ diff --git a/include/syslevel.h b/include/syslevel.h deleted file mode 100644 index 5e4fc20a437..00000000000 --- a/include/syslevel.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Win32 'syslevel' routines - * - * Copyright 1998 Ulrich Weigand - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __WINE_SYSLEVEL_H -#define __WINE_SYSLEVEL_H - -#include -#include -#include - -extern WORD SYSLEVEL_Win16CurrentTeb; -extern WORD SYSLEVEL_EmergencyTeb; - -VOID SYSLEVEL_CheckNotLevel( INT level ); - -#endif /* __WINE_SYSLEVEL_H */ diff --git a/scheduler/synchro.c b/scheduler/synchro.c deleted file mode 100644 index b2ce0fe383b..00000000000 --- a/scheduler/synchro.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Win32 process and thread synchronisation - * - * Copyright 1997 Alexandre Julliard - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "config.h" - -#include - -#include "ntstatus.h" -#include "windef.h" -#include "winbase.h" -#include "winreg.h" -#include "winternl.h" -#include "../kernel/kernel_private.h" /* FIXME: to be changed when moving file to dlls/kernel */ - - -/*********************************************************************** - * Sleep (KERNEL32.@) - */ -VOID WINAPI Sleep( DWORD timeout ) -{ - SleepEx( timeout, FALSE ); -} - -/****************************************************************************** - * SleepEx (KERNEL32.@) - */ -DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable ) -{ - NTSTATUS status; - - if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL ); - else - { - LARGE_INTEGER time; - - time.QuadPart = timeout * (ULONGLONG)10000; - time.QuadPart = -time.QuadPart; - status = NtDelayExecution( alertable, &time ); - } - if (status != STATUS_USER_APC) status = STATUS_SUCCESS; - return status; -} - - -/*********************************************************************** - * WaitForSingleObject (KERNEL32.@) - */ -DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout ) -{ - return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE ); -} - - -/*********************************************************************** - * WaitForSingleObjectEx (KERNEL32.@) - */ -DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout, - BOOL alertable ) -{ - return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable ); -} - - -/*********************************************************************** - * WaitForMultipleObjects (KERNEL32.@) - */ -DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles, - BOOL wait_all, DWORD timeout ) -{ - return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE ); -} - - -/*********************************************************************** - * WaitForMultipleObjectsEx (KERNEL32.@) - */ -DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles, - BOOL wait_all, DWORD timeout, - BOOL alertable ) -{ - NTSTATUS status; - HANDLE hloc[MAXIMUM_WAIT_OBJECTS]; - int i; - - if (count >= MAXIMUM_WAIT_OBJECTS) - { - SetLastError(ERROR_INVALID_PARAMETER); - return WAIT_FAILED; - } - for (i = 0; i < count; i++) - { - if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) || - (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) || - (handles[i] == (HANDLE)STD_ERROR_HANDLE)) - hloc[i] = GetStdHandle( (DWORD)handles[i] ); - else - hloc[i] = handles[i]; - - /* yes, even screen buffer console handles are waitable, and are - * handled as a handle to the console itself !! - */ - if (is_console_handle(hloc[i])) - { - if (!VerifyConsoleIoHandle(hloc[i])) - { - return FALSE; - } - hloc[i] = GetConsoleInputWaitHandle(); - } - } - - if (timeout == INFINITE) - { - status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL ); - } - else - { - LARGE_INTEGER time; - - time.QuadPart = timeout * (ULONGLONG)10000; - time.QuadPart = -time.QuadPart; - status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time ); - } - - if (HIWORD(status)) /* is it an error code? */ - { - SetLastError( RtlNtStatusToDosError(status) ); - status = WAIT_FAILED; - } - return status; -} - - -/*********************************************************************** - * WaitForSingleObject (KERNEL.460) - */ -DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout ) -{ - DWORD retval, mutex_count; - - ReleaseThunkLock( &mutex_count ); - retval = WaitForSingleObject( handle, timeout ); - RestoreThunkLock( mutex_count ); - return retval; -} - -/*********************************************************************** - * WaitForMultipleObjects (KERNEL.461) - */ -DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles, - BOOL wait_all, DWORD timeout ) -{ - DWORD retval, mutex_count; - - ReleaseThunkLock( &mutex_count ); - retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE ); - RestoreThunkLock( mutex_count ); - return retval; -} - -/*********************************************************************** - * WaitForMultipleObjectsEx (KERNEL.495) - */ -DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles, - BOOL wait_all, DWORD timeout, BOOL alertable ) -{ - DWORD retval, mutex_count; - - ReleaseThunkLock( &mutex_count ); - retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable ); - RestoreThunkLock( mutex_count ); - return retval; -}