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"
53 #include "wine/debug.h"
55 WINE_DEFAULT_DEBUG_CHANNEL(sync);
57 /* check if current version is NT or Win95 */
58 inline static int is_version_nt(void)
60 return !(GetVersion() & 0x80000000);
64 /***********************************************************************
67 VOID WINAPI Sleep( DWORD timeout )
69 SleepEx( timeout, FALSE );
72 /******************************************************************************
73 * SleepEx (KERNEL32.@)
75 DWORD WINAPI SleepEx( DWORD timeout, BOOL alertable )
79 if (timeout == INFINITE) status = NtDelayExecution( alertable, NULL );
84 time.QuadPart = timeout * (ULONGLONG)10000;
85 time.QuadPart = -time.QuadPart;
86 status = NtDelayExecution( alertable, &time );
88 if (status != STATUS_USER_APC) status = STATUS_SUCCESS;
93 /***********************************************************************
94 * WaitForSingleObject (KERNEL32.@)
96 DWORD WINAPI WaitForSingleObject( HANDLE handle, DWORD timeout )
98 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, FALSE );
102 /***********************************************************************
103 * WaitForSingleObjectEx (KERNEL32.@)
105 DWORD WINAPI WaitForSingleObjectEx( HANDLE handle, DWORD timeout,
108 return WaitForMultipleObjectsEx( 1, &handle, FALSE, timeout, alertable );
112 /***********************************************************************
113 * WaitForMultipleObjects (KERNEL32.@)
115 DWORD WINAPI WaitForMultipleObjects( DWORD count, const HANDLE *handles,
116 BOOL wait_all, DWORD timeout )
118 return WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
122 /***********************************************************************
123 * WaitForMultipleObjectsEx (KERNEL32.@)
125 DWORD WINAPI WaitForMultipleObjectsEx( DWORD count, const HANDLE *handles,
126 BOOL wait_all, DWORD timeout,
130 HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
133 if (count >= MAXIMUM_WAIT_OBJECTS)
135 SetLastError(ERROR_INVALID_PARAMETER);
138 for (i = 0; i < count; i++)
140 if ((handles[i] == (HANDLE)STD_INPUT_HANDLE) ||
141 (handles[i] == (HANDLE)STD_OUTPUT_HANDLE) ||
142 (handles[i] == (HANDLE)STD_ERROR_HANDLE))
143 hloc[i] = GetStdHandle( (DWORD)handles[i] );
145 hloc[i] = handles[i];
147 /* yes, even screen buffer console handles are waitable, and are
148 * handled as a handle to the console itself !!
150 if (is_console_handle(hloc[i]))
152 if (!VerifyConsoleIoHandle(hloc[i]))
156 hloc[i] = GetConsoleInputWaitHandle();
160 if (timeout == INFINITE)
162 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, NULL );
168 time.QuadPart = timeout * (ULONGLONG)10000;
169 time.QuadPart = -time.QuadPart;
170 status = NtWaitForMultipleObjects( count, hloc, wait_all, alertable, &time );
173 if (HIWORD(status)) /* is it an error code? */
175 SetLastError( RtlNtStatusToDosError(status) );
176 status = WAIT_FAILED;
182 /***********************************************************************
183 * WaitForSingleObject (KERNEL.460)
185 DWORD WINAPI WaitForSingleObject16( HANDLE handle, DWORD timeout )
187 DWORD retval, mutex_count;
189 ReleaseThunkLock( &mutex_count );
190 retval = WaitForSingleObject( handle, timeout );
191 RestoreThunkLock( mutex_count );
195 /***********************************************************************
196 * WaitForMultipleObjects (KERNEL.461)
198 DWORD WINAPI WaitForMultipleObjects16( DWORD count, const HANDLE *handles,
199 BOOL wait_all, DWORD timeout )
201 DWORD retval, mutex_count;
203 ReleaseThunkLock( &mutex_count );
204 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, FALSE );
205 RestoreThunkLock( mutex_count );
209 /***********************************************************************
210 * WaitForMultipleObjectsEx (KERNEL.495)
212 DWORD WINAPI WaitForMultipleObjectsEx16( DWORD count, const HANDLE *handles,
213 BOOL wait_all, DWORD timeout, BOOL alertable )
215 DWORD retval, mutex_count;
217 ReleaseThunkLock( &mutex_count );
218 retval = WaitForMultipleObjectsEx( count, handles, wait_all, timeout, alertable );
219 RestoreThunkLock( mutex_count );
223 /***********************************************************************
224 * RegisterWaitForSingleObject (KERNEL32.@)
226 BOOL WINAPI RegisterWaitForSingleObject(PHANDLE phNewWaitObject, HANDLE hObject,
227 WAITORTIMERCALLBACK Callback, PVOID Context,
228 ULONG dwMilliseconds, ULONG dwFlags)
230 FIXME("%p %p %p %p %ld %ld\n",
231 phNewWaitObject,hObject,Callback,Context,dwMilliseconds,dwFlags);
235 /***********************************************************************
236 * RegisterWaitForSingleObjectEx (KERNEL32.@)
238 BOOL WINAPI RegisterWaitForSingleObjectEx( HANDLE hObject,
239 WAITORTIMERCALLBACK Callback, PVOID Context,
240 ULONG dwMilliseconds, ULONG dwFlags )
242 FIXME("%p %p %p %ld %ld\n",
243 hObject,Callback,Context,dwMilliseconds,dwFlags);
247 /***********************************************************************
248 * UnregisterWait (KERNEL32.@)
250 BOOL WINAPI UnregisterWait( HANDLE WaitHandle )
252 FIXME("%p\n",WaitHandle);
256 /***********************************************************************
257 * UnregisterWaitEx (KERNEL32.@)
259 BOOL WINAPI UnregisterWaitEx( HANDLE WaitHandle, HANDLE CompletionEvent )
261 FIXME("%p %p\n",WaitHandle, CompletionEvent);
265 /***********************************************************************
266 * InitializeCriticalSection (KERNEL32.@)
268 * Initialise a critical section before use.
271 * crit [O] Critical section to initialise.
274 * Nothing. If the function fails an exception is raised.
276 void WINAPI InitializeCriticalSection( CRITICAL_SECTION *crit )
278 NTSTATUS ret = RtlInitializeCriticalSection( crit );
279 if (ret) RtlRaiseStatus( ret );
282 /***********************************************************************
283 * InitializeCriticalSectionAndSpinCount (KERNEL32.@)
285 * Initialise a critical section with a spin count.
288 * crit [O] Critical section to initialise.
289 * spincount [I] Number of times to spin upon contention.
293 * Failure: Nothing. If the function fails an exception is raised.
296 * spincount is ignored on uni-processor systems.
298 BOOL WINAPI InitializeCriticalSectionAndSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
300 NTSTATUS ret = RtlInitializeCriticalSectionAndSpinCount( crit, spincount );
301 if (ret) RtlRaiseStatus( ret );
305 /***********************************************************************
306 * SetCriticalSectionSpinCount (KERNEL32.@)
308 * Set the spin count for a critical section.
311 * crit [O] Critical section to set the spin count for.
312 * spincount [I] Number of times to spin upon contention.
315 * The previous spin count value of crit.
318 * This function is available on NT4SP3 or later, but not Win98.
320 DWORD WINAPI SetCriticalSectionSpinCount( CRITICAL_SECTION *crit, DWORD spincount )
322 ULONG_PTR oldspincount = crit->SpinCount;
323 if(spincount) FIXME("critsection=%p: spincount=%ld not supported\n", crit, spincount);
324 crit->SpinCount = spincount;
328 /***********************************************************************
329 * MakeCriticalSectionGlobal (KERNEL32.@)
331 void WINAPI MakeCriticalSectionGlobal( CRITICAL_SECTION *crit )
333 /* let's assume that only one thread at a time will try to do this */
334 HANDLE sem = crit->LockSemaphore;
335 if (!sem) NtCreateSemaphore( &sem, SEMAPHORE_ALL_ACCESS, NULL, 0, 1 );
336 crit->LockSemaphore = ConvertToGlobalHandle( sem );
339 RtlFreeHeap( GetProcessHeap(), 0, crit->DebugInfo );
340 crit->DebugInfo = NULL;
345 /***********************************************************************
346 * ReinitializeCriticalSection (KERNEL32.@)
348 * Initialise an already used critical section.
351 * crit [O] Critical section to initialise.
356 void WINAPI ReinitializeCriticalSection( CRITICAL_SECTION *crit )
358 if ( !crit->LockSemaphore )
359 RtlInitializeCriticalSection( crit );
363 /***********************************************************************
364 * UninitializeCriticalSection (KERNEL32.@)
366 * UnInitialise a critical section after use.
369 * crit [O] Critical section to uninitialise (destroy).
374 void WINAPI UninitializeCriticalSection( CRITICAL_SECTION *crit )
376 RtlDeleteCriticalSection( crit );
380 /***********************************************************************
381 * CreateEventA (KERNEL32.@)
383 HANDLE WINAPI CreateEventA( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
384 BOOL initial_state, LPCSTR name )
386 WCHAR buffer[MAX_PATH];
388 if (!name) return CreateEventW( sa, manual_reset, initial_state, NULL );
390 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
392 SetLastError( ERROR_FILENAME_EXCED_RANGE );
395 return CreateEventW( sa, manual_reset, initial_state, buffer );
399 /***********************************************************************
400 * CreateEventW (KERNEL32.@)
402 HANDLE WINAPI CreateEventW( SECURITY_ATTRIBUTES *sa, BOOL manual_reset,
403 BOOL initial_state, LPCWSTR name )
406 DWORD len = name ? strlenW(name) : 0;
409 SetLastError( ERROR_FILENAME_EXCED_RANGE );
412 /* one buggy program needs this
413 * ("Van Dale Groot woordenboek der Nederlandse taal")
415 if (sa && IsBadReadPtr(sa,sizeof(SECURITY_ATTRIBUTES)))
417 ERR("Bad security attributes pointer %p\n",sa);
418 SetLastError( ERROR_INVALID_PARAMETER);
421 SERVER_START_REQ( create_event )
423 req->manual_reset = manual_reset;
424 req->initial_state = initial_state;
425 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
426 wine_server_add_data( req, name, len * sizeof(WCHAR) );
428 wine_server_call_err( req );
436 /***********************************************************************
437 * CreateW32Event (KERNEL.457)
439 HANDLE WINAPI WIN16_CreateEvent( BOOL manual_reset, BOOL initial_state )
441 return CreateEventA( NULL, manual_reset, initial_state, NULL );
445 /***********************************************************************
446 * OpenEventA (KERNEL32.@)
448 HANDLE WINAPI OpenEventA( DWORD access, BOOL inherit, LPCSTR name )
450 WCHAR buffer[MAX_PATH];
452 if (!name) return OpenEventW( access, inherit, NULL );
454 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
456 SetLastError( ERROR_FILENAME_EXCED_RANGE );
459 return OpenEventW( access, inherit, buffer );
463 /***********************************************************************
464 * OpenEventW (KERNEL32.@)
466 HANDLE WINAPI OpenEventW( DWORD access, BOOL inherit, LPCWSTR name )
469 DWORD len = name ? strlenW(name) : 0;
472 SetLastError( ERROR_FILENAME_EXCED_RANGE );
475 if (!is_version_nt()) access = EVENT_ALL_ACCESS;
477 SERVER_START_REQ( open_event )
479 req->access = access;
480 req->inherit = inherit;
481 wine_server_add_data( req, name, len * sizeof(WCHAR) );
482 wine_server_call_err( req );
490 /***********************************************************************
493 * Execute an event operation (set,reset,pulse).
495 static BOOL EVENT_Operation( HANDLE handle, enum event_op op )
498 SERVER_START_REQ( event_op )
500 req->handle = handle;
502 ret = !wine_server_call_err( req );
509 /***********************************************************************
510 * PulseEvent (KERNEL32.@)
512 BOOL WINAPI PulseEvent( HANDLE handle )
514 return EVENT_Operation( handle, PULSE_EVENT );
518 /***********************************************************************
519 * SetW32Event (KERNEL.458)
520 * SetEvent (KERNEL32.@)
522 BOOL WINAPI SetEvent( HANDLE handle )
524 return EVENT_Operation( handle, SET_EVENT );
528 /***********************************************************************
529 * ResetW32Event (KERNEL.459)
530 * ResetEvent (KERNEL32.@)
532 BOOL WINAPI ResetEvent( HANDLE handle )
534 return EVENT_Operation( handle, RESET_EVENT );
538 /***********************************************************************
539 * NOTE: The Win95 VWin32_Event routines given below are really low-level
540 * routines implemented directly by VWin32. The user-mode libraries
541 * implement Win32 synchronisation routines on top of these low-level
542 * primitives. We do it the other way around here :-)
545 /***********************************************************************
546 * VWin32_EventCreate (KERNEL.442)
548 HANDLE WINAPI VWin32_EventCreate(VOID)
550 HANDLE hEvent = CreateEventA( NULL, FALSE, 0, NULL );
551 return ConvertToGlobalHandle( hEvent );
554 /***********************************************************************
555 * VWin32_EventDestroy (KERNEL.443)
557 VOID WINAPI VWin32_EventDestroy(HANDLE event)
559 CloseHandle( event );
562 /***********************************************************************
563 * VWin32_EventWait (KERNEL.450)
565 VOID WINAPI VWin32_EventWait(HANDLE event)
569 ReleaseThunkLock( &mutex_count );
570 WaitForSingleObject( event, INFINITE );
571 RestoreThunkLock( mutex_count );
574 /***********************************************************************
575 * VWin32_EventSet (KERNEL.451)
576 * KERNEL_479 (KERNEL.479)
578 VOID WINAPI VWin32_EventSet(HANDLE event)
585 /***********************************************************************
586 * CreateMutexA (KERNEL32.@)
588 HANDLE WINAPI CreateMutexA( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCSTR name )
590 WCHAR buffer[MAX_PATH];
592 if (!name) return CreateMutexW( sa, owner, NULL );
594 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
596 SetLastError( ERROR_FILENAME_EXCED_RANGE );
599 return CreateMutexW( sa, owner, buffer );
603 /***********************************************************************
604 * CreateMutexW (KERNEL32.@)
606 HANDLE WINAPI CreateMutexW( SECURITY_ATTRIBUTES *sa, BOOL owner, LPCWSTR name )
609 DWORD len = name ? strlenW(name) : 0;
612 SetLastError( ERROR_FILENAME_EXCED_RANGE );
615 SERVER_START_REQ( create_mutex )
618 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
619 wine_server_add_data( req, name, len * sizeof(WCHAR) );
621 wine_server_call_err( req );
629 /***********************************************************************
630 * OpenMutexA (KERNEL32.@)
632 HANDLE WINAPI OpenMutexA( DWORD access, BOOL inherit, LPCSTR name )
634 WCHAR buffer[MAX_PATH];
636 if (!name) return OpenMutexW( access, inherit, NULL );
638 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
640 SetLastError( ERROR_FILENAME_EXCED_RANGE );
643 return OpenMutexW( access, inherit, buffer );
647 /***********************************************************************
648 * OpenMutexW (KERNEL32.@)
650 HANDLE WINAPI OpenMutexW( DWORD access, BOOL inherit, LPCWSTR name )
653 DWORD len = name ? strlenW(name) : 0;
656 SetLastError( ERROR_FILENAME_EXCED_RANGE );
659 if (!is_version_nt()) access = MUTEX_ALL_ACCESS;
661 SERVER_START_REQ( open_mutex )
663 req->access = access;
664 req->inherit = inherit;
665 wine_server_add_data( req, name, len * sizeof(WCHAR) );
666 wine_server_call_err( req );
674 /***********************************************************************
675 * ReleaseMutex (KERNEL32.@)
677 BOOL WINAPI ReleaseMutex( HANDLE handle )
680 SERVER_START_REQ( release_mutex )
682 req->handle = handle;
683 ret = !wine_server_call_err( req );
695 /***********************************************************************
696 * CreateSemaphoreA (KERNEL32.@)
698 HANDLE WINAPI CreateSemaphoreA( SECURITY_ATTRIBUTES *sa, LONG initial, LONG max, LPCSTR name )
700 WCHAR buffer[MAX_PATH];
702 if (!name) return CreateSemaphoreW( sa, initial, max, NULL );
704 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
706 SetLastError( ERROR_FILENAME_EXCED_RANGE );
709 return CreateSemaphoreW( sa, initial, max, buffer );
713 /***********************************************************************
714 * CreateSemaphoreW (KERNEL32.@)
716 HANDLE WINAPI CreateSemaphoreW( SECURITY_ATTRIBUTES *sa, LONG initial,
717 LONG max, LPCWSTR name )
720 DWORD len = name ? strlenW(name) : 0;
722 /* Check parameters */
724 if ((max <= 0) || (initial < 0) || (initial > max))
726 SetLastError( ERROR_INVALID_PARAMETER );
731 SetLastError( ERROR_FILENAME_EXCED_RANGE );
735 SERVER_START_REQ( create_semaphore )
737 req->initial = (unsigned int)initial;
738 req->max = (unsigned int)max;
739 req->inherit = (sa && (sa->nLength>=sizeof(*sa)) && sa->bInheritHandle);
740 wine_server_add_data( req, name, len * sizeof(WCHAR) );
742 wine_server_call_err( req );
750 /***********************************************************************
751 * OpenSemaphoreA (KERNEL32.@)
753 HANDLE WINAPI OpenSemaphoreA( DWORD access, BOOL inherit, LPCSTR name )
755 WCHAR buffer[MAX_PATH];
757 if (!name) return OpenSemaphoreW( access, inherit, NULL );
759 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
761 SetLastError( ERROR_FILENAME_EXCED_RANGE );
764 return OpenSemaphoreW( access, inherit, buffer );
768 /***********************************************************************
769 * OpenSemaphoreW (KERNEL32.@)
771 HANDLE WINAPI OpenSemaphoreW( DWORD access, BOOL inherit, LPCWSTR name )
774 DWORD len = name ? strlenW(name) : 0;
777 SetLastError( ERROR_FILENAME_EXCED_RANGE );
780 if (!is_version_nt()) access = SEMAPHORE_ALL_ACCESS;
782 SERVER_START_REQ( open_semaphore )
784 req->access = access;
785 req->inherit = inherit;
786 wine_server_add_data( req, name, len * sizeof(WCHAR) );
787 wine_server_call_err( req );
795 /***********************************************************************
796 * ReleaseSemaphore (KERNEL32.@)
798 BOOL WINAPI ReleaseSemaphore( HANDLE handle, LONG count, LONG *previous )
800 NTSTATUS status = NtReleaseSemaphore( handle, count, previous );
801 if (status) SetLastError( RtlNtStatusToDosError(status) );
811 /***********************************************************************
812 * CreateWaitableTimerA (KERNEL32.@)
814 HANDLE WINAPI CreateWaitableTimerA( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCSTR name )
816 WCHAR buffer[MAX_PATH];
818 if (!name) return CreateWaitableTimerW( sa, manual, NULL );
820 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
822 SetLastError( ERROR_FILENAME_EXCED_RANGE );
825 return CreateWaitableTimerW( sa, manual, buffer );
829 /***********************************************************************
830 * CreateWaitableTimerW (KERNEL32.@)
832 HANDLE WINAPI CreateWaitableTimerW( SECURITY_ATTRIBUTES *sa, BOOL manual, LPCWSTR name )
838 OBJECT_ATTRIBUTES oa;
840 if (name) RtlInitUnicodeString(&us, name);
841 if (sa && (sa->nLength >= sizeof(*sa)) && sa->bInheritHandle)
843 InitializeObjectAttributes(&oa, name ? &us : NULL, attr,
844 NULL /* FIXME */, NULL /* FIXME */);
845 status = NtCreateTimer(&handle, TIMER_ALL_ACCESS, &oa,
846 manual ? NotificationTimer : SynchronizationTimer);
848 if (status != STATUS_SUCCESS)
850 SetLastError( RtlNtStatusToDosError(status) );
857 /***********************************************************************
858 * OpenWaitableTimerA (KERNEL32.@)
860 HANDLE WINAPI OpenWaitableTimerA( DWORD access, BOOL inherit, LPCSTR name )
862 WCHAR buffer[MAX_PATH];
864 if (!name) return OpenWaitableTimerW( access, inherit, NULL );
866 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
868 SetLastError( ERROR_FILENAME_EXCED_RANGE );
871 return OpenWaitableTimerW( access, inherit, buffer );
875 /***********************************************************************
876 * OpenWaitableTimerW (KERNEL32.@)
878 HANDLE WINAPI OpenWaitableTimerW( DWORD access, BOOL inherit, LPCWSTR name )
884 OBJECT_ATTRIBUTES oa;
886 if (inherit) attr |= OBJ_INHERIT;
888 if (name) RtlInitUnicodeString(&us, name);
889 InitializeObjectAttributes(&oa, name ? &us : NULL, attr, NULL /* FIXME */, NULL /* FIXME */);
890 status = NtOpenTimer(&handle, access, &oa);
891 if (status != STATUS_SUCCESS)
893 SetLastError( RtlNtStatusToDosError(status) );
900 /***********************************************************************
901 * SetWaitableTimer (KERNEL32.@)
903 BOOL WINAPI SetWaitableTimer( HANDLE handle, const LARGE_INTEGER *when, LONG period,
904 PTIMERAPCROUTINE callback, LPVOID arg, BOOL resume )
906 NTSTATUS status = NtSetTimer(handle, when, callback, arg, resume, period, NULL);
908 if (status != STATUS_SUCCESS)
910 SetLastError( RtlNtStatusToDosError(status) );
911 if (status != STATUS_TIMER_RESUME_IGNORED) return FALSE;
917 /***********************************************************************
918 * CancelWaitableTimer (KERNEL32.@)
920 BOOL WINAPI CancelWaitableTimer( HANDLE handle )
924 status = NtCancelTimer(handle, NULL);
925 if (status != STATUS_SUCCESS)
927 SetLastError( RtlNtStatusToDosError(status) );
934 /***********************************************************************
935 * CreateTimerQueue (KERNEL32.@)
937 HANDLE WINAPI CreateTimerQueue(void)
940 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
945 /***********************************************************************
946 * DeleteTimerQueueEx (KERNEL32.@)
948 BOOL WINAPI DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent)
950 FIXME("(%p, %p): stub\n", TimerQueue, CompletionEvent);
951 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
955 /***********************************************************************
956 * CreateTimerQueueTimer (KERNEL32.@)
958 * Creates a timer-queue timer. This timer expires at the specified due
959 * time (in ms), then after every specified period (in ms). When the timer
960 * expires, the callback function is called.
963 * nonzero on success or zero on faillure
968 BOOL WINAPI CreateTimerQueueTimer( PHANDLE phNewTimer, HANDLE TimerQueue,
969 WAITORTIMERCALLBACK Callback, PVOID Parameter,
970 DWORD DueTime, DWORD Period, ULONG Flags )
973 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
977 /***********************************************************************
978 * DeleteTimerQueueTimer (KERNEL32.@)
980 * Cancels a timer-queue timer.
983 * nonzero on success or zero on faillure
988 BOOL WINAPI DeleteTimerQueueTimer( HANDLE TimerQueue, HANDLE Timer,
989 HANDLE CompletionEvent )
992 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1002 /***********************************************************************
1003 * CreateNamedPipeA (KERNEL32.@)
1005 HANDLE WINAPI CreateNamedPipeA( LPCSTR name, DWORD dwOpenMode,
1006 DWORD dwPipeMode, DWORD nMaxInstances,
1007 DWORD nOutBufferSize, DWORD nInBufferSize,
1008 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1010 WCHAR buffer[MAX_PATH];
1012 if (!name) return CreateNamedPipeW( NULL, dwOpenMode, dwPipeMode, nMaxInstances,
1013 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1015 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1017 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1018 return INVALID_HANDLE_VALUE;
1020 return CreateNamedPipeW( buffer, dwOpenMode, dwPipeMode, nMaxInstances,
1021 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1025 /***********************************************************************
1026 * CreateNamedPipeW (KERNEL32.@)
1028 HANDLE WINAPI CreateNamedPipeW( LPCWSTR name, DWORD dwOpenMode,
1029 DWORD dwPipeMode, DWORD nMaxInstances,
1030 DWORD nOutBufferSize, DWORD nInBufferSize,
1031 DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES attr )
1035 static const WCHAR leadin[] = {'\\','\\','.','\\','P','I','P','E','\\'};
1037 TRACE("(%s, %#08lx, %#08lx, %ld, %ld, %ld, %ld, %p)\n",
1038 debugstr_w(name), dwOpenMode, dwPipeMode, nMaxInstances,
1039 nOutBufferSize, nInBufferSize, nDefaultTimeOut, attr );
1043 SetLastError( ERROR_PATH_NOT_FOUND );
1044 return INVALID_HANDLE_VALUE;
1046 len = strlenW(name);
1047 if (len >= MAX_PATH)
1049 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1050 return INVALID_HANDLE_VALUE;
1052 if (strncmpiW(name, leadin, sizeof(leadin)/sizeof(leadin[0])))
1054 SetLastError( ERROR_INVALID_NAME );
1055 return INVALID_HANDLE_VALUE;
1057 SERVER_START_REQ( create_named_pipe )
1059 req->openmode = dwOpenMode;
1060 req->pipemode = dwPipeMode;
1061 req->maxinstances = nMaxInstances;
1062 req->outsize = nOutBufferSize;
1063 req->insize = nInBufferSize;
1064 req->timeout = nDefaultTimeOut;
1065 req->inherit = (attr && (attr->nLength>=sizeof(*attr)) && attr->bInheritHandle);
1066 wine_server_add_data( req, name, len * sizeof(WCHAR) );
1068 if (!wine_server_call_err( req )) ret = reply->handle;
1069 else ret = INVALID_HANDLE_VALUE;
1076 /***********************************************************************
1077 * PeekNamedPipe (KERNEL32.@)
1079 BOOL WINAPI PeekNamedPipe( HANDLE hPipe, LPVOID lpvBuffer, DWORD cbBuffer,
1080 LPDWORD lpcbRead, LPDWORD lpcbAvail, LPDWORD lpcbMessage )
1083 int avail=0, fd, ret, flags;
1085 ret = wine_server_handle_to_fd( hPipe, GENERIC_READ, &fd, NULL, &flags );
1088 SetLastError( RtlNtStatusToDosError(ret) );
1091 if (flags & FD_FLAG_RECV_SHUTDOWN)
1093 wine_server_release_fd( hPipe, fd );
1094 SetLastError ( ERROR_PIPE_NOT_CONNECTED );
1098 if (ioctl(fd,FIONREAD, &avail ) != 0)
1100 TRACE("FIONREAD failed reason: %s\n",strerror(errno));
1101 wine_server_release_fd( hPipe, fd );
1104 if (!avail) /* check for closed pipe */
1106 struct pollfd pollfd;
1108 pollfd.events = POLLIN;
1110 switch (poll( &pollfd, 1, 0 ))
1114 case 1: /* got something */
1115 if (!(pollfd.revents & (POLLHUP | POLLERR))) break;
1116 TRACE("POLLHUP | POLLERR\n");
1119 wine_server_release_fd( hPipe, fd );
1120 SetLastError(ERROR_BROKEN_PIPE);
1124 TRACE(" 0x%08x bytes available\n", avail );
1130 if (avail && lpvBuffer)
1132 int readbytes = (avail < cbBuffer) ? avail : cbBuffer;
1133 readbytes = recv(fd, lpvBuffer, readbytes, MSG_PEEK);
1136 WARN("failed to peek socket (%d)\n", errno);
1140 *lpcbRead = readbytes;
1142 wine_server_release_fd( hPipe, fd );
1144 #endif /* defined(FIONREAD) */
1146 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1147 FIXME("function not implemented\n");
1151 /***********************************************************************
1152 * SYNC_CompletePipeOverlapped (Internal)
1154 static void SYNC_CompletePipeOverlapped (LPOVERLAPPED overlapped, DWORD result)
1156 TRACE("for %p result %08lx\n",overlapped,result);
1159 overlapped->Internal = result;
1160 SetEvent(overlapped->hEvent);
1164 /***********************************************************************
1165 * WaitNamedPipeA (KERNEL32.@)
1167 BOOL WINAPI WaitNamedPipeA (LPCSTR name, DWORD nTimeOut)
1169 WCHAR buffer[MAX_PATH];
1171 if (!name) return WaitNamedPipeW( NULL, nTimeOut );
1173 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, buffer, MAX_PATH ))
1175 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1178 return WaitNamedPipeW( buffer, nTimeOut );
1182 /***********************************************************************
1183 * WaitNamedPipeW (KERNEL32.@)
1185 BOOL WINAPI WaitNamedPipeW (LPCWSTR name, DWORD nTimeOut)
1187 DWORD len = name ? strlenW(name) : 0;
1191 if (len >= MAX_PATH)
1193 SetLastError( ERROR_FILENAME_EXCED_RANGE );
1197 TRACE("%s 0x%08lx\n",debugstr_w(name),nTimeOut);
1199 memset(&ov,0,sizeof(ov));
1200 ov.hEvent = CreateEventA( NULL, 0, 0, NULL );
1204 SERVER_START_REQ( wait_named_pipe )
1206 req->timeout = nTimeOut;
1207 req->overlapped = &ov;
1208 req->func = SYNC_CompletePipeOverlapped;
1209 wine_server_add_data( req, name, len * sizeof(WCHAR) );
1210 ret = !wine_server_call_err( req );
1216 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1218 SetLastError(ov.Internal);
1219 ret = (ov.Internal==STATUS_SUCCESS);
1222 CloseHandle(ov.hEvent);
1227 /***********************************************************************
1228 * SYNC_ConnectNamedPipe (Internal)
1230 static BOOL SYNC_ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1237 overlapped->Internal = STATUS_PENDING;
1239 SERVER_START_REQ( connect_named_pipe )
1241 req->handle = hPipe;
1242 req->overlapped = overlapped;
1243 req->func = SYNC_CompletePipeOverlapped;
1244 ret = !wine_server_call_err( req );
1251 /***********************************************************************
1252 * ConnectNamedPipe (KERNEL32.@)
1254 BOOL WINAPI ConnectNamedPipe(HANDLE hPipe, LPOVERLAPPED overlapped)
1259 TRACE("(%p,%p)\n",hPipe, overlapped);
1263 if(SYNC_ConnectNamedPipe(hPipe,overlapped))
1264 SetLastError( ERROR_IO_PENDING );
1268 memset(&ov,0,sizeof(ov));
1269 ov.hEvent = CreateEventA(NULL,0,0,NULL);
1273 ret=SYNC_ConnectNamedPipe(hPipe, &ov);
1276 if (WAIT_OBJECT_0==WaitForSingleObject(ov.hEvent,INFINITE))
1278 SetLastError(ov.Internal);
1279 ret = (ov.Internal==STATUS_SUCCESS);
1283 CloseHandle(ov.hEvent);
1288 /***********************************************************************
1289 * DisconnectNamedPipe (KERNEL32.@)
1291 BOOL WINAPI DisconnectNamedPipe(HANDLE hPipe)
1295 TRACE("(%p)\n",hPipe);
1297 SERVER_START_REQ( disconnect_named_pipe )
1299 req->handle = hPipe;
1300 ret = !wine_server_call_err( req );
1301 if (ret && reply->fd != -1) close( reply->fd );
1308 /***********************************************************************
1309 * TransactNamedPipe (KERNEL32.@)
1311 BOOL WINAPI TransactNamedPipe(
1312 HANDLE hPipe, LPVOID lpInput, DWORD dwInputSize, LPVOID lpOutput,
1313 DWORD dwOutputSize, LPDWORD lpBytesRead, LPOVERLAPPED lpOverlapped)
1315 FIXME("%p %p %ld %p %ld %p %p\n",
1316 hPipe, lpInput, dwInputSize, lpOutput,
1317 dwOutputSize, lpBytesRead, lpOverlapped);
1323 /***********************************************************************
1324 * GetNamedPipeInfo (KERNEL32.@)
1326 BOOL WINAPI GetNamedPipeInfo(
1327 HANDLE hNamedPipe, LPDWORD lpFlags, LPDWORD lpOutputBufferSize,
1328 LPDWORD lpInputBufferSize, LPDWORD lpMaxInstances)
1332 TRACE("%p %p %p %p %p\n", hNamedPipe, lpFlags,
1333 lpOutputBufferSize, lpInputBufferSize, lpMaxInstances);
1335 SERVER_START_REQ( get_named_pipe_info )
1337 req->handle = hNamedPipe;
1338 ret = !wine_server_call_err( req );
1339 if(lpFlags) *lpFlags = reply->flags;
1340 if(lpOutputBufferSize) *lpOutputBufferSize = reply->outsize;
1341 if(lpInputBufferSize) *lpInputBufferSize = reply->outsize;
1342 if(lpMaxInstances) *lpMaxInstances = reply->maxinstances;
1349 /***********************************************************************
1350 * GetNamedPipeHandleStateA (KERNEL32.@)
1352 BOOL WINAPI GetNamedPipeHandleStateA(
1353 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1354 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1355 LPSTR lpUsername, DWORD nUsernameMaxSize)
1357 FIXME("%p %p %p %p %p %p %ld\n",
1358 hNamedPipe, lpState, lpCurInstances,
1359 lpMaxCollectionCount, lpCollectDataTimeout,
1360 lpUsername, nUsernameMaxSize);
1365 /***********************************************************************
1366 * GetNamedPipeHandleStateW (KERNEL32.@)
1368 BOOL WINAPI GetNamedPipeHandleStateW(
1369 HANDLE hNamedPipe, LPDWORD lpState, LPDWORD lpCurInstances,
1370 LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout,
1371 LPWSTR lpUsername, DWORD nUsernameMaxSize)
1373 FIXME("%p %p %p %p %p %p %ld\n",
1374 hNamedPipe, lpState, lpCurInstances,
1375 lpMaxCollectionCount, lpCollectDataTimeout,
1376 lpUsername, nUsernameMaxSize);
1381 /***********************************************************************
1382 * SetNamedPipeHandleState (KERNEL32.@)
1384 BOOL WINAPI SetNamedPipeHandleState(
1385 HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount,
1386 LPDWORD lpCollectDataTimeout)
1388 FIXME("%p %p %p %p\n",
1389 hNamedPipe, lpMode, lpMaxCollectionCount, lpCollectDataTimeout);
1393 /***********************************************************************
1394 * CallNamedPipeA (KERNEL32.@)
1396 BOOL WINAPI CallNamedPipeA(
1397 LPCSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
1398 LPVOID lpOutput, DWORD lpOutputSize,
1399 LPDWORD lpBytesRead, DWORD nTimeout)
1401 FIXME("%s %p %ld %p %ld %p %ld\n",
1402 debugstr_a(lpNamedPipeName), lpInput, lpInputSize,
1403 lpOutput, lpOutputSize, lpBytesRead, nTimeout);
1407 /***********************************************************************
1408 * CallNamedPipeW (KERNEL32.@)
1410 BOOL WINAPI CallNamedPipeW(
1411 LPCWSTR lpNamedPipeName, LPVOID lpInput, DWORD lpInputSize,
1412 LPVOID lpOutput, DWORD lpOutputSize,
1413 LPDWORD lpBytesRead, DWORD nTimeout)
1415 FIXME("%s %p %ld %p %ld %p %ld\n",
1416 debugstr_w(lpNamedPipeName), lpInput, lpInputSize,
1417 lpOutput, lpOutputSize, lpBytesRead, nTimeout);
1421 /******************************************************************
1422 * CreatePipe (KERNEL32.@)
1425 BOOL WINAPI CreatePipe( PHANDLE hReadPipe, PHANDLE hWritePipe,
1426 LPSECURITY_ATTRIBUTES sa, DWORD size )
1428 static unsigned index = 0;
1431 unsigned in_index = index;
1433 *hReadPipe = *hWritePipe = INVALID_HANDLE_VALUE;
1434 /* generate a unique pipe name (system wide) */
1437 sprintf(name, "\\\\.\\pipe\\Win32.Pipes.%08lu.%08u", GetCurrentProcessId(), ++index);
1438 hr = CreateNamedPipeA(name, PIPE_ACCESS_INBOUND,
1439 PIPE_TYPE_BYTE | PIPE_WAIT, 1, size, size,
1440 NMPWAIT_USE_DEFAULT_WAIT, sa);
1441 } while (hr == INVALID_HANDLE_VALUE && index != in_index);
1442 /* from completion sakeness, I think system resources might be exhausted before this happens !! */
1443 if (hr == INVALID_HANDLE_VALUE) return FALSE;
1445 hw = CreateFileA(name, GENERIC_WRITE, 0, sa, OPEN_EXISTING, 0, 0);
1446 if (hw == INVALID_HANDLE_VALUE)
1458 /******************************************************************************
1459 * CreateMailslotA [KERNEL32.@]
1461 HANDLE WINAPI CreateMailslotA( LPCSTR lpName, DWORD nMaxMessageSize,
1462 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1468 TRACE("%s %ld %ld %p\n", debugstr_a(lpName),
1469 nMaxMessageSize, lReadTimeout, sa);
1473 len = MultiByteToWideChar( CP_ACP, 0, lpName, -1, NULL, 0 );
1474 name = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1475 MultiByteToWideChar( CP_ACP, 0, lpName, -1, name, len );
1478 handle = CreateMailslotW( name, nMaxMessageSize, lReadTimeout, sa );
1481 HeapFree( GetProcessHeap(), 0, name );
1487 /******************************************************************************
1488 * CreateMailslotW [KERNEL32.@]
1490 * Create a mailslot with specified name.
1493 * lpName [I] Pointer to string for mailslot name
1494 * nMaxMessageSize [I] Maximum message size
1495 * lReadTimeout [I] Milliseconds before read time-out
1496 * sa [I] Pointer to security structure
1499 * Success: Handle to mailslot
1500 * Failure: INVALID_HANDLE_VALUE
1502 HANDLE WINAPI CreateMailslotW( LPCWSTR lpName, DWORD nMaxMessageSize,
1503 DWORD lReadTimeout, LPSECURITY_ATTRIBUTES sa )
1505 FIXME("(%s,%ld,%ld,%p): stub\n", debugstr_w(lpName),
1506 nMaxMessageSize, lReadTimeout, sa);
1507 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1508 return INVALID_HANDLE_VALUE;
1512 /******************************************************************************
1513 * GetMailslotInfo [KERNEL32.@]
1515 * Retrieve information about a mailslot.
1518 * hMailslot [I] Mailslot handle
1519 * lpMaxMessageSize [O] Address of maximum message size
1520 * lpNextSize [O] Address of size of next message
1521 * lpMessageCount [O] Address of number of messages
1522 * lpReadTimeout [O] Address of read time-out
1528 BOOL WINAPI GetMailslotInfo( HANDLE hMailslot, LPDWORD lpMaxMessageSize,
1529 LPDWORD lpNextSize, LPDWORD lpMessageCount,
1530 LPDWORD lpReadTimeout )
1532 FIXME("(%p): stub\n",hMailslot);
1533 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1538 /******************************************************************************
1539 * SetMailslotInfo [KERNEL32.@]
1541 * Set the read timeout of a mailslot.
1544 * hMailslot [I] Mailslot handle
1545 * dwReadTimeout [I] Timeout in milliseconds.
1551 BOOL WINAPI SetMailslotInfo( HANDLE hMailslot, DWORD dwReadTimeout)
1553 FIXME("%p %ld: stub\n", hMailslot, dwReadTimeout);
1554 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1559 /******************************************************************************
1560 * CreateIoCompletionPort (KERNEL32.@)
1562 HANDLE WINAPI CreateIoCompletionPort(HANDLE hFileHandle, HANDLE hExistingCompletionPort,
1563 DWORD dwCompletionKey, DWORD dwNumberOfConcurrentThreads)
1565 FIXME("(%p, %p, %08lx, %08lx): stub.\n",
1566 hFileHandle, hExistingCompletionPort, dwCompletionKey, dwNumberOfConcurrentThreads);
1571 /******************************************************************************
1572 * GetQueuedCompletionStatus (KERNEL32.@)
1574 BOOL WINAPI GetQueuedCompletionStatus( HANDLE CompletionPort, LPDWORD lpNumberOfBytesTransferred,
1575 LPDWORD lpCompletionKey, LPOVERLAPPED *lpOverlapped,
1576 DWORD dwMilliseconds )
1578 FIXME("(%p,%p,%p,%p,%ld), stub!\n",
1579 CompletionPort,lpNumberOfBytesTransferred,lpCompletionKey,lpOverlapped,dwMilliseconds);
1580 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1584 /******************************************************************************
1585 * CreateJobObjectW (KERNEL32.@)
1587 HANDLE WINAPI CreateJobObjectW( LPSECURITY_ATTRIBUTES attr, LPCWSTR name )
1589 FIXME("%p %s\n", attr, debugstr_w(name) );
1590 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1594 /******************************************************************************
1595 * CreateJobObjectA (KERNEL32.@)
1597 HANDLE WINAPI CreateJobObjectA( LPSECURITY_ATTRIBUTES attr, LPCSTR name )
1603 TRACE("%p %s\n", attr, debugstr_a(name) );
1607 len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
1608 str = HeapAlloc( GetProcessHeap(), 0, len*sizeof(WCHAR) );
1611 SetLastError( ERROR_OUTOFMEMORY );
1614 len = MultiByteToWideChar( CP_ACP, 0, name, -1, str, len );
1617 r = CreateJobObjectW( attr, str );
1620 HeapFree( GetProcessHeap(), 0, str );
1625 /******************************************************************************
1626 * AssignProcessToJobObject (KERNEL32.@)
1628 BOOL WINAPI AssignProcessToJobObject( HANDLE hJob, HANDLE hProcess )
1630 FIXME("%p %p\n", hJob, hProcess);
1636 /***********************************************************************
1637 * InterlockedCompareExchange (KERNEL32.@)
1639 /* LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare ); */
1640 __ASM_GLOBAL_FUNC(InterlockedCompareExchange,
1641 "movl 12(%esp),%eax\n\t"
1642 "movl 8(%esp),%ecx\n\t"
1643 "movl 4(%esp),%edx\n\t"
1644 "lock; cmpxchgl %ecx,(%edx)\n\t"
1647 /***********************************************************************
1648 * InterlockedExchange (KERNEL32.@)
1650 /* LONG WINAPI InterlockedExchange( PLONG dest, LONG val ); */
1651 __ASM_GLOBAL_FUNC(InterlockedExchange,
1652 "movl 8(%esp),%eax\n\t"
1653 "movl 4(%esp),%edx\n\t"
1654 "lock; xchgl %eax,(%edx)\n\t"
1657 /***********************************************************************
1658 * InterlockedExchangeAdd (KERNEL32.@)
1660 /* LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr ); */
1661 __ASM_GLOBAL_FUNC(InterlockedExchangeAdd,
1662 "movl 8(%esp),%eax\n\t"
1663 "movl 4(%esp),%edx\n\t"
1664 "lock; xaddl %eax,(%edx)\n\t"
1667 /***********************************************************************
1668 * InterlockedIncrement (KERNEL32.@)
1670 /* LONG WINAPI InterlockedIncrement( PLONG dest ); */
1671 __ASM_GLOBAL_FUNC(InterlockedIncrement,
1672 "movl 4(%esp),%edx\n\t"
1674 "lock; xaddl %eax,(%edx)\n\t"
1678 /***********************************************************************
1679 * InterlockedDecrement (KERNEL32.@)
1681 __ASM_GLOBAL_FUNC(InterlockedDecrement,
1682 "movl 4(%esp),%edx\n\t"
1684 "lock; xaddl %eax,(%edx)\n\t"
1688 #else /* __i386__ */
1690 /***********************************************************************
1691 * InterlockedCompareExchange (KERNEL32.@)
1693 * Atomically swap one value with another.
1696 * dest [I/O] The value to replace
1697 * xchq [I] The value to be swapped
1698 * compare [I] The value to compare to dest
1701 * The resulting value of dest.
1704 * dest is updated only if it is equal to compare, otherwise no swap is done.
1706 LONG WINAPI InterlockedCompareExchange( PLONG dest, LONG xchg, LONG compare )
1708 return interlocked_cmpxchg( dest, xchg, compare );
1711 /***********************************************************************
1712 * InterlockedExchange (KERNEL32.@)
1714 * Atomically swap one value with another.
1717 * dest [I/O] The value to replace
1718 * val [I] The value to be swapped
1721 * The resulting value of dest.
1723 LONG WINAPI InterlockedExchange( PLONG dest, LONG val )
1725 return interlocked_xchg( dest, val );
1728 /***********************************************************************
1729 * InterlockedExchangeAdd (KERNEL32.@)
1731 * Atomically add one value to another.
1734 * dest [I/O] The value to add to
1735 * incr [I] The value to be added
1738 * The resulting value of dest.
1740 LONG WINAPI InterlockedExchangeAdd( PLONG dest, LONG incr )
1742 return interlocked_xchg_add( dest, incr );
1745 /***********************************************************************
1746 * InterlockedIncrement (KERNEL32.@)
1748 * Atomically increment a value.
1751 * dest [I/O] The value to increment
1754 * The resulting value of dest.
1756 LONG WINAPI InterlockedIncrement( PLONG dest )
1758 return interlocked_xchg_add( dest, 1 ) + 1;
1761 /***********************************************************************
1762 * InterlockedDecrement (KERNEL32.@)
1764 * Atomically decrement a value.
1767 * dest [I/O] The value to decrement
1770 * The resulting value of dest.
1772 LONG WINAPI InterlockedDecrement( PLONG dest )
1774 return interlocked_xchg_add( dest, -1 ) - 1;
1777 #endif /* __i386__ */