2 * Kernel synchronization objects
4 * Copyright 1998 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
29 #ifdef HAVE_SYS_IOCTL_H
30 #include <sys/ioctl.h>
32 #ifdef HAVE_SYS_POLL_H
35 #ifdef HAVE_SYS_SOCKET_H
36 #include <sys/socket.h>
47 #include "wine/server.h"
48 #include "wine/unicode.h"
49 #include "wine/winbase16.h"
50 #include "kernel_private.h"
52 #include "wine/debug.h"
54 WINE_DEFAULT_DEBUG_CHANNEL(sync);
56 /* check if current version is NT or Win95 */
57 inline static int is_version_nt(void)
59 return !(GetVersion() & 0x80000000);
63 /***********************************************************************
66 VOID WINAPI Sleep( DWORD timeout )
68 SleepEx( timeout, FALSE );
71 /******************************************************************************
72 * SleepEx (KERNEL32.@)
74 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
78 if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL );
83 time.QuadPart = timeout * (ULONGLONG)10000;
84 time.QuadPart = -time.QuadPart;
85 status = NtDelayExecution( alertable, &time );
87 if (status != STATUS_USER_APC) status = STATUS_SUCCESS;
92 /***********************************************************************
93 * WaitForSingleObject (KERNEL32.@)
95 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
97 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
101 /***********************************************************************
102 * WaitForSingleObjectEx (KERNEL32.@)
104 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
107 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
111 /***********************************************************************
112 * WaitForMultipleObjects (KERNEL32.@)
114 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
115 BOOL wait_all, DWORD timeout )
117 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
121 /***********************************************************************
122 * WaitForMultipleObjectsEx (KERNEL32.@)
124 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
125 BOOL wait_all, DWORD timeout,
129 HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
132 if (count >= MAXIMUM_WAIT_OBJECTS)
134 SetLastError(ERROR_INVALID_PARAMETER);
137 for (i = 0; i < count; i++)
139 if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
140 (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
141 (handles[i] == (HANDLE)STD_ERROR_HANDLE))
142 hloc[i] = GetStdHandle( (DWORD)handles[i] );
144 hloc[i] = handles[i];
146 /* yes, even screen buffer console handles are waitable, and are
147 * handled as a handle to the console itself !!
149 if (is_console_handle(hloc[i]))
151 if (!VerifyConsoleIoHandle(hloc[i]))
155 hloc[i] = GetConsoleInputWaitHandle();
159 if (timeout == INFINITE)
161 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL );
167 time.QuadPart = timeout * (ULONGLONG)10000;
168 time.QuadPart = -time.QuadPart;
169 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time );
172 if (HIWORD(status)) /* is it an error code? */
174 SetLastError( RtlNtStatusToDosError(status) );
175 status = WAIT_FAILED;
181 /***********************************************************************
182 * WaitForSingleObject (KERNEL.460)
184 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
186 DWORD retval, mutex_count;
188 ReleaseThunkLock( &mutex_count );
189 retval = WaitForSingleObject( handle, timeout );
190 RestoreThunkLock( mutex_count );
194 /***********************************************************************
195 * WaitForMultipleObjects (KERNEL.461)
197 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
198 BOOL wait_all, DWORD timeout )
200 DWORD retval, mutex_count;
202 ReleaseThunkLock( &mutex_count );
203 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
204 RestoreThunkLock( mutex_count );
208 /***********************************************************************
209 * WaitForMultipleObjectsEx (KERNEL.495)
211 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
212 BOOL wait_all, DWORD timeout, BOOL alertable )
214 DWORD retval, mutex_count;
216 ReleaseThunkLock( &mutex_count );
217 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
218 RestoreThunkLock( mutex_count );
222 /***********************************************************************
223 * RegisterWaitForSingleObject (KERNEL32.@)
225 BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
226 WAITORTIMERCALLBACK Callback, PVOID Context,
227 ULONG dwMilliseconds, ULONG dwFlags)
229 FIXME("%p %p %p %p %ld %ld\n",
230 phNewWaitObject,hObject,Callback,Context,dwMilliseconds,dwFlags);
234 /***********************************************************************
235 * RegisterWaitForSingleObjectEx (KERNEL32.@)
237 BOOL WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
238 WAITORTIMERCALLBACK Callback, PVOID Context,
239 ULONG dwMilliseconds, ULONG dwFlags )
241 FIXME("%p %p %p %ld %ld\n",
242 hObject,Callback,Context,dwMilliseconds,dwFlags);
246 /***********************************************************************
247 * UnregisterWait (KERNEL32.@)
249 BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
251 FIXME("%p\n",WaitHandle);
255 /***********************************************************************
256 * UnregisterWaitEx (KERNEL32.@)
258 BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
260 FIXME("%p %p\n",WaitHandle, CompletionEvent);
264 /***********************************************************************
265 * InitializeCriticalSection (KERNEL32.@)
267 * Initialise a critical section before use.
270 * crit [O] Critical section to initialise.
273 * Nothing. If the function fails an exception is raised.
275 void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
277 NTSTATUS ret = RtlInitializeCriticalSection( crit );
278 if (ret) RtlRaiseStatus( ret );
281 /***********************************************************************
282 * InitializeCriticalSectionAndSpinCount (KERNEL32.@)
284 * Initialise a critical section with a spin count.
287 * crit [O] Critical section to initialise.
288 * spincount [I] Number of times to spin upon contention.
292 * Failure: Nothing. If the function fails an exception is raised.
295 * spincount is ignored on uni-processor systems.
297 BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
299 NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount );
300 if (ret) RtlRaiseStatus( ret );
304 /***********************************************************************
305 * SetCriticalSectionSpinCount (KERNEL32.@)
307 * Set the spin count for a critical section.
310 * crit [O] Critical section to set the spin count for.
311 * spincount [I] Number of times to spin upon contention.
314 * The previous spin count value of crit.
317 * This function is available on NT4SP3 or later, but not Win98.
319 DWORD WINAPI SetCriticalSectionSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
321 ULONG_PTR oldspincount = crit->SpinCount;
322 if(spincount) FIXME("critsection=%p: spincount=%ld not supported\n", crit, spincount);
323 crit->SpinCount = spincount;
327 /***********************************************************************
328 * MakeCriticalSectionGlobal (KERNEL32.@)
330 void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
332 /* let's assume that only one thread at a time will try to do this */
333 HANDLE sem = crit->LockSemaphore;
334 if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 );
335 crit->LockSemaphore = ConvertToGlobalHandle( sem );
338 RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
339 crit->DebugInfo = NULL;
344 /***********************************************************************
345 * ReinitializeCriticalSection (KERNEL32.@)
347 * Initialise an already used critical section.
350 * crit [O] Critical section to initialise.
355 void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
357 if ( !crit->LockSemaphore )
358 RtlInitializeCriticalSection( crit );
362 /***********************************************************************
363 * UninitializeCriticalSection (KERNEL32.@)
365 * UnInitialise a critical section after use.
368 * crit [O] Critical section to uninitialise (destroy).
373 void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
375 RtlDeleteCriticalSection( crit );
379 /***********************************************************************
380 * CreateEventA (KERNEL32.@)
382 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
383 BOOL initial_state, LPCSTR name )
385 WCHAR buffer[MAX_PATH];
387 if (!name) return CreateEventW( sa, manual_reset, initial_state, NULL );
389 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
391 SetLastError( ERROR_FILENAME_EXCED_RANGE );
394 return CreateEventW( sa, manual_reset, initial_state, buffer );
398 /***********************************************************************
399 * CreateEventW (KERNEL32.@)
401 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
402 BOOL initial_state, LPCWSTR name )
405 DWORD len = name ? strlenW(name) : 0;
408 SetLastError( ERROR_FILENAME_EXCED_RANGE );
411 /* one buggy program needs this
412 * ("Van Dale Groot woordenboek der Nederlandse taal")
414 if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
416 ERR("Bad security attributes pointer %p\n",sa);
417 SetLastError( ERROR_INVALID_PARAMETER);
420 SERVER_START_REQ( create_event )
422 req->manual_reset = manual_reset;
423 req->initial_state = initial_state;
424 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
425 wine_server_add_data( req, name, len * sizeof(WCHAR) );
427 wine_server_call_err( req );
435 /***********************************************************************
436 * CreateW32Event (KERNEL.457)
438 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
440 return CreateEventA( NULL, manual_reset, initial_state, NULL );
444 /***********************************************************************
445 * OpenEventA (KERNEL32.@)
447 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
449 WCHAR buffer[MAX_PATH];
451 if (!name) return OpenEventW( access, inherit, NULL );
453 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
455 SetLastError( ERROR_FILENAME_EXCED_RANGE );
458 return OpenEventW( access, inherit, buffer );
462 /***********************************************************************
463 * OpenEventW (KERNEL32.@)
465 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
468 DWORD len = name ? strlenW(name) : 0;
471 SetLastError( ERROR_FILENAME_EXCED_RANGE );
474 if (!is_version_nt()) access = EVENT_ALL_ACCESS;
476 SERVER_START_REQ( open_event )
478 req->access = access;
479 req->inherit = inherit;
480 wine_server_add_data( req, name, len * sizeof(WCHAR) );
481 wine_server_call_err( req );
489 /***********************************************************************
492 * Execute an event operation (set,reset,pulse).
494 static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
497 SERVER_START_REQ( event_op )
499 req->handle = handle;
501 ret = !wine_server_call_err( req );
508 /***********************************************************************
509 * PulseEvent (KERNEL32.@)
511 BOOL WINAPI PulseEvent( HANDLE handle )
513 return EVENT_Operation( handle, PULSE_EVENT );
517 /***********************************************************************
518 * SetW32Event (KERNEL.458)
519 * SetEvent (KERNEL32.@)
521 BOOL WINAPI SetEvent( HANDLE handle )
523 return EVENT_Operation( handle, SET_EVENT );
527 /***********************************************************************
528 * ResetW32Event (KERNEL.459)
529 * ResetEvent (KERNEL32.@)
531 BOOL WINAPI ResetEvent( HANDLE handle )
533 return EVENT_Operation( handle, RESET_EVENT );
537 /***********************************************************************
538 * NOTE: The Win95 VWin32_Event routines given below are really low-level
539 * routines implemented directly by VWin32. The user-mode libraries
540 * implement Win32 synchronisation routines on top of these low-level
541 * primitives. We do it the other way around here :-)
544 /***********************************************************************
545 * VWin32_EventCreate (KERNEL.442)
547 HANDLE WINAPI VWin32_EventCreate(VOID)
549 HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
550 return ConvertToGlobalHandle( hEvent );
553 /***********************************************************************
554 * VWin32_EventDestroy (KERNEL.443)
556 VOID WINAPI VWin32_EventDestroy(HANDLE event)
558 CloseHandle( event );
561 /***********************************************************************
562 * VWin32_EventWait (KERNEL.450)
564 VOID WINAPI VWin32_EventWait(HANDLE event)
568 ReleaseThunkLock( &mutex_count );
569 WaitForSingleObject( event, INFINITE );
570 RestoreThunkLock( mutex_count );
573 /***********************************************************************
574 * VWin32_EventSet (KERNEL.451)
575 * KERNEL_479 (KERNEL.479)
577 VOID WINAPI VWin32_EventSet(HANDLE event)
584 /***********************************************************************
585 * CreateMutexA (KERNEL32.@)
587 HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
589 WCHAR buffer[MAX_PATH];
591 if (!name) return CreateMutexW( sa, owner, NULL );
593 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
595 SetLastError( ERROR_FILENAME_EXCED_RANGE );
598 return CreateMutexW( sa, owner, buffer );
602 /***********************************************************************
603 * CreateMutexW (KERNEL32.@)
605 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
608 DWORD len = name ? strlenW(name) : 0;
611 SetLastError( ERROR_FILENAME_EXCED_RANGE );
614 SERVER_START_REQ( create_mutex )
617 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
618 wine_server_add_data( req, name, len * sizeof(WCHAR) );
620 wine_server_call_err( req );
628 /***********************************************************************
629 * OpenMutexA (KERNEL32.@)
631 HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
633 WCHAR buffer[MAX_PATH];
635 if (!name) return OpenMutexW( access, inherit, NULL );
637 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
639 SetLastError( ERROR_FILENAME_EXCED_RANGE );
642 return OpenMutexW( access, inherit, buffer );
646 /***********************************************************************
647 * OpenMutexW (KERNEL32.@)
649 HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
652 DWORD len = name ? strlenW(name) : 0;
655 SetLastError( ERROR_FILENAME_EXCED_RANGE );
658 if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
660 SERVER_START_REQ( open_mutex )
662 req->access = access;
663 req->inherit = inherit;
664 wine_server_add_data( req, name, len * sizeof(WCHAR) );
665 wine_server_call_err( req );
673 /***********************************************************************
674 * ReleaseMutex (KERNEL32.@)
676 BOOL WINAPI ReleaseMutex( HANDLE handle )
679 SERVER_START_REQ( release_mutex )
681 req->handle = handle;
682 ret = !wine_server_call_err( req );
694 /***********************************************************************
695 * CreateSemaphoreA (KERNEL32.@)
697 HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
699 WCHAR buffer[MAX_PATH];
701 if (!name) return CreateSemaphoreW( sa, initial, max, NULL );
703 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
705 SetLastError( ERROR_FILENAME_EXCED_RANGE );
708 return CreateSemaphoreW( sa, initial, max, buffer );
712 /***********************************************************************
713 * CreateSemaphoreW (KERNEL32.@)
715 HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
716 LONG max, LPCWSTR name )
719 DWORD len = name ? strlenW(name) : 0;
721 /* Check parameters */
723 if ((max <= 0) || (initial < 0) || (initial > max))
725 SetLastError( ERROR_INVALID_PARAMETER );
730 SetLastError( ERROR_FILENAME_EXCED_RANGE );
734 SERVER_START_REQ( create_semaphore )
736 req->initial = (unsigned int)initial;
737 req->max = (unsigned int)max;
738 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
739 wine_server_add_data( req, name, len * sizeof(WCHAR) );
741 wine_server_call_err( req );
749 /***********************************************************************
750 * OpenSemaphoreA (KERNEL32.@)
752 HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
754 WCHAR buffer[MAX_PATH];
756 if (!name) return OpenSemaphoreW( access, inherit, NULL );
758 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
760 SetLastError( ERROR_FILENAME_EXCED_RANGE );
763 return OpenSemaphoreW( access, inherit, buffer );
767 /***********************************************************************
768 * OpenSemaphoreW (KERNEL32.@)
770 HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
773 DWORD len = name ? strlenW(name) : 0;
776 SetLastError( ERROR_FILENAME_EXCED_RANGE );
779 if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
781 SERVER_START_REQ( open_semaphore )
783 req->access = access;
784 req->inherit = inherit;
785 wine_server_add_data( req, name, len * sizeof(WCHAR) );
786 wine_server_call_err( req );
794 /***********************************************************************
795 * ReleaseSemaphore (KERNEL32.@)
797 BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
799 NTSTATUS status = NtReleaseSemaphore( handle, count, previous );
800 if (status) SetLastError( RtlNtStatusToDosError(status) );
810 /***********************************************************************
811 * CreateWaitableTimerA (KERNEL32.@)
813 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
815 WCHAR buffer[MAX_PATH];
817 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
819 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
821 SetLastError( ERROR_FILENAME_EXCED_RANGE );
824 return CreateWaitableTimerW( sa, manual, buffer );
828 /***********************************************************************
829 * CreateWaitableTimerW (KERNEL32.@)
831 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
837 OBJECT_ATTRIBUTES oa;
839 if (name) RtlInitUnicodeString(&us, name);
840 if (sa && (sa->nLength >= sizeof(*sa)) && sa->bInheritHandle)
842 InitializeObjectAttributes(&oa, name ? &us : NULL, attr,
843 NULL /* FIXME */, NULL /* FIXME */);
844 status = NtCreateTimer(&handle, TIMER_ALL_ACCESS, &oa,
845 manual ? NotificationTimer : SynchronizationTimer);
847 if (status != STATUS_SUCCESS)
849 SetLastError( RtlNtStatusToDosError(status) );
856 /***********************************************************************
857 * OpenWaitableTimerA (KERNEL32.@)
859 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
861 WCHAR buffer[MAX_PATH];
863 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
865 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
867 SetLastError( ERROR_FILENAME_EXCED_RANGE );
870 return OpenWaitableTimerW( access, inherit, buffer );
874 /***********************************************************************
875 * OpenWaitableTimerW (KERNEL32.@)
877 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
883 OBJECT_ATTRIBUTES oa;
885 if (inherit) attr |= OBJ_INHERIT;
887 if (name) RtlInitUnicodeString(&us, name);
888 InitializeObjectAttributes(&oa, name ? &us : NULL, attr, NULL /* FIXME */, NULL /* FIXME */);
889 status = NtOpenTimer(&handle, access, &oa);
890 if (status != STATUS_SUCCESS)
892 SetLastError( RtlNtStatusToDosError(status) );
899 /***********************************************************************
900 * SetWaitableTimer (KERNEL32.@)
902 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
903 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
905 NTSTATUS status = NtSetTimer(handle, when, callback, arg, resume, period, NULL);
907 if (status != STATUS_SUCCESS)
909 SetLastError( RtlNtStatusToDosError(status) );
910 if (status != STATUS_TIMER_RESUME_IGNORED) return FALSE;
916 /***********************************************************************
917 * CancelWaitableTimer (KERNEL32.@)
919 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
923 status = NtCancelTimer(handle, NULL);
924 if (status != STATUS_SUCCESS)
926 SetLastError( RtlNtStatusToDosError(status) );
933 /***********************************************************************
934 * CreateTimerQueue (KERNEL32.@)
936 HANDLE WINAPI CreateTimerQueue(void)
939 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
944 /***********************************************************************
945 * DeleteTimerQueueEx (KERNEL32.@)
947 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
949 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
950 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
954 /***********************************************************************
955 * CreateTimerQueueTimer (KERNEL32.@)
957 * Creates a timer-queue timer. This timer expires at the specified due
958 * time (in ms), then after every specified period (in ms). When the timer
959 * expires, the callback function is called.
962 * nonzero on success or zero on faillure
967 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
968 WAITORTIMERCALLBACK Callback, PVOID Parameter,
969 DWORD DueTime, DWORD Period, ULONG Flags )
972 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
976 /***********************************************************************
977 * DeleteTimerQueueTimer (KERNEL32.@)
979 * Cancels a timer-queue timer.
982 * nonzero on success or zero on faillure
987 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
988 HANDLE CompletionEvent )
991 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1001 /***********************************************************************
1002 * CreateNamedPipeA (KERNEL32.@)
1004 HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
1005 DWORD dwPipeMode, DWORD nMaxInstances,
1006 DWORD nOutBufferSize, DWORD nInBufferSize,
1007 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1009 WCHAR buffer[MAX_PATH];
1011 if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
1012 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1014 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1016 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1017 return INVALID_HANDLE_VALUE;
1019 return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
1020 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1024 /***********************************************************************
1025 * CreateNamedPipeW (KERNEL32.@)
1027 HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
1028 DWORD dwPipeMode, DWORD nMaxInstances,
1029 DWORD nOutBufferSize, DWORD nInBufferSize,
1030 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1034 static const WCHAR leadin[] = {'\\','\\','.','\\','P','I','P','E','\\'};
1036 TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
1037 debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
1038 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1042 SetLastError( ERROR_PATH_NOT_FOUND );
1043 return INVALID_HANDLE_VALUE;
1045 len = strlenW(name);
1046 if (len >= MAX_PATH)
1048 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1049 return INVALID_HANDLE_VALUE;
1051 if (strncmpiW(name, leadin, sizeof(leadin)/sizeof(leadin[0])))
1053 SetLastError( ERROR_INVALID_NAME );
1054 return INVALID_HANDLE_VALUE;
1056 SERVER_START_REQ( create_named_pipe )
1058 req->openmode = dwOpenMode;
1059 req->pipemode = dwPipeMode;
1060 req->maxinstances = nMaxInstances;
1061 req->outsize = nOutBufferSize;
1062 req->insize = nInBufferSize;
1063 req->timeout = nDefaultTimeOut;
1064 req->inherit = (attr && (attr->nLength>=sizeof(*attr)) && attr->bInheritHandle);
1065 wine_server_add_data( req, name, len * sizeof(WCHAR) );
1067 if (!wine_server_call_err( req )) ret = reply->handle;
1068 else ret = INVALID_HANDLE_VALUE;
1075 /***********************************************************************
1076 * PeekNamedPipe (KERNEL32.@)
1078 BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
1079 LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
1082 int avail=0, fd, ret, flags;
1084 ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, NULL, &flags );
1087 SetLastError( RtlNtStatusToDosError(ret) );
1090 if (flags & FD_FLAG_RECV_SHUTDOWN)
1092 wine_server_release_fd( hPipe, fd );
1093 SetLastError ( ERROR_PIPE_NOT_CONNECTED );
1097 if (ioctl(fd,FIONREAD, &avail ) != 0)
1099 TRACE("FIONREAD failed reason: %s\n",strerror(errno));
1100 wine_server_release_fd( hPipe, fd );
1103 if (!avail) /* check for closed pipe */
1105 struct pollfd pollfd;
1107 pollfd.events = POLLIN;
1109 switch (poll( &pollfd, 1, 0 ))
1113 case 1: /* got something */
1114 if (!(pollfd.revents & (POLLHUP | POLLERR))) break;
1115 TRACE("POLLHUP | POLLERR\n");
1118 wine_server_release_fd( hPipe, fd );
1119 SetLastError(ERROR_BROKEN_PIPE);
1123 TRACE(" 0x%08x bytes available\n", avail );
1129 if (avail && lpvBuffer)
1131 int readbytes = (avail < cbBuffer) ? avail : cbBuffer;
1132 readbytes = recv(fd, lpvBuffer, readbytes, MSG_PEEK);
1135 WARN("failed to peek socket (%d)\n", errno);
1139 *lpcbRead = readbytes;
1141 wine_server_release_fd( hPipe, fd );
1143 #endif /* defined(FIONREAD) */
1145 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1146 FIXME("function not implemented\n");
1150 /***********************************************************************
1151 * SYNC_CompletePipeOverlapped (Internal)
1153 static void SYNC_CompletePipeOverlapped (LPOVERLAPPED overlapped, DWORD result)
1155 TRACE("for %p result %08lx\n",overlapped,result);
1158 overlapped->Internal = result;
1159 SetEvent(overlapped->hEvent);
1163 /***********************************************************************
1164 * WaitNamedPipeA (KERNEL32.@)
1166 BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
1168 WCHAR buffer[MAX_PATH];
1170 if (!name) return WaitNamedPipeW( NULL, nTimeOut );
1172 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1174 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1177 return WaitNamedPipeW( buffer, nTimeOut );
1181 /***********************************************************************
1182 * WaitNamedPipeW (KERNEL32.@)
1184 BOOL WINAPI WaitNamedPipeW (LPCWSTR name, DWORD nTimeOut)
1186 DWORD len = name ? strlenW(name) : 0;
1190 if (len >= MAX_PATH)
1192 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1196 TRACE("%s 0x%08lx\n",debugstr_w(name),nTimeOut);
1198 memset(&ov,0,sizeof(ov));
1199 ov.hEvent = CreateEventA( NULL, 0, 0, NULL );
1203 SERVER_START_REQ( wait_named_pipe )
1205 req->timeout = nTimeOut;
1206 req->overlapped = &ov;
1207 req->func = SYNC_CompletePipeOverlapped;
1208 wine_server_add_data( req, name, len * sizeof(WCHAR) );
1209 ret = !wine_server_call_err( req );
1215 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1217 SetLastError(ov.Internal);
1218 ret = (ov.Internal==STATUS_SUCCESS);
1221 CloseHandle(ov.hEvent);
1226 /***********************************************************************
1227 * SYNC_ConnectNamedPipe (Internal)
1229 static BOOL SYNC_ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1236 overlapped->Internal = STATUS_PENDING;
1238 SERVER_START_REQ( connect_named_pipe )
1240 req->handle = hPipe;
1241 req->overlapped = overlapped;
1242 req->func = SYNC_CompletePipeOverlapped;
1243 ret = !wine_server_call_err( req );
1250 /***********************************************************************
1251 * ConnectNamedPipe (KERNEL32.@)
1253 BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1258 TRACE("(%p,%p)\n",hPipe, overlapped);
1262 if(SYNC_ConnectNamedPipe(hPipe,overlapped))
1263 SetLastError( ERROR_IO_PENDING );
1267 memset(&ov,0,sizeof(ov));
1268 ov.hEvent = CreateEventA(NULL,0,0,NULL);
1272 ret=SYNC_ConnectNamedPipe(hPipe, &ov);
1275 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1277 SetLastError(ov.Internal);
1278 ret = (ov.Internal==STATUS_SUCCESS);
1282 CloseHandle(ov.hEvent);
1287 /***********************************************************************
1288 * DisconnectNamedPipe (KERNEL32.@)
1290 BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
1294 TRACE("(%p)\n",hPipe);
1296 SERVER_START_REQ( disconnect_named_pipe )
1298 req->handle = hPipe;
1299 ret = !wine_server_call_err( req );
1300 if (ret && reply->fd != -1) close( reply->fd );
1307 /***********************************************************************
1308 * TransactNamedPipe (KERNEL32.@)
1310 BOOL WINAPI TransactNamedPipe(
1311 HANDLE hPipe, LPVOID lpInput, DWORD dwInputSize, LPVOID lpOutput,
1312 DWORD dwOutputSize, LPDWORD lpBytesRead, LPOVERLAPPED lpOverlapped)
1314 FIXME("%p %p %ld %p %ld %p %p\n",
1315 hPipe, lpInput, dwInputSize, lpOutput,
1316 dwOutputSize, lpBytesRead, lpOverlapped);
1322 /***********************************************************************
1323 * GetNamedPipeInfo (KERNEL32.@)
1325 BOOL WINAPI GetNamedPipeInfo(
1326 HANDLE hNamedPipe, LPDWORD lpFlags, LPDWORD lpOutputBufferSize,
1327 LPDWORD lpInputBufferSize, LPDWORD lpMaxInstances)
1331 TRACE("%p %p %p %p %p\n", hNamedPipe, lpFlags,
1332 lpOutputBufferSize, lpInputBufferSize, lpMaxInstances);
1334 SERVER_START_REQ( get_named_pipe_info )
1336 req->handle = hNamedPipe;
1337 ret = !wine_server_call_err( req );
1338 if(lpFlags) *lpFlags = reply->flags;
1339 if(lpOutputBufferSize) *lpOutputBufferSize = reply->outsize;
1340 if(lpInputBufferSize) *lpInputBufferSize = reply->outsize;
1341 if(lpMaxInstances) *lpMaxInstances = reply->maxinstances;
1348 /***********************************************************************
1349 * GetNamedPipeHandleStateA (KERNEL32.@)
1351 BOOL WINAPI GetNamedPipeHandleStateA(
1352 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1353 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1354 LPSTR lpUsername, DWORD nUsernameMaxSize)
1356 FIXME("%p %p %p %p %p %p %ld\n",
1357 hNamedPipe, lpState, lpCurInstances,
1358 lpMaxCollectionCount, lpCollectDataTimeout,
1359 lpUsername, nUsernameMaxSize);
1364 /***********************************************************************
1365 * GetNamedPipeHandleStateW (KERNEL32.@)
1367 BOOL WINAPI GetNamedPipeHandleStateW(
1368 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1369 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1370 LPWSTR lpUsername, DWORD nUsernameMaxSize)
1372 FIXME("%p %p %p %p %p %p %ld\n",
1373 hNamedPipe, lpState, lpCurInstances,
1374 lpMaxCollectionCount, lpCollectDataTimeout,
1375 lpUsername, nUsernameMaxSize);
1380 /***********************************************************************
1381 * SetNamedPipeHandleState (KERNEL32.@)
1383 BOOL WINAPI SetNamedPipeHandleState(
1384 HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount,
1385 LPDWORD lpCollectDataTimeout)
1387 FIXME("%p %p %p %p\n",
1388 hNamedPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout);
1392 /***********************************************************************
1393 * CallNamedPipeA (KERNEL32.@)
1395 BOOL WINAPI CallNamedPipeA(
1396 LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
1397 LPVOID lpOutput, DWORD lpOutputSize,
1398 LPDWORD lpBytesRead, DWORD nTimeout)
1400 FIXME("%s %p %ld %p %ld %p %ld\n",
1401 debugstr_a(lpNamedPipeName), lpInput, lpInputSize,
1402 lpOutput, lpOutputSize, lpBytesRead, nTimeout);
1406 /***********************************************************************
1407 * CallNamedPipeW (KERNEL32.@)
1409 BOOL WINAPI CallNamedPipeW(
1410 LPCWSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
1411 LPVOID lpOutput, DWORD lpOutputSize,
1412 LPDWORD lpBytesRead, DWORD nTimeout)
1414 FIXME("%s %p %ld %p %ld %p %ld\n",
1415 debugstr_w(lpNamedPipeName), lpInput, lpInputSize,
1416 lpOutput, lpOutputSize, lpBytesRead, nTimeout);
1420 /******************************************************************
1421 * CreatePipe (KERNEL32.@)
1424 BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
1425 LPSECURITY_ATTRIBUTES sa, DWORD size )
1427 static unsigned index = 0;
1430 unsigned in_index = index;
1432 *hReadPipe = *hWritePipe = INVALID_HANDLE_VALUE;
1433 /* generate a unique pipe name (system wide) */
1436 sprintf(name, "\\\\.\\pipe\\Win32.Pipes.%08lu.%08u", GetCurrentProcessId(), ++index);
1437 hr = CreateNamedPipeA(name, PIPE_ACCESS_INBOUND,
1438 PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size,
1439 NMPWAIT_USE_DEFAULT_WAIT, sa);
1440 } while (hr == INVALID_HANDLE_VALUE && index != in_index);
1441 /* from completion sakeness, I think system resources might be exhausted before this happens !! */
1442 if (hr == INVALID_HANDLE_VALUE) return FALSE;
1444 hw = CreateFileA(name, GENERIC_WRITE, 0, sa, OPEN_EXISTING, 0, 0);
1445 if (hw == INVALID_HANDLE_VALUE)
1457 /******************************************************************************
1458 * CreateMailslotA [KERNEL32.@]
1460 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
1461 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1467 TRACE("%s %ld %ld %p\n", debugstr_a(lpName),
1468 nMaxMessageSize, lReadTimeout, sa);
1472 len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
1473 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1474 MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
1477 handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
1480 HeapFree( GetProcessHeap(), 0, name );
1486 /******************************************************************************
1487 * CreateMailslotW [KERNEL32.@]
1489 * Create a mailslot with specified name.
1492 * lpName [I] Pointer to string for mailslot name
1493 * nMaxMessageSize [I] Maximum message size
1494 * lReadTimeout [I] Milliseconds before read time-out
1495 * sa [I] Pointer to security structure
1498 * Success: Handle to mailslot
1499 * Failure: INVALID_HANDLE_VALUE
1501 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
1502 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1504 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
1505 nMaxMessageSize, lReadTimeout, sa);
1506 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1507 return INVALID_HANDLE_VALUE;
1511 /******************************************************************************
1512 * GetMailslotInfo [KERNEL32.@]
1514 * Retrieve information about a mailslot.
1517 * hMailslot [I] Mailslot handle
1518 * lpMaxMessageSize [O] Address of maximum message size
1519 * lpNextSize [O] Address of size of next message
1520 * lpMessageCount [O] Address of number of messages
1521 * lpReadTimeout [O] Address of read time-out
1527 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
1528 LPDWORD lpNextSize, LPDWORD lpMessageCount,
1529 LPDWORD lpReadTimeout )
1531 FIXME("(%p): stub\n",hMailslot);
1532 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1537 /******************************************************************************
1538 * SetMailslotInfo [KERNEL32.@]
1540 * Set the read timeout of a mailslot.
1543 * hMailslot [I] Mailslot handle
1544 * dwReadTimeout [I] Timeout in milliseconds.
1550 BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
1552 FIXME("%p %ld: stub\n", hMailslot, dwReadTimeout);
1553 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1558 /******************************************************************************
1559 * CreateIoCompletionPort (KERNEL32.@)
1561 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle, HANDLE hExistingCompletionPort,
1562 DWORD dwCompletionKey, DWORD dwNumberOfConcurrentThreads)
1564 FIXME("(%p, %p, %08lx, %08lx): stub.\n",
1565 hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
1570 /******************************************************************************
1571 * GetQueuedCompletionStatus (KERNEL32.@)
1573 BOOL WINAPI GetQueuedCompletionStatus( HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
1574 LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped,
1575 DWORD dwMilliseconds )
1577 FIXME("(%p,%p,%p,%p,%ld), stub!\n",
1578 CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
1579 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1583 /******************************************************************************
1584 * CreateJobObjectW (KERNEL32.@)
1586 HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES attr, LPCWSTR name )
1588 FIXME("%p %s\n", attr, debugstr_w(name) );
1589 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1593 /******************************************************************************
1594 * CreateJobObjectA (KERNEL32.@)
1596 HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
1602 TRACE("%p %s\n", attr, debugstr_a(name) );
1606 len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1607 str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1610 SetLastError( ERROR_OUTOFMEMORY );
1613 len = MultiByteToWideChar( CP_ACP, 0, name, -1, str, len );
1616 r = CreateJobObjectW( attr, str );
1619 HeapFree( GetProcessHeap(), 0, str );
1624 /******************************************************************************
1625 * AssignProcessToJobObject (KERNEL32.@)
1627 BOOL WINAPI AssignProcessToJobObject( HANDLE hJob, HANDLE hProcess )
1629 FIXME("%p %p\n", hJob, hProcess);
1635 /***********************************************************************
1636 * InterlockedCompareExchange (KERNEL32.@)
1638 /* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
1639 __ASM_GLOBAL_FUNC(InterlockedCompareExchange,
1640 "movl 12(%esp),%eax\n\t"
1641 "movl 8(%esp),%ecx\n\t"
1642 "movl 4(%esp),%edx\n\t"
1643 "lock; cmpxchgl %ecx,(%edx)\n\t"
1646 /***********************************************************************
1647 * InterlockedExchange (KERNEL32.@)
1649 /* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
1650 __ASM_GLOBAL_FUNC(InterlockedExchange,
1651 "movl 8(%esp),%eax\n\t"
1652 "movl 4(%esp),%edx\n\t"
1653 "lock; xchgl %eax,(%edx)\n\t"
1656 /***********************************************************************
1657 * InterlockedExchangeAdd (KERNEL32.@)
1659 /* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
1660 __ASM_GLOBAL_FUNC(InterlockedExchangeAdd,
1661 "movl 8(%esp),%eax\n\t"
1662 "movl 4(%esp),%edx\n\t"
1663 "lock; xaddl %eax,(%edx)\n\t"
1666 /***********************************************************************
1667 * InterlockedIncrement (KERNEL32.@)
1669 /* LONG WINAPI InterlockedIncrement( PLONG dest ); */
1670 __ASM_GLOBAL_FUNC(InterlockedIncrement,
1671 "movl 4(%esp),%edx\n\t"
1673 "lock; xaddl %eax,(%edx)\n\t"
1677 /***********************************************************************
1678 * InterlockedDecrement (KERNEL32.@)
1680 __ASM_GLOBAL_FUNC(InterlockedDecrement,
1681 "movl 4(%esp),%edx\n\t"
1683 "lock; xaddl %eax,(%edx)\n\t"
1687 #else /* __i386__ */
1689 /***********************************************************************
1690 * InterlockedCompareExchange (KERNEL32.@)
1692 * Atomically swap one value with another.
1695 * dest [I/O] The value to replace
1696 * xchq [I] The value to be swapped
1697 * compare [I] The value to compare to dest
1700 * The resulting value of dest.
1703 * dest is updated only if it is equal to compare, otherwise no swap is done.
1705 LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
1707 return interlocked_cmpxchg( dest, xchg, compare );
1710 /***********************************************************************
1711 * InterlockedExchange (KERNEL32.@)
1713 * Atomically swap one value with another.
1716 * dest [I/O] The value to replace
1717 * val [I] The value to be swapped
1720 * The resulting value of dest.
1722 LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
1724 return interlocked_xchg( dest, val );
1727 /***********************************************************************
1728 * InterlockedExchangeAdd (KERNEL32.@)
1730 * Atomically add one value to another.
1733 * dest [I/O] The value to add to
1734 * incr [I] The value to be added
1737 * The resulting value of dest.
1739 LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
1741 return interlocked_xchg_add( dest, incr );
1744 /***********************************************************************
1745 * InterlockedIncrement (KERNEL32.@)
1747 * Atomically increment a value.
1750 * dest [I/O] The value to increment
1753 * The resulting value of dest.
1755 LONG WINAPI InterlockedIncrement( PLONG dest )
1757 return interlocked_xchg_add( dest, 1 ) + 1;
1760 /***********************************************************************
1761 * InterlockedDecrement (KERNEL32.@)
1763 * Atomically decrement a value.
1766 * dest [I/O] The value to decrement
1769 * The resulting value of dest.
1771 LONG WINAPI InterlockedDecrement( PLONG dest )
1773 return interlocked_xchg_add( dest, -1 ) - 1;
1776 #endif /* __i386__ */