ReactOS  0.4.10-dev-348-gbcec1fd
sync.c File Reference
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <windef.h>
#include <winbase.h>
#include <winternl.h>
#include "wine/test.h"
Include dependency graph for sync.c:

Go to the source code of this file.

Classes

struct  timer_queue_data1
 
struct  apc_deadlock_info
 

Macros

#define _WIN32_WINNT   0x500
 
#define __fastcall   __stdcall
 
#define init_fastcall_thunk()   do { } while(0)
 
#define call_func4(func, a, b, c, d)   func(a, b, c, d)
 
#define BUFFER_SIZE   5
 

Functions

static HANDLE (WINAPI *pCreateMemoryResourceNotification)(MEMORY_RESOURCE_NOTIFICATION_TYPE)
 
static BOOL (WINAPI *pQueryMemoryResourceNotification)(HANDLE
 
static VOID (WINAPI *pInitOnceInitialize)(PINIT_ONCE)
 
static BOOLEAN (WINAPI *pTryAcquireSRWLockExclusive)(PSRWLOCK)
 
static NTSTATUS (WINAPI *pNtAllocateVirtualMemory)(HANDLE
 
static const LARGE_INTEGER
*static const HANDLE const
LARGE_INTEGER *static 
PSLIST_ENTRY (__fastcall *pRtlInterlockedPushListSList)(PSLIST_HEADER list
 
static PSLIST_ENTRY (WINAPI *pRtlInterlockedPushListSListEx)(PSLIST_HEADER list
 
static void test_signalandwait (void)
 
static void test_mutex (void)
 
static void test_slist (void)
 
static void test_event (void)
 
static void test_semaphore (void)
 
static void test_waitable_timer (void)
 
static void CALLBACK iocp_callback (DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
 
static void test_iocp_callback (void)
 
static void CALLBACK timer_queue_cb1 (PVOID p, BOOLEAN timedOut)
 
static void CALLBACK timer_queue_cb2 (PVOID p, BOOLEAN timedOut)
 
static void CALLBACK timer_queue_cb3 (PVOID p, BOOLEAN timedOut)
 
static void CALLBACK timer_queue_cb4 (PVOID p, BOOLEAN timedOut)
 
static void CALLBACK timer_queue_cb5 (PVOID p, BOOLEAN timedOut)
 
static void CALLBACK timer_queue_cb6 (PVOID p, BOOLEAN timedOut)
 
static void test_timer_queue (void)
 
static HANDLE modify_handle (HANDLE handle, DWORD modify)
 
static void test_WaitForSingleObject (void)
 
static void test_WaitForMultipleObjects (void)
 
static BOOL CALLBACK initonce_callback (INIT_ONCE *initonce, void *parameter, void **ctxt)
 
static void test_initonce (void)
 
static DWORD WINAPI condvar_producer (LPVOID x)
 
static DWORD WINAPI condvar_consumer (LPVOID x)
 
static void test_condvars_consumer_producer (void)
 
static DWORD WINAPI condvar_base_producer (LPVOID x)
 
static DWORD WINAPI condvar_base_consumer (LPVOID x)
 
static void test_condvars_base (void)
 
static DWORD WINAPI srwlock_base_thread1 (LPVOID x)
 
static DWORD WINAPI srwlock_base_thread2 (LPVOID x)
 
static DWORD WINAPI srwlock_base_thread3 (LPVOID x)
 
static void test_srwlock_base (void)
 
static DWORD WINAPI srwlock_example_thread (LPVOID x)
 
static void test_srwlock_example (void)
 
static DWORD WINAPI alertable_wait_thread (void *param)
 
static void CALLBACK alertable_wait_apc (ULONG_PTR userdata)
 
static void CALLBACK alertable_wait_apc2 (ULONG_PTR userdata)
 
static void test_alertable_wait (void)
 
static DWORD WINAPI apc_deadlock_thread (void *param)
 
static void test_apc_deadlock (void)
 
 START_TEST (sync)
 

Variables

static PBOOL
 
static PINIT_ONCE_FN
 
static PVOID
 
static LPVOID *static DWORD
 
static LPVOID *static BOOL
LPVOID *static 
LPVOID
 
static PCRITICAL_SECTION
 
static PSRWLOCK
 
static ULONG
 
static BOOLEAN
 
static const LARGE_INTEGER
*static const HANDLE const
LARGE_INTEGER *static
PSLIST_ENTRY 
first
 
static const LARGE_INTEGER
*static const HANDLE const
LARGE_INTEGER *static
PSLIST_ENTRY PSLIST_ENTRY 
last
 
static const LARGE_INTEGER
*static const HANDLE const
LARGE_INTEGER *static
PSLIST_ENTRY PSLIST_ENTRY
ULONG 
count
 
static HANDLE sem = 0
 
static
LPOVERLAPPED_COMPLETION_ROUTINE 
Function
 
static
LPOVERLAPPED_COMPLETION_ROUTINE
ULONG 
Flags = NULL
 
static BOOL g_initcallback_ret
 
static BOOL g_initcallback_called
 
static voidg_initctxt
 
static CONDITION_VARIABLE buffernotempty = CONDITION_VARIABLE_INIT
 
static CONDITION_VARIABLE buffernotfull = CONDITION_VARIABLE_INIT
 
static CRITICAL_SECTION buffercrit
 
static BOOL condvar_stop = FALSE
 
static BOOL condvar_sleeperr = FALSE
 
static LONG bufferlen
 
static LONG totalproduced
 
static LONG totalconsumed
 
static LONG condvar_producer_sleepcnt
 
static LONG condvar_consumer_sleepcnt
 
static DWORD condvar_seq = 0
 
static CONDITION_VARIABLE condvar_base = CONDITION_VARIABLE_INIT
 
static CRITICAL_SECTION condvar_crit
 
static SRWLOCK condvar_srwlock
 
static LONG srwlock_seq = 0
 
static SRWLOCK srwlock_base
 
struct {
   LONG   wrong_execution_order
 
   LONG   samethread_excl_excl
 
   LONG   samethread_excl_shared
 
   LONG   samethread_shared_excl
 
   LONG   multithread_excl_excl
 
   LONG   excl_not_preferred
 
   LONG   trylock_excl
 
   LONG   trylock_shared
 
srwlock_base_errors
 
static SRWLOCK srwlock_example
 
static LONG srwlock_protected_value = 0
 
static LONG srwlock_example_errors = 0
 
static LONG srwlock_inside = 0
 
static LONG srwlock_cnt = 0
 
static BOOL srwlock_stop = FALSE
 

Macro Definition Documentation

IN OUT PLONG IN OUT PLONG Addend __fastcall   __stdcall

Definition at line 41 of file sync.c.

Referenced by iskeyword().

#define _WIN32_WINNT   0x500

Definition at line 22 of file sync.c.

#define BUFFER_SIZE   5

Definition at line 1603 of file sync.c.

Referenced by condvar_producer().

#define call_func4 (   func,
  a,
  b,
  c,
  d 
)    func(a, b, c, d)

Definition at line 107 of file sync.c.

Referenced by test_slist().

#define init_fastcall_thunk ( )    do { } while(0)

Definition at line 106 of file sync.c.

Referenced by START_TEST().

Function Documentation

static void CALLBACK alertable_wait_apc ( ULONG_PTR  userdata)
static

Definition at line 2498 of file sync.c.

Referenced by test_alertable_wait().

2499 {
2500  HANDLE *semaphores = (void *)userdata;
2501  ReleaseSemaphore(semaphores[1], 1, NULL);
2502 }
smooth NULL
Definition: ftsmooth.c:416
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
static void CALLBACK alertable_wait_apc2 ( ULONG_PTR  userdata)
static

Definition at line 2504 of file sync.c.

Referenced by test_alertable_wait().

2505 {
2506  HANDLE *semaphores = (void *)userdata;
2507  DWORD result;
2508 
2509  result = WaitForSingleObject(semaphores[0], 1000);
2510  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2511 }
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define ok(value,...)
Definition: CComObject.cpp:34
#define WAIT_OBJECT_0
Definition: winbase.h:387
DWORD *typedef HANDLE
Definition: winlogon.h:52
GLuint64EXT * result
Definition: glext.h:11304
static DWORD WINAPI alertable_wait_thread ( void param)
static

Definition at line 2467 of file sync.c.

Referenced by test_alertable_wait().

2468 {
2469  HANDLE *semaphores = param;
2471  NTSTATUS status;
2472  DWORD result;
2473 
2474  ReleaseSemaphore(semaphores[0], 1, NULL);
2475  result = WaitForMultipleObjectsEx(1, &semaphores[1], TRUE, 1000, TRUE);
2476  ok(result == WAIT_IO_COMPLETION, "expected WAIT_IO_COMPLETION, got %u\n", result);
2477  result = WaitForMultipleObjectsEx(1, &semaphores[1], TRUE, 200, TRUE);
2478  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2479 
2480  ReleaseSemaphore(semaphores[0], 1, NULL);
2481  timeout.QuadPart = -10000000;
2482  status = pNtWaitForMultipleObjects(1, &semaphores[1], FALSE, TRUE, &timeout);
2483  ok(status == STATUS_USER_APC, "expected STATUS_USER_APC, got %08x\n", status);
2484  timeout.QuadPart = -2000000;
2485  status = pNtWaitForMultipleObjects(1, &semaphores[1], FALSE, TRUE, &timeout);
2486  ok(status == STATUS_WAIT_0, "expected STATUS_WAIT_0, got %08x\n", status);
2487 
2488  ReleaseSemaphore(semaphores[0], 1, NULL);
2489  timeout.QuadPart = -10000000;
2490  status = pNtWaitForMultipleObjects(1, &semaphores[1], FALSE, TRUE, &timeout);
2491  ok(status == STATUS_USER_APC, "expected STATUS_USER_APC, got %08x\n", status);
2492  result = WaitForSingleObject(semaphores[0], 0);
2493  ok(result == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", result);
2494 
2495  return 0;
2496 }
#define TRUE
Definition: types.h:120
GLbitfield GLuint64 timeout
Definition: glext.h:7164
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define STATUS_WAIT_0
Definition: ntstatus.h:223
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define WAIT_IO_COMPLETION
Definition: winbase.h:392
#define ok(value,...)
Definition: CComObject.cpp:34
#define WAIT_OBJECT_0
Definition: winbase.h:387
LONG NTSTATUS
Definition: precomp.h:26
DWORD WINAPI WaitForMultipleObjectsEx(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:169
GLfloat param
Definition: glext.h:5796
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define STATUS_USER_APC
Definition: ntstatus.h:78
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
GLuint64EXT * result
Definition: glext.h:11304
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:112
static DWORD WINAPI apc_deadlock_thread ( void param)
static

Definition at line 2560 of file sync.c.

Referenced by test_apc_deadlock().

2561 {
2562  struct apc_deadlock_info *info = param;
2563  PROCESS_INFORMATION *pi = info->pi;
2564  NTSTATUS status;
2565  SIZE_T size;
2566  void *base;
2567 
2568  while (info->running)
2569  {
2570  base = NULL;
2571  size = 0x1000;
2572  status = pNtAllocateVirtualMemory(pi->hProcess, &base, 0, &size,
2574  ok(!status, "expected STATUS_SUCCESS, got %08x\n", status);
2575  ok(base != NULL, "expected base != NULL, got %p\n", base);
2576  SetEvent(info->event);
2577 
2578  size = 0;
2579  status = pNtFreeVirtualMemory(pi->hProcess, &base, &size, MEM_RELEASE);
2580  ok(!status, "expected STATUS_SUCCESS, got %08x\n", status);
2581  SetEvent(info->event);
2582  }
2583 
2584  return 0;
2585 }
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
#define MEM_COMMIT
Definition: nt_native.h:1313
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
#define MEM_RESERVE
Definition: nt_native.h:1314
HANDLE event
Definition: sync.c:2556
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
GLsizeiptr size
Definition: glext.h:5919
LONG NTSTATUS
Definition: precomp.h:26
GLfloat param
Definition: glext.h:5796
static DWORD pi
Definition: protocol.c:150
PROCESS_INFORMATION * pi
Definition: sync.c:2555
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define MEM_RELEASE
Definition: nt_native.h:1316
static SERVICE_STATUS status
Definition: service.c:31
#define PAGE_READWRITE
Definition: nt_native.h:1304
static BOOL ( WINAPI pQueryMemoryResourceNotification)
static
static BOOLEAN ( WINAPI pTryAcquireSRWLockExclusive)
static
static DWORD WINAPI condvar_base_consumer ( LPVOID  x)
static

Definition at line 1805 of file sync.c.

Referenced by test_condvars_base().

1805  {
1806  BOOL ret;
1807 
1808  while (condvar_seq < 2) Sleep(1);
1809 
1810  /* wake was emitted, but we were not sleeping */
1812  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
1814  ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
1815  ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
1816 
1817  condvar_seq = 3;
1818  while (condvar_seq < 4) Sleep(1);
1819 
1820  /* wake all was emitted, but we were not sleeping */
1822  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
1824  ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
1825  ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
1826 
1828  condvar_seq = 5;
1829  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 200);
1831  ok (ret, "SleepConditionVariableCS should return TRUE on good wake\n");
1832 
1834  condvar_seq = 6;
1835  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 200);
1837  ok (ret, "SleepConditionVariableCS should return TRUE on good wakeall\n");
1838  condvar_seq = 7;
1839 
1841  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
1843  ok (!ret, "SleepConditionVariableCS should return FALSE on out of band wake\n");
1844  ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on out of band wake, not %d\n", GetLastError());
1845 
1847  condvar_seq = 8;
1848  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 20);
1850  ok (ret, "SleepConditionVariableCS should still return TRUE on crit unlock delay\n");
1851 
1852  /* skip over remaining tests if InitializeSRWLock is not available */
1853  if (!pInitializeSRWLock)
1854  {
1855  win_skip("no srw lock support.\n");
1856  condvar_seq = 13; /* end */
1857  return 0;
1858  }
1859 
1860  pAcquireSRWLockExclusive(&condvar_srwlock);
1861  condvar_seq = 9;
1862  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 200, 0);
1863  pReleaseSRWLockExclusive(&condvar_srwlock);
1864  ok (ret, "pSleepConditionVariableSRW should return TRUE on good wake\n");
1865 
1866  pAcquireSRWLockShared(&condvar_srwlock);
1867  condvar_seq = 10;
1868  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 200, CONDITION_VARIABLE_LOCKMODE_SHARED);
1869  pReleaseSRWLockShared(&condvar_srwlock);
1870  ok (ret, "pSleepConditionVariableSRW should return TRUE on good wake\n");
1871 
1872  pAcquireSRWLockExclusive(&condvar_srwlock);
1873  condvar_seq = 11;
1874  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 200, 0);
1875  pReleaseSRWLockExclusive(&condvar_srwlock);
1876  ok (ret, "pSleepConditionVariableSRW should return TRUE on good wake\n");
1877 
1878  pAcquireSRWLockShared(&condvar_srwlock);
1879  condvar_seq = 12;
1880  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 200, CONDITION_VARIABLE_LOCKMODE_SHARED);
1881  pReleaseSRWLockShared(&condvar_srwlock);
1882  ok (ret, "pSleepConditionVariableSRW should return TRUE on good wake\n");
1883 
1884  condvar_seq = 13;
1885  return 0;
1886 }
static CRITICAL_SECTION condvar_crit
Definition: sync.c:1730
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static CONDITION_VARIABLE condvar_base
Definition: sync.c:1729
#define ERROR_TIMEOUT
Definition: winerror.h:941
static SRWLOCK condvar_srwlock
Definition: sync.c:1731
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
int ret
static DWORD condvar_seq
Definition: sync.c:1728
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define win_skip
Definition: test.h:141
static DWORD WINAPI condvar_base_producer ( LPVOID  x)
static

Definition at line 1752 of file sync.c.

Referenced by test_condvars_base().

1752  {
1753  while (condvar_seq < 1) Sleep(1);
1754 
1755  pWakeConditionVariable (&condvar_base);
1756  condvar_seq = 2;
1757 
1758  while (condvar_seq < 3) Sleep(1);
1759  pWakeAllConditionVariable (&condvar_base);
1760  condvar_seq = 4;
1761 
1762  while (condvar_seq < 5) Sleep(1);
1764  pWakeConditionVariable (&condvar_base);
1766  while (condvar_seq < 6) Sleep(1);
1768  pWakeAllConditionVariable (&condvar_base);
1770 
1771  while (condvar_seq < 8) Sleep(1);
1773  pWakeConditionVariable (&condvar_base);
1774  Sleep(50);
1776 
1777  /* skip over remaining tests if InitializeSRWLock is not available */
1778  if (!pInitializeSRWLock)
1779  return 0;
1780 
1781  while (condvar_seq < 9) Sleep(1);
1782  pAcquireSRWLockExclusive(&condvar_srwlock);
1783  pWakeConditionVariable(&condvar_base);
1784  pReleaseSRWLockExclusive(&condvar_srwlock);
1785 
1786  while (condvar_seq < 10) Sleep(1);
1787  pAcquireSRWLockExclusive(&condvar_srwlock);
1788  pWakeConditionVariable(&condvar_base);
1789  pReleaseSRWLockExclusive(&condvar_srwlock);
1790 
1791  while (condvar_seq < 11) Sleep(1);
1792  pAcquireSRWLockShared(&condvar_srwlock);
1793  pWakeConditionVariable(&condvar_base);
1794  pReleaseSRWLockShared(&condvar_srwlock);
1795 
1796  while (condvar_seq < 12) Sleep(1);
1797  Sleep(50); /* ensure that consumer waits for cond variable */
1798  pAcquireSRWLockShared(&condvar_srwlock);
1799  pWakeConditionVariable(&condvar_base);
1800  pReleaseSRWLockShared(&condvar_srwlock);
1801 
1802  return 0;
1803 }
static CRITICAL_SECTION condvar_crit
Definition: sync.c:1730
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static CONDITION_VARIABLE condvar_base
Definition: sync.c:1729
static SRWLOCK condvar_srwlock
Definition: sync.c:1731
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static DWORD condvar_seq
Definition: sync.c:1728
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static DWORD WINAPI condvar_consumer ( LPVOID  x)
static

Definition at line 1633 of file sync.c.

Referenced by test_condvars_consumer_producer().

1633  {
1634  DWORD *cnt = (DWORD*)x;
1635  DWORD sleepinterval = 1;
1636 
1637  while (1) {
1639  while ((bufferlen == 0) && !condvar_stop) {
1641  if (!pSleepConditionVariableCS (&buffernotempty, &buffercrit, sleepinterval)) {
1642  if (GetLastError() != ERROR_TIMEOUT)
1644  }
1645  }
1646  if (condvar_stop && (bufferlen == 0)) {
1648  break;
1649  }
1650  bufferlen--;
1651  totalconsumed++;
1652  (*cnt)++;
1654  pWakeConditionVariable(&buffernotfull);
1655  Sleep(sleepinterval);
1656  if (sleepinterval < 5) sleepinterval += 1;
1657  }
1658  return 0;
1659 }
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define ERROR_TIMEOUT
Definition: winerror.h:941
static LONG condvar_consumer_sleepcnt
Definition: sync.c:1601
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static BOOL condvar_stop
Definition: sync.c:1599
static LONG bufferlen
Definition: sync.c:1600
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
static LONG totalconsumed
Definition: sync.c:1600
DWORD DWORD
Definition: winlogon.h:75
static CONDITION_VARIABLE buffernotfull
Definition: sync.c:1597
static CONDITION_VARIABLE buffernotempty
Definition: sync.c:1596
static CRITICAL_SECTION buffercrit
Definition: sync.c:1598
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL condvar_sleeperr
Definition: sync.c:1599
static DWORD WINAPI condvar_producer ( LPVOID  x)
static

Definition at line 1605 of file sync.c.

Referenced by test_condvars_consumer_producer().

1605  {
1606  DWORD sleepinterval = 5;
1607 
1608  while (1) {
1609  Sleep(sleepinterval);
1610  if (sleepinterval > 1)
1611  sleepinterval -= 1;
1612 
1614  while ((bufferlen == BUFFER_SIZE) && !condvar_stop) {
1616  if (!pSleepConditionVariableCS(&buffernotfull, &buffercrit, sleepinterval)) {
1617  if (GetLastError() != ERROR_TIMEOUT)
1619  }
1620  }
1621  if (condvar_stop) {
1623  break;
1624  }
1625  bufferlen++;
1626  totalproduced++;
1628  pWakeConditionVariable(&buffernotempty);
1629  }
1630  return 0;
1631 }
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define ERROR_TIMEOUT
Definition: winerror.h:941
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static BOOL condvar_stop
Definition: sync.c:1599
static LONG bufferlen
Definition: sync.c:1600
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
DWORD DWORD
Definition: winlogon.h:75
static CONDITION_VARIABLE buffernotfull
Definition: sync.c:1597
static LONG condvar_producer_sleepcnt
Definition: sync.c:1601
#define BUFFER_SIZE
Definition: sync.c:1603
static CONDITION_VARIABLE buffernotempty
Definition: sync.c:1596
static CRITICAL_SECTION buffercrit
Definition: sync.c:1598
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL condvar_sleeperr
Definition: sync.c:1599
static LONG totalproduced
Definition: sync.c:1600
static HANDLE ( WINAPI pCreateMemoryResourceNotification)
static
static BOOL CALLBACK initonce_callback ( INIT_ONCE initonce,
void parameter,
void **  ctxt 
)
static

Definition at line 1355 of file sync.c.

Referenced by test_initonce().

1356 {
1358  /* zero bit set means here that initialization is taking place - initialization locked */
1359  ok(g_initctxt == *ctxt, "got wrong context value %p, expected %p\n", *ctxt, g_initctxt);
1360  ok(initonce->Ptr == (void*)0x1, "got %p\n", initonce->Ptr);
1361  ok(parameter == (void*)0xdeadbeef, "got wrong parameter\n");
1362  return g_initcallback_ret;
1363 }
#define TRUE
Definition: types.h:120
static void * g_initctxt
Definition: sync.c:1353
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
#define ok(value,...)
Definition: CComObject.cpp:34
static BOOL g_initcallback_called
Definition: sync.c:1352
static BOOL g_initcallback_ret
Definition: sync.c:1352
static void CALLBACK iocp_callback ( DWORD  dwErrorCode,
DWORD  dwNumberOfBytesTransferred,
LPOVERLAPPED  lpOverlapped 
)
static

Definition at line 679 of file sync.c.

Referenced by test_iocp_callback().

680 {
682 }
smooth NULL
Definition: ftsmooth.c:416
static HANDLE sem
Definition: sync.c:677
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
static HANDLE modify_handle ( HANDLE  handle,
DWORD  modify 
)
static

Definition at line 1176 of file sync.c.

Referenced by test_WaitForSingleObject().

1177 {
1178  DWORD tmp = HandleToULong(handle);
1179  tmp |= modify;
1180  return ULongToHandle(tmp);
1181 }
#define ULongToHandle(h)
Definition: basetsd.h:81
#define HandleToULong(h)
Definition: basetsd.h:95
DWORD DWORD
Definition: winlogon.h:75
static NTSTATUS ( WINAPI pNtAllocateVirtualMemory)
static
static const LARGE_INTEGER* static const HANDLE const LARGE_INTEGER* static PSLIST_ENTRY ( __fastcall pRtlInterlockedPushListSList)
static
static PSLIST_ENTRY ( WINAPI pRtlInterlockedPushListSListEx)
static
static DWORD WINAPI srwlock_base_thread1 ( LPVOID  x)
static

Definition at line 2026 of file sync.c.

Referenced by test_srwlock_base().

2027 {
2028  /* seq 2 */
2029  while (srwlock_seq < 2) Sleep(1);
2030  Sleep(100);
2031  if (InterlockedIncrement(&srwlock_seq) != 3)
2032  InterlockedIncrement(&srwlock_base_errors.samethread_excl_excl);
2033  pReleaseSRWLockExclusive(&srwlock_base);
2034 
2035  /* seq 4 */
2036  while (srwlock_seq < 4) Sleep(1);
2037  Sleep(100);
2038  if (InterlockedIncrement(&srwlock_seq) != 5)
2039  InterlockedIncrement(&srwlock_base_errors.samethread_excl_shared);
2040  pReleaseSRWLockExclusive(&srwlock_base);
2041 
2042  /* seq 6 */
2043  while (srwlock_seq < 6) Sleep(1);
2044  Sleep(100);
2045  if (InterlockedIncrement(&srwlock_seq) != 7)
2046  InterlockedIncrement(&srwlock_base_errors.samethread_shared_excl);
2047  pReleaseSRWLockShared(&srwlock_base);
2048 
2049  /* seq 8 */
2050  while (srwlock_seq < 8) Sleep(1);
2051  pAcquireSRWLockExclusive(&srwlock_base);
2052  if (InterlockedIncrement(&srwlock_seq) != 9)
2053  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2054  Sleep(100);
2055  if (InterlockedIncrement(&srwlock_seq) != 10)
2056  InterlockedIncrement(&srwlock_base_errors.multithread_excl_excl);
2057  pReleaseSRWLockExclusive(&srwlock_base);
2058 
2059  /* seq 11 */
2060  while (srwlock_seq < 11) Sleep(1);
2061  pAcquireSRWLockShared(&srwlock_base);
2062  if (InterlockedIncrement(&srwlock_seq) != 12)
2063  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2064 
2065  /* seq 13 */
2066  while (srwlock_seq < 13) Sleep(1);
2067  pReleaseSRWLockShared(&srwlock_base);
2068  pAcquireSRWLockShared(&srwlock_base);
2069  if (InterlockedIncrement(&srwlock_seq) != 14)
2070  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2071 
2072  /* seq 16 */
2073  while (srwlock_seq < 16) Sleep(1);
2074  Sleep(50); /* ensure that both the exclusive and shared access thread are queued */
2075  if (InterlockedIncrement(&srwlock_seq) != 17)
2076  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2077  pReleaseSRWLockShared(&srwlock_base);
2078 
2079  /* skip over remaining tests if TryAcquireSRWLock* is not available */
2080  if (!pTryAcquireSRWLockExclusive)
2081  return 0;
2082 
2083  /* seq 19 */
2084  while (srwlock_seq < 19) Sleep(1);
2085  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2086  {
2087  if (pTryAcquireSRWLockShared(&srwlock_base))
2088  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2089  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2091  pReleaseSRWLockExclusive(&srwlock_base);
2092  }
2093  else
2095 
2096  if (pTryAcquireSRWLockShared(&srwlock_base))
2097  {
2098  if (pTryAcquireSRWLockShared(&srwlock_base))
2099  pReleaseSRWLockShared(&srwlock_base);
2100  else
2101  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2102  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2104  pReleaseSRWLockShared(&srwlock_base);
2105  }
2106  else
2107  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2108 
2109  pAcquireSRWLockExclusive(&srwlock_base);
2110  if (InterlockedIncrement(&srwlock_seq) != 20)
2111  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2112 
2113  /* seq 21 */
2114  while (srwlock_seq < 21) Sleep(1);
2115  pReleaseSRWLockExclusive(&srwlock_base);
2116  pAcquireSRWLockShared(&srwlock_base);
2117  if (InterlockedIncrement(&srwlock_seq) != 22)
2118  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2119 
2120  /* seq 23 */
2121  while (srwlock_seq < 23) Sleep(1);
2122  pReleaseSRWLockShared(&srwlock_base);
2123  pAcquireSRWLockShared(&srwlock_base);
2124  if (InterlockedIncrement(&srwlock_seq) != 24)
2125  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2126 
2127  /* seq 25 */
2128  pAcquireSRWLockExclusive(&srwlock_base);
2129  if (srwlock_seq != 25)
2130  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2131  pReleaseSRWLockExclusive(&srwlock_base);
2132 
2133  pAcquireSRWLockShared(&srwlock_base);
2134  pAcquireSRWLockShared(&srwlock_base);
2135  if (InterlockedIncrement(&srwlock_seq) != 26)
2136  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2137 
2138  /* seq 27 */
2139  while (srwlock_seq < 27) Sleep(1);
2140  pReleaseSRWLockShared(&srwlock_base);
2141  if (InterlockedIncrement(&srwlock_seq) != 28)
2142  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2143 
2144  /* seq 29 */
2145  while (srwlock_seq < 29) Sleep(1);
2146  pReleaseSRWLockShared(&srwlock_base);
2147  if (InterlockedIncrement(&srwlock_seq) != 30)
2148  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2149 
2150  return 0;
2151 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_seq
Definition: sync.c:1941
static SRWLOCK srwlock_base
Definition: sync.c:1942
static struct @1539 srwlock_base_errors
#define InterlockedIncrement
Definition: armddk.h:53
static DWORD WINAPI srwlock_base_thread2 ( LPVOID  x)
static

Definition at line 2153 of file sync.c.

Referenced by test_srwlock_base().

2154 {
2155  /* seq 1 */
2156  while (srwlock_seq < 1) Sleep(1);
2157  pAcquireSRWLockExclusive(&srwlock_base);
2158  if (InterlockedIncrement(&srwlock_seq) != 2)
2159  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2160 
2161  /* seq 3 */
2162  pAcquireSRWLockExclusive(&srwlock_base);
2163  if (srwlock_seq != 3)
2164  InterlockedIncrement(&srwlock_base_errors.samethread_excl_excl);
2165  pReleaseSRWLockExclusive(&srwlock_base);
2166  pAcquireSRWLockExclusive(&srwlock_base);
2167  if (InterlockedIncrement(&srwlock_seq) != 4)
2168  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2169 
2170  /* seq 5 */
2171  pAcquireSRWLockShared(&srwlock_base);
2172  if (srwlock_seq != 5)
2173  InterlockedIncrement(&srwlock_base_errors.samethread_excl_shared);
2174  pReleaseSRWLockShared(&srwlock_base);
2175  pAcquireSRWLockShared(&srwlock_base);
2176  if (InterlockedIncrement(&srwlock_seq) != 6)
2177  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2178 
2179  /* seq 7 */
2180  pAcquireSRWLockExclusive(&srwlock_base);
2181  if (srwlock_seq != 7)
2182  InterlockedIncrement(&srwlock_base_errors.samethread_shared_excl);
2183  pReleaseSRWLockExclusive(&srwlock_base);
2184  pAcquireSRWLockShared(&srwlock_base);
2185  pAcquireSRWLockShared(&srwlock_base);
2186  pReleaseSRWLockShared(&srwlock_base);
2187  pReleaseSRWLockShared(&srwlock_base);
2188  if (InterlockedIncrement(&srwlock_seq) != 8)
2189  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2190 
2191  /* seq 9, 10 */
2192  while (srwlock_seq < 9) Sleep(1);
2193  pAcquireSRWLockExclusive(&srwlock_base);
2194  if (srwlock_seq != 10)
2195  InterlockedIncrement(&srwlock_base_errors.multithread_excl_excl);
2196  pReleaseSRWLockExclusive(&srwlock_base);
2197  if (InterlockedIncrement(&srwlock_seq) != 11)
2198  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2199 
2200  /* seq 12 */
2201  while (srwlock_seq < 12) Sleep(1);
2202  pAcquireSRWLockShared(&srwlock_base);
2203  pReleaseSRWLockShared(&srwlock_base);
2204  if (InterlockedIncrement(&srwlock_seq) != 13)
2205  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2206 
2207  /* seq 14 */
2208  while (srwlock_seq < 14) Sleep(1);
2209  if (InterlockedIncrement(&srwlock_seq) != 15)
2210  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2211 
2212  /* seq 17 */
2213  pAcquireSRWLockExclusive(&srwlock_base);
2214  if (srwlock_seq != 17)
2215  InterlockedIncrement(&srwlock_base_errors.excl_not_preferred);
2216  if (InterlockedIncrement(&srwlock_seq) != 18)
2217  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2218  pReleaseSRWLockExclusive(&srwlock_base);
2219 
2220  /* skip over remaining tests if TryAcquireSRWLock* is not available */
2221  if (!pTryAcquireSRWLockExclusive)
2222  return 0;
2223 
2224  /* seq 20 */
2225  while (srwlock_seq < 20) Sleep(1);
2226  if (pTryAcquireSRWLockShared(&srwlock_base))
2227  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2228  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2230  if (InterlockedIncrement(&srwlock_seq) != 21)
2231  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2232 
2233  /* seq 22 */
2234  while (srwlock_seq < 22) Sleep(1);
2235  if (pTryAcquireSRWLockShared(&srwlock_base))
2236  pReleaseSRWLockShared(&srwlock_base);
2237  else
2238  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2239  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2241  if (InterlockedIncrement(&srwlock_seq) != 23)
2242  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2243 
2244  /* seq 24 */
2245  while (srwlock_seq < 24) Sleep(1);
2246  Sleep(50); /* ensure that exclusive access request is queued */
2247  if (pTryAcquireSRWLockShared(&srwlock_base))
2248  {
2249  pReleaseSRWLockShared(&srwlock_base);
2250  InterlockedIncrement(&srwlock_base_errors.excl_not_preferred);
2251  }
2252  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2254  if (InterlockedIncrement(&srwlock_seq) != 25)
2255  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2256  pReleaseSRWLockShared(&srwlock_base);
2257 
2258  /* seq 26 */
2259  while (srwlock_seq < 26) Sleep(1);
2260  if (pTryAcquireSRWLockShared(&srwlock_base))
2261  pReleaseSRWLockShared(&srwlock_base);
2262  else
2263  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2264  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2266  if (InterlockedIncrement(&srwlock_seq) != 27)
2267  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2268 
2269  /* seq 28 */
2270  while (srwlock_seq < 28) Sleep(1);
2271  if (pTryAcquireSRWLockShared(&srwlock_base))
2272  pReleaseSRWLockShared(&srwlock_base);
2273  else
2274  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2275  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2277  if (InterlockedIncrement(&srwlock_seq) != 29)
2278  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2279 
2280  /* seq 30 */
2281  while (srwlock_seq < 30) Sleep(1);
2282  if (pTryAcquireSRWLockShared(&srwlock_base))
2283  pReleaseSRWLockShared(&srwlock_base);
2284  else
2285  InterlockedIncrement(&srwlock_base_errors.trylock_shared);
2286  if (pTryAcquireSRWLockExclusive(&srwlock_base))
2287  pReleaseSRWLockExclusive(&srwlock_base);
2288  else
2290  if (InterlockedIncrement(&srwlock_seq) != 31)
2291  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2292 
2293  return 0;
2294 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_seq
Definition: sync.c:1941
static SRWLOCK srwlock_base
Definition: sync.c:1942
static struct @1539 srwlock_base_errors
#define InterlockedIncrement
Definition: armddk.h:53
static DWORD WINAPI srwlock_base_thread3 ( LPVOID  x)
static

Definition at line 2296 of file sync.c.

Referenced by test_srwlock_base().

2297 {
2298  /* seq 15 */
2299  while (srwlock_seq < 15) Sleep(1);
2300  Sleep(50); /* some delay, so that thread2 can try to acquire a second exclusive lock */
2301  if (InterlockedIncrement(&srwlock_seq) != 16)
2302  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2303 
2304  /* seq 18 */
2305  pAcquireSRWLockShared(&srwlock_base);
2306  if (srwlock_seq != 18)
2307  InterlockedIncrement(&srwlock_base_errors.excl_not_preferred);
2308  pReleaseSRWLockShared(&srwlock_base);
2309  if (InterlockedIncrement(&srwlock_seq) != 19)
2310  InterlockedIncrement(&srwlock_base_errors.wrong_execution_order);
2311 
2312  /* skip over remaining tests if TryAcquireSRWLock* is not available */
2313  if (!pTryAcquireSRWLockExclusive)
2314  {
2315  /* function is only in Windows 7 and newer */
2316  win_skip("no srw trylock support.\n");
2317  srwlock_seq = 31; /* end */
2318  return 0;
2319  }
2320 
2321  return 0;
2322 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_seq
Definition: sync.c:1941
static SRWLOCK srwlock_base
Definition: sync.c:1942
static struct @1539 srwlock_base_errors
#define InterlockedIncrement
Definition: armddk.h:53
#define win_skip
Definition: test.h:141
static DWORD WINAPI srwlock_example_thread ( LPVOID  x)
static

Definition at line 2390 of file sync.c.

Referenced by test_srwlock_example().

2390  {
2391  DWORD *cnt = x;
2392  LONG old;
2393 
2394  while (!srwlock_stop)
2395  {
2396 
2397  /* periodically request exclusive access */
2398  if (InterlockedIncrement(&srwlock_cnt) % 13 == 0)
2399  {
2400  pAcquireSRWLockExclusive(&srwlock_example);
2403 
2405  Sleep(1);
2406 
2409  pReleaseSRWLockExclusive(&srwlock_example);
2410  }
2411 
2412  /* request shared access */
2413  pAcquireSRWLockShared(&srwlock_example);
2416 
2417  (*cnt)++;
2418  Sleep(1);
2419 
2420  if (old != srwlock_protected_value)
2423  pReleaseSRWLockShared(&srwlock_example);
2424  }
2425 
2426  return 0;
2427 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_cnt
Definition: sync.c:2387
static LONG srwlock_example_errors
Definition: sync.c:2387
static BOOL srwlock_stop
Definition: sync.c:2388
static LONG srwlock_inside
Definition: sync.c:2387
DWORD DWORD
Definition: winlogon.h:75
long LONG
Definition: pedump.c:60
static LONG srwlock_protected_value
Definition: sync.c:2386
#define InterlockedDecrement
Definition: armddk.h:52
#define InterlockedIncrement
Definition: armddk.h:53
static SRWLOCK srwlock_example
Definition: sync.c:2385
INT x
Definition: msvc.h:62
START_TEST ( sync  )

Definition at line 2641 of file sync.c.

2642 {
2643  char **argv;
2644  int argc;
2645  HMODULE hdll = GetModuleHandleA("kernel32.dll");
2646  HMODULE hntdll = GetModuleHandleA("ntdll.dll");
2647 
2648  pInitOnceInitialize = (void *)GetProcAddress(hdll, "InitOnceInitialize");
2649  pInitOnceExecuteOnce = (void *)GetProcAddress(hdll, "InitOnceExecuteOnce");
2650  pInitOnceBeginInitialize = (void *)GetProcAddress(hdll, "InitOnceBeginInitialize");
2651  pInitOnceComplete = (void *)GetProcAddress(hdll, "InitOnceComplete");
2652  pInitializeConditionVariable = (void *)GetProcAddress(hdll, "InitializeConditionVariable");
2653  pSleepConditionVariableCS = (void *)GetProcAddress(hdll, "SleepConditionVariableCS");
2654  pSleepConditionVariableSRW = (void *)GetProcAddress(hdll, "SleepConditionVariableSRW");
2655  pWakeAllConditionVariable = (void *)GetProcAddress(hdll, "WakeAllConditionVariable");
2656  pWakeConditionVariable = (void *)GetProcAddress(hdll, "WakeConditionVariable");
2657  pInitializeSRWLock = (void *)GetProcAddress(hdll, "InitializeSRWLock");
2658  pAcquireSRWLockExclusive = (void *)GetProcAddress(hdll, "AcquireSRWLockExclusive");
2659  pAcquireSRWLockShared = (void *)GetProcAddress(hdll, "AcquireSRWLockShared");
2660  pReleaseSRWLockExclusive = (void *)GetProcAddress(hdll, "ReleaseSRWLockExclusive");
2661  pReleaseSRWLockShared = (void *)GetProcAddress(hdll, "ReleaseSRWLockShared");
2662  pTryAcquireSRWLockExclusive = (void *)GetProcAddress(hdll, "TryAcquireSRWLockExclusive");
2663  pTryAcquireSRWLockShared = (void *)GetProcAddress(hdll, "TryAcquireSRWLockShared");
2664  pNtAllocateVirtualMemory = (void *)GetProcAddress(hntdll, "NtAllocateVirtualMemory");
2665  pNtFreeVirtualMemory = (void *)GetProcAddress(hntdll, "NtFreeVirtualMemory");
2666  pNtWaitForSingleObject = (void *)GetProcAddress(hntdll, "NtWaitForSingleObject");
2667  pNtWaitForMultipleObjects = (void *)GetProcAddress(hntdll, "NtWaitForMultipleObjects");
2668  pRtlInterlockedPushListSList = (void *)GetProcAddress(hntdll, "RtlInterlockedPushListSList");
2669  pRtlInterlockedPushListSListEx = (void *)GetProcAddress(hntdll, "RtlInterlockedPushListSListEx");
2670 
2671  argc = winetest_get_mainargs( &argv );
2672  if (argc >= 3)
2673  {
2674  if (!strcmp(argv[2], "apc_deadlock"))
2675  {
2676  for (;;) SleepEx(INFINITE, TRUE);
2677  }
2678  return;
2679  }
2680 
2683  test_mutex();
2684  test_slist();
2685  test_event();
2686  test_semaphore();
2689  test_timer_queue();
2692  test_initonce();
2699 }
static void test_semaphore(void)
Definition: sync.c:585
static int argc
Definition: ServiceArgs.c:12
static void test_event(void)
Definition: sync.c:472
#define TRUE
Definition: types.h:120
static void test_slist(void)
Definition: sync.c:301
static void test_alertable_wait(void)
Definition: sync.c:2513
static void test_signalandwait(void)
Definition: sync.c:111
static char ** argv
Definition: ServiceArgs.c:11
static void test_iocp_callback(void)
Definition: sync.c:686
static void test_WaitForMultipleObjects(void)
Definition: sync.c:1276
static void test_condvars_base(void)
Definition: sync.c:1888
static void test_srwlock_example(void)
Definition: sync.c:2429
static void test_initonce(void)
Definition: sync.c:1365
DWORD WINAPI SleepEx(IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:748
static void test_waitable_timer(void)
Definition: sync.c:631
#define init_fastcall_thunk()
Definition: sync.c:106
static void test_WaitForSingleObject(void)
Definition: sync.c:1183
int winetest_get_mainargs(char ***pargv)
static void test_timer_queue(void)
Definition: sync.c:880
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:818
static void test_mutex(void)
Definition: sync.c:189
static PVOID hdll
Definition: shimdbg.c:126
static void test_apc_deadlock(void)
Definition: sync.c:2587
static HINSTANCE hntdll
Definition: process.c:66
HANDLE HMODULE
Definition: typedefs.h:75
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define GetProcAddress(x, y)
Definition: compat.h:410
#define INFINITE
Definition: serial.h:102
static void test_srwlock_base(void)
Definition: sync.c:2324
static void test_condvars_consumer_producer(void)
Definition: sync.c:1661
static void test_alertable_wait ( void  )
static

Definition at line 2513 of file sync.c.

Referenced by START_TEST().

2514 {
2515  HANDLE thread, semaphores[2];
2516  DWORD result;
2517 
2518  semaphores[0] = CreateSemaphoreW(NULL, 0, 2, NULL);
2519  ok(semaphores[0] != NULL, "CreateSemaphore failed with %u\n", GetLastError());
2520  semaphores[1] = CreateSemaphoreW(NULL, 0, 1, NULL);
2521  ok(semaphores[1] != NULL, "CreateSemaphore failed with %u\n", GetLastError());
2522  thread = CreateThread(NULL, 0, alertable_wait_thread, semaphores, 0, NULL);
2523  ok(thread != NULL, "CreateThread failed with %u\n", GetLastError());
2524 
2525  result = WaitForSingleObject(semaphores[0], 1000);
2526  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2527  Sleep(100); /* ensure the thread is blocking in WaitForMultipleObjectsEx */
2528  result = QueueUserAPC(alertable_wait_apc, thread, (ULONG_PTR)semaphores);
2529  ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
2530 
2531  result = WaitForSingleObject(semaphores[0], 1000);
2532  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2533  Sleep(100); /* ensure the thread is blocking in NtWaitForMultipleObjects */
2534  result = QueueUserAPC(alertable_wait_apc, thread, (ULONG_PTR)semaphores);
2535  ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
2536 
2537  result = WaitForSingleObject(semaphores[0], 1000);
2538  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2539  Sleep(100); /* ensure the thread is blocking in NtWaitForMultipleObjects */
2540  result = QueueUserAPC(alertable_wait_apc2, thread, (ULONG_PTR)semaphores);
2541  ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
2542  result = QueueUserAPC(alertable_wait_apc2, thread, (ULONG_PTR)semaphores);
2543  ok(result != 0, "QueueUserAPC failed with %u\n", GetLastError());
2544  ReleaseSemaphore(semaphores[0], 2, NULL);
2545 
2546  result = WaitForSingleObject(thread, 1000);
2547  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2548  CloseHandle(thread);
2549  CloseHandle(semaphores[0]);
2550  CloseHandle(semaphores[1]);
2551 }
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static DWORD WINAPI alertable_wait_thread(void *param)
Definition: sync.c:2467
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
uint32_t ULONG_PTR
Definition: typedefs.h:63
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD WINAPI QueueUserAPC(IN PAPCFUNC pfnAPC, IN HANDLE hThread, IN ULONG_PTR dwData)
Definition: thread.c:932
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:416
static void CALLBACK alertable_wait_apc2(ULONG_PTR userdata)
Definition: sync.c:2504
#define ok(value,...)
Definition: CComObject.cpp:34
#define WAIT_OBJECT_0
Definition: winbase.h:387
static HANDLE thread
Definition: service.c:33
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
static void CALLBACK alertable_wait_apc(ULONG_PTR userdata)
Definition: sync.c:2498
GLuint64EXT * result
Definition: glext.h:11304
static void test_apc_deadlock ( void  )
static

Definition at line 2587 of file sync.c.

Referenced by START_TEST().

2588 {
2589  struct apc_deadlock_info info;
2591  STARTUPINFOA si = { sizeof(si) };
2592  char cmdline[MAX_PATH];
2593  HANDLE event, thread;
2594  DWORD result;
2595  BOOL success;
2596  char **argv;
2597  int i;
2598 
2599  winetest_get_mainargs(&argv);
2600  sprintf(cmdline, "\"%s\" sync apc_deadlock", argv[0]);
2601  success = CreateProcessA(argv[0], cmdline, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
2602  ok(success, "CreateProcess failed with %u\n", GetLastError());
2603 
2604  event = CreateEventA(NULL, FALSE, FALSE, NULL);
2605  ok(event != NULL, "CreateEvent failed with %u\n", GetLastError());
2606 
2607  info.pi = &pi;
2608  info.event = event;
2609  info.running = TRUE;
2610 
2611  thread = CreateThread(NULL, 0, apc_deadlock_thread, &info, 0, NULL);
2612  ok(thread != NULL, "CreateThread failed with %u\n", GetLastError());
2613  result = WaitForSingleObject(event, 1000);
2614  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2615 
2616  for (i = 0; i < 1000; i++)
2617  {
2618  result = SuspendThread(pi.hThread);
2619  ok(result == 0, "expected 0, got %u\n", result);
2620 
2621  WaitForSingleObject(event, 0); /* reset event */
2622  result = WaitForSingleObject(event, 1000);
2623  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2624 
2625  result = ResumeThread(pi.hThread);
2626  ok(result == 1, "expected 1, got %u\n", result);
2627  Sleep(1);
2628  }
2629 
2630  info.running = FALSE;
2631  result = WaitForSingleObject(thread, 1000);
2632  ok(result == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %u\n", result);
2633  CloseHandle(thread);
2634  CloseHandle(event);
2635 
2636  TerminateProcess(pi.hProcess, 0);
2637  CloseHandle(pi.hThread);
2638  CloseHandle(pi.hProcess);
2639 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
TCHAR * cmdline
Definition: stretchblt.cpp:32
DWORD DWORD
Definition: winlogon.h:75
static char ** argv
Definition: ServiceArgs.c:11
#define sprintf(buf, format,...)
Definition: sprintf.c:55
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:583
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
BOOL WINAPI DECLSPEC_HOTPATCH CreateProcessA(LPCSTR lpApplicationName, LPSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCSTR lpCurrentDirectory, LPSTARTUPINFOA lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)
Definition: proc.c:4780
#define MAX_PATH
Definition: compat.h:26
#define success(from, fromstr, to, tostr)
int winetest_get_mainargs(char ***pargv)
static DWORD pi
Definition: protocol.c:150
static HANDLE thread
Definition: service.c:33
DWORD WINAPI SuspendThread(IN HANDLE hThread)
Definition: thread.c:626
static DWORD WINAPI apc_deadlock_thread(void *param)
Definition: sync.c:2560
struct _cl_event * event
Definition: glext.h:7739
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI TerminateProcess(IN HANDLE hProcess, IN UINT uExitCode)
Definition: proc.c:1589
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:551
GLuint64EXT * result
Definition: glext.h:11304
static void test_condvars_base ( void  )
static

Definition at line 1888 of file sync.c.

Referenced by START_TEST().

1888  {
1889  HANDLE hp, hc;
1890  DWORD dummy;
1891  BOOL ret;
1892 
1893 
1894  if (!pInitializeConditionVariable) {
1895  /* function is not yet in XP, only in newer Windows */
1896  win_skip("no condition variable support.\n");
1897  return;
1898  }
1899 
1901 
1902  if (pInitializeSRWLock)
1903  pInitializeSRWLock(&condvar_srwlock);
1904 
1906  ret = pSleepConditionVariableCS(&condvar_base, &condvar_crit, 10);
1908 
1909  ok (!ret, "SleepConditionVariableCS should return FALSE on untriggered condvar\n");
1910  ok (GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableCS should return ERROR_TIMEOUT on untriggered condvar, not %d\n", GetLastError());
1911 
1912  if (pInitializeSRWLock)
1913  {
1914  pAcquireSRWLockExclusive(&condvar_srwlock);
1915  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 10, 0);
1916  pReleaseSRWLockExclusive(&condvar_srwlock);
1917 
1918  ok(!ret, "SleepConditionVariableSRW should return FALSE on untriggered condvar\n");
1919  ok(GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableSRW should return ERROR_TIMEOUT on untriggered condvar, not %d\n", GetLastError());
1920 
1921  pAcquireSRWLockShared(&condvar_srwlock);
1922  ret = pSleepConditionVariableSRW(&condvar_base, &condvar_srwlock, 10, CONDITION_VARIABLE_LOCKMODE_SHARED);
1923  pReleaseSRWLockShared(&condvar_srwlock);
1924 
1925  ok(!ret, "SleepConditionVariableSRW should return FALSE on untriggered condvar\n");
1926  ok(GetLastError() == ERROR_TIMEOUT, "SleepConditionVariableSRW should return ERROR_TIMEOUT on untriggered condvar, not %d\n", GetLastError());
1927  }
1928 
1929 
1930  hp = CreateThread(NULL, 0, condvar_base_producer, NULL, 0, &dummy);
1931  hc = CreateThread(NULL, 0, condvar_base_consumer, NULL, 0, &dummy);
1932 
1933  condvar_seq = 1; /* go */
1934 
1935  while (condvar_seq < 9)
1936  Sleep (5);
1937  WaitForSingleObject(hp, 100);
1938  WaitForSingleObject(hc, 100);
1939 }
static CRITICAL_SECTION condvar_crit
Definition: sync.c:1730
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static CONDITION_VARIABLE condvar_base
Definition: sync.c:1729
#define ERROR_TIMEOUT
Definition: winerror.h:941
static SRWLOCK condvar_srwlock
Definition: sync.c:1731
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
static DWORD WINAPI condvar_base_consumer(LPVOID x)
Definition: sync.c:1805
unsigned int BOOL
Definition: ntddk_ex.h:94
int ret
static DWORD WINAPI condvar_base_producer(LPVOID x)
Definition: sync.c:1752
DWORD *typedef HANDLE
Definition: winlogon.h:52
unsigned char dummy
Definition: maze.c:118
static DWORD condvar_seq
Definition: sync.c:1728
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
#define win_skip
Definition: test.h:141
static void test_condvars_consumer_producer ( void  )
static

Definition at line 1661 of file sync.c.

Referenced by START_TEST().

1662 {
1663  HANDLE hp1,hp2,hp3,hc1,hc2,hc3;
1664  DWORD dummy;
1665  DWORD cnt1,cnt2,cnt3;
1666 
1667  if (!pInitializeConditionVariable) {
1668  /* function is not yet in XP, only in newer Windows */
1669  win_skip("no condition variable support.\n");
1670  return;
1671  }
1672 
1673  /* Implement a producer / consumer scheme with non-full / non-empty triggers */
1674 
1675  /* If we have static initialized condition variables, InitializeConditionVariable
1676  * is not strictly necessary.
1677  * pInitializeConditionVariable(&buffernotfull);
1678  */
1679  pInitializeConditionVariable(&buffernotempty);
1681 
1682  /* Larger Test: consumer/producer example */
1683 
1684  bufferlen = totalproduced = totalconsumed = cnt1 = cnt2 = cnt3 = 0;
1685 
1686  hp1 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
1687  hp2 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
1688  hp3 = CreateThread(NULL, 0, condvar_producer, NULL, 0, &dummy);
1689  hc1 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt1, 0, &dummy);
1690  hc2 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt2, 0, &dummy);
1691  hc3 = CreateThread(NULL, 0, condvar_consumer, (PVOID)&cnt3, 0, &dummy);
1692 
1693  /* Limit run to 0.5 seconds. */
1694  Sleep(500);
1695 
1696  /* tear down start */
1697  condvar_stop = TRUE;
1698 
1699  /* final wake up call */
1700  pWakeAllConditionVariable (&buffernotfull);
1701  pWakeAllConditionVariable (&buffernotempty);
1702 
1703  /* (mostly an implementation detail)
1704  * ok(buffernotfull.Ptr == NULL, "buffernotfull.Ptr is %p\n", buffernotfull.Ptr);
1705  */
1706 
1707  WaitForSingleObject(hp1, 1000);
1708  WaitForSingleObject(hp2, 1000);
1709  WaitForSingleObject(hp3, 1000);
1710  WaitForSingleObject(hc1, 1000);
1711  WaitForSingleObject(hc2, 1000);
1712  WaitForSingleObject(hc3, 1000);
1713 
1715  "consumed %d != produced %d\n", totalconsumed, totalproduced);
1716  ok (!condvar_sleeperr, "error occurred during SleepConditionVariableCS\n");
1717 
1718  /* Checking cnt1 - cnt2 for non-0 would be not good, the case where
1719  * one consumer does not get anything to do is possible. */
1720  trace("produced %d, c1 %d, c2 %d, c3 %d\n", totalproduced, cnt1, cnt2, cnt3);
1721  /* The sleeps of the producer or consumer should not go above 100* produced count,
1722  * otherwise the implementation does not sleep correctly. But yet again, this is
1723  * not hard defined. */
1724  trace("producer sleep %d, consumer sleep %d\n", condvar_producer_sleepcnt, condvar_consumer_sleepcnt);
1725 }
DWORD *typedef PVOID
Definition: winlogon.h:52
#define trace(...)
Definition: kmt_test.h:217
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG condvar_consumer_sleepcnt
Definition: sync.c:1601
static BOOL condvar_stop
Definition: sync.c:1599
static LONG bufferlen
Definition: sync.c:1600
static LONG totalconsumed
Definition: sync.c:1600
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static DWORD WINAPI condvar_consumer(LPVOID x)
Definition: sync.c:1633
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:697
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
static CONDITION_VARIABLE buffernotfull
Definition: sync.c:1597
static LONG condvar_producer_sleepcnt
Definition: sync.c:1601
DWORD *typedef HANDLE
Definition: winlogon.h:52
unsigned char dummy
Definition: maze.c:118
static CONDITION_VARIABLE buffernotempty
Definition: sync.c:1596
static DWORD WINAPI condvar_producer(LPVOID x)
Definition: sync.c:1605
static CRITICAL_SECTION buffercrit
Definition: sync.c:1598
static BOOL condvar_sleeperr
Definition: sync.c:1599
static LONG totalproduced
Definition: sync.c:1600
#define win_skip
Definition: test.h:141
static void test_event ( void  )
static

Definition at line 472 of file sync.c.

Referenced by START_TEST().

473 {
474  HANDLE handle, handle2;
477  ACL acl;
478  DWORD ret;
479  BOOL val;
480 
481  /* no sd */
482  handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
483  ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
484  CloseHandle(handle);
485 
486  sa.nLength = sizeof(sa);
487  sa.lpSecurityDescriptor = &sd;
488  sa.bInheritHandle = FALSE;
489 
491 
492  /* blank sd */
493  handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
494  ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
495  CloseHandle(handle);
496 
497  /* sd with NULL dacl */
499  handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
500  ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
501  CloseHandle(handle);
502 
503  /* sd with empty dacl */
504  InitializeAcl(&acl, sizeof(acl), ACL_REVISION);
505  SetSecurityDescriptorDacl(&sd, TRUE, &acl, FALSE);
506  handle = CreateEventA(&sa, FALSE, FALSE, __FILE__ ": Test Event");
507  ok(handle != NULL, "CreateEventW with blank sd failed with error %d\n", GetLastError());
508  CloseHandle(handle);
509 
510  /* test case sensitivity */
511 
512  SetLastError(0xdeadbeef);
513  handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
514  ok( handle != NULL, "CreateEvent failed with error %u\n", GetLastError());
515  ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
516 
517  SetLastError(0xdeadbeef);
518  handle2 = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
519  ok( handle2 != NULL, "CreateEvent failed with error %d\n", GetLastError());
520  ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
521  CloseHandle( handle2 );
522 
523  SetLastError(0xdeadbeef);
524  handle2 = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": TEST EVENT");
525  ok( handle2 != NULL, "CreateEvent failed with error %d\n", GetLastError());
526  ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
527  CloseHandle( handle2 );
528 
529  SetLastError(0xdeadbeef);
530  handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, __FILE__ ": Test Event");
531  ok( handle2 != NULL, "OpenEvent failed with error %d\n", GetLastError());
532  CloseHandle( handle2 );
533 
534  SetLastError(0xdeadbeef);
535  handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, __FILE__ ": TEST EVENT");
536  ok( !handle2, "OpenEvent succeeded\n");
537  ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
538 
539  SetLastError(0xdeadbeef);
540  handle2 = OpenEventA( EVENT_ALL_ACCESS, FALSE, NULL );
541  ok( !handle2, "OpenEvent succeeded\n");
542  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
543 
544  SetLastError(0xdeadbeef);
545  handle2 = OpenEventW( EVENT_ALL_ACCESS, FALSE, NULL );
546  ok( !handle2, "OpenEvent succeeded\n");
547  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
548 
549  CloseHandle( handle );
550 
551  /* resource notifications are events too */
552 
553  if (!pCreateMemoryResourceNotification || !pQueryMemoryResourceNotification)
554  {
555  trace( "memory resource notifications not supported\n" );
556  return;
557  }
558  handle = pCreateMemoryResourceNotification( HighMemoryResourceNotification + 1 );
559  ok( !handle, "CreateMemoryResourceNotification succeeded\n" );
560  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
561  ret = pQueryMemoryResourceNotification( handle, &val );
562  ok( !ret, "QueryMemoryResourceNotification succeeded\n" );
563  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
564 
565  handle = pCreateMemoryResourceNotification( LowMemoryResourceNotification );
566  ok( handle != 0, "CreateMemoryResourceNotification failed err %u\n", GetLastError() );
567  ret = WaitForSingleObject( handle, 10 );
568  ok( ret == WAIT_OBJECT_0 || ret == WAIT_TIMEOUT, "WaitForSingleObject wrong ret %u\n", ret );
569 
570  val = ~0;
571  ret = pQueryMemoryResourceNotification( handle, &val );
572  ok( ret, "QueryMemoryResourceNotification failed err %u\n", GetLastError() );
573  ok( val == FALSE || val == TRUE, "wrong value %u\n", val );
574  ret = CloseHandle( handle );
575  ok( ret, "CloseHandle failed err %u\n", GetLastError() );
576 
577  handle = CreateEventA(NULL, FALSE, FALSE, __FILE__ ": Test Event");
578  val = ~0;
579  ret = pQueryMemoryResourceNotification( handle, &val );
580  ok( ret, "QueryMemoryResourceNotification failed err %u\n", GetLastError() );
581  ok( val == FALSE || val == TRUE, "wrong value %u\n", val );
582  CloseHandle( handle );
583 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define trace(...)
Definition: kmt_test.h:217
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:881
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:804
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:628
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
HANDLE WINAPI DECLSPEC_HOTPATCH OpenEventA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:615
#define EVENT_ALL_ACCESS
Definition: isotest.c:82
smooth NULL
Definition: ftsmooth.c:416
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventA(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:583
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
GLuint GLfloat * val
Definition: glext.h:7180
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define SetLastError(x)
Definition: compat.h:409
#define WAIT_TIMEOUT
Definition: dderror.h:14
static const WCHAR sd[]
Definition: suminfo.c:287
int ret
DWORD *typedef HANDLE
Definition: winlogon.h:52
LPVOID lpSecurityDescriptor
Definition: compat.h:181
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
#define ACL_REVISION
Definition: setypes.h:39
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
static void test_initonce ( void  )
static

Definition at line 1365 of file sync.c.

Referenced by START_TEST().

1366 {
1367  INIT_ONCE initonce;
1368  BOOL ret, pending;
1369 
1370  if (!pInitOnceInitialize || !pInitOnceExecuteOnce)
1371  {
1372  win_skip("one-time initialization API not supported\n");
1373  return;
1374  }
1375 
1376  /* blocking initialization with callback */
1377  initonce.Ptr = (void*)0xdeadbeef;
1378  pInitOnceInitialize(&initonce);
1379  ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
1380 
1381  /* initialisation completed successfully */
1383  g_initctxt = NULL;
1384  ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
1385  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1386  ok(initonce.Ptr == (void*)0x2, "got %p\n", initonce.Ptr);
1387  ok(g_initctxt == NULL, "got %p\n", g_initctxt);
1389 
1390  /* so it's been called already so won't be called again */
1391  g_initctxt = NULL;
1393  ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
1394  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1395  ok(initonce.Ptr == (void*)0x2, "got %p\n", initonce.Ptr);
1396  ok(g_initctxt == NULL, "got %p\n", g_initctxt);
1398 
1399  pInitOnceInitialize(&initonce);
1401  /* 2 lower order bits should never be used, you'll get a crash in result */
1402  g_initctxt = (void*)0xFFFFFFF0;
1403  ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
1404  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1405  ok(initonce.Ptr == (void*)0xFFFFFFF2, "got %p\n", initonce.Ptr);
1406  ok(g_initctxt == (void*)0xFFFFFFF0, "got %p\n", g_initctxt);
1408 
1409  /* callback failed */
1412  g_initctxt = NULL;
1413  pInitOnceInitialize(&initonce);
1414  SetLastError( 0xdeadbeef );
1415  ret = pInitOnceExecuteOnce(&initonce, initonce_callback, (void*)0xdeadbeef, &g_initctxt);
1416  ok(!ret && GetLastError() == 0xdeadbeef, "got wrong ret value %d err %u\n", ret, GetLastError());
1417  ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
1418  ok(g_initctxt == NULL, "got %p\n", g_initctxt);
1420 
1421  /* blocking initialization without a callback */
1422  pInitOnceInitialize(&initonce);
1423  g_initctxt = NULL;
1424  pending = FALSE;
1425  ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
1426  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1427  ok(pending, "got %d\n", pending);
1428  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1429  ok(g_initctxt == NULL, "got %p\n", g_initctxt);
1430  /* another attempt to begin initialization with block a single thread */
1431 
1432  g_initctxt = NULL;
1433  pending = 0xf;
1434  SetLastError( 0xdeadbeef );
1435  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1436  ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
1437  ok(pending == 0xf, "got %d\n", pending);
1438  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1439  ok(g_initctxt == NULL, "got %p\n", g_initctxt);
1440 
1441  g_initctxt = (void*)0xdeadbee0;
1442  SetLastError( 0xdeadbeef );
1443  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, g_initctxt);
1444  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1445  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1446 
1447  /* once failed already */
1448  g_initctxt = (void*)0xdeadbee0;
1449  ret = pInitOnceComplete(&initonce, 0, g_initctxt);
1450  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1451  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1452 
1453  pInitOnceInitialize(&initonce);
1454  SetLastError( 0xdeadbeef );
1455  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
1456  ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
1457  ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
1458 
1459  SetLastError( 0xdeadbeef );
1460  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
1461  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1462  ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
1463 
1464  ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
1465  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1466  ok(pending, "got %d\n", pending);
1467  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1468 
1469  SetLastError( 0xdeadbeef );
1470  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
1471  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1472 
1473  SetLastError( 0xdeadbeef );
1474  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
1475  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1476  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1477 
1478  SetLastError( 0xdeadbeef );
1479  ret = pInitOnceComplete(&initonce, 0, (void *)0xdeadbeef);
1480  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1481  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1482 
1483  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
1484  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1485  ok(initonce.Ptr == NULL, "got %p\n", initonce.Ptr);
1486 
1487  pInitOnceInitialize(&initonce);
1488  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
1489  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1490  ok(pending, "got %d\n", pending);
1491  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1492 
1493  SetLastError( 0xdeadbeef );
1494  ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
1495  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1496 
1497  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
1498  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1499  ok(pending, "got %d\n", pending);
1500  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1501 
1502  SetLastError( 0xdeadbeef );
1503  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED, NULL);
1504  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1505  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1506 
1507  SetLastError( 0xdeadbeef );
1508  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
1509  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1510  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1511 
1512  SetLastError( 0xdeadbeef );
1513  ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbeef);
1514  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1515  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1516 
1517  ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbee0);
1518  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1519  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1520 
1521  SetLastError( 0xdeadbeef );
1522  ret = pInitOnceComplete(&initonce, INIT_ONCE_INIT_FAILED | INIT_ONCE_ASYNC, NULL);
1523  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1524  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1525 
1526  pInitOnceInitialize(&initonce);
1527  ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
1528  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1529  ok(pending, "got %d\n", pending);
1530  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1531 
1532  /* test INIT_ONCE_CHECK_ONLY */
1533 
1534  pInitOnceInitialize(&initonce);
1535  SetLastError( 0xdeadbeef );
1536  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1537  ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
1538  SetLastError( 0xdeadbeef );
1539  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
1540  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1541 
1542  ret = pInitOnceBeginInitialize(&initonce, 0, &pending, &g_initctxt);
1543  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1544  ok(pending, "got %d\n", pending);
1545  ok(initonce.Ptr == (void*)1, "got %p\n", initonce.Ptr);
1546 
1547  SetLastError( 0xdeadbeef );
1548  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1549  ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
1550  SetLastError( 0xdeadbeef );
1551  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
1552  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1553 
1554  ret = pInitOnceComplete(&initonce, 0, (void *)0xdeadbee0);
1555  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1556  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1557 
1558  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1559  ok(ret, "got wrong ret value %d err %u\n", ret, GetLastError());
1560  ok(!pending, "got %d\n", pending);
1561  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1562  ok(g_initctxt == (void*)0xdeadbee0, "got %p\n", initonce.Ptr);
1563 
1564  SetLastError( 0xdeadbeef );
1565  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
1566  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1567 
1568  pInitOnceInitialize(&initonce);
1569  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_ASYNC, &pending, &g_initctxt);
1570  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1571  ok(pending, "got %d\n", pending);
1572  ok(initonce.Ptr == (void*)3, "got %p\n", initonce.Ptr);
1573 
1574  SetLastError( 0xdeadbeef );
1575  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1576  ok(!ret && GetLastError() == ERROR_GEN_FAILURE, "wrong ret %d err %u\n", ret, GetLastError());
1577  SetLastError( 0xdeadbeef );
1578  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
1579  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1580 
1581  ret = pInitOnceComplete(&initonce, INIT_ONCE_ASYNC, (void *)0xdeadbee0);
1582  ok(ret, "wrong ret %d err %u\n", ret, GetLastError());
1583  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1584 
1585  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY, &pending, &g_initctxt);
1586  ok(ret, "got wrong ret value %d err %u\n", ret, GetLastError());
1587  ok(!pending, "got %d\n", pending);
1588  ok(initonce.Ptr == (void*)0xdeadbee2, "got %p\n", initonce.Ptr);
1589  ok(g_initctxt == (void*)0xdeadbee0, "got %p\n", initonce.Ptr);
1590 
1591  SetLastError( 0xdeadbeef );
1592  ret = pInitOnceBeginInitialize(&initonce, INIT_ONCE_CHECK_ONLY|INIT_ONCE_ASYNC, &pending, &g_initctxt);
1593  ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "wrong ret %d err %u\n", ret, GetLastError());
1594 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
static void * g_initctxt
Definition: sync.c:1353
#define INIT_ONCE_ASYNC
Definition: winbase.h:3750
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
static BOOL CALLBACK initonce_callback(INIT_ONCE *initonce, void *parameter, void **ctxt)
Definition: sync.c:1355
#define FALSE
Definition: types.h:117
#define INIT_ONCE_INIT_FAILED
Definition: winbase.h:3751
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
static BOOL g_initcallback_called
Definition: sync.c:1352
unsigned int BOOL
Definition: ntddk_ex.h:94
#define SetLastError(x)
Definition: compat.h:409
int ret
#define INIT_ONCE_CHECK_ONLY
Definition: winbase.h:3749
static BOOL g_initcallback_ret
Definition: sync.c:1352
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG _In_ LONG _In_ LONG x2
Definition: winddi.h:3706
#define ERROR_GEN_FAILURE
Definition: winerror.h:134
#define win_skip
Definition: test.h:141
static void test_iocp_callback ( void  )
static

Definition at line 686 of file sync.c.

Referenced by START_TEST().

687 {
688  char temp_path[MAX_PATH];
689  char filename[MAX_PATH];
690  DWORD ret;
691  BOOL retb;
692  static const char prefix[] = "pfx";
693  HANDLE hFile;
694  HMODULE hmod = GetModuleHandleA("kernel32.dll");
696  const char *buffer = "12345678123456781234567812345678";
698 
699  p_BindIoCompletionCallback = (void*)GetProcAddress(hmod, "BindIoCompletionCallback");
700  if(!p_BindIoCompletionCallback) {
701  win_skip("BindIoCompletionCallback not found in this DLL\n");
702  return;
703  }
704 
705  sem = CreateSemaphoreW(NULL, 0, 1, NULL);
706  ok(sem != INVALID_HANDLE_VALUE, "Creating a semaphore failed\n");
707 
708  ret = GetTempPathA(MAX_PATH, temp_path);
709  ok(ret != 0, "GetTempPathA error %d\n", GetLastError());
710  ok(ret < MAX_PATH, "temp path should fit into MAX_PATH\n");
711 
712  ret = GetTempFileNameA(temp_path, prefix, 0, filename);
713  ok(ret != 0, "GetTempFileNameA error %d\n", GetLastError());
714 
715  hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
717  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
718 
719  retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
720  ok(retb == FALSE, "BindIoCompletionCallback succeeded on a file that wasn't created with FILE_FLAG_OVERLAPPED\n");
721  ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
722 
723  ret = CloseHandle(hFile);
724  ok( ret, "CloseHandle: error %d\n", GetLastError());
725  ret = DeleteFileA(filename);
726  ok( ret, "DeleteFileA: error %d\n", GetLastError());
727 
728  hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
730  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
731 
732  retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
733  ok(retb == TRUE, "BindIoCompletionCallback failed\n");
734 
735  memset(&overlapped, 0, sizeof(overlapped));
736  retb = WriteFile(hFile, buffer, 4, &bytesWritten, &overlapped);
737  ok(retb == TRUE || GetLastError() == ERROR_IO_PENDING, "WriteFile failed, lastError = %d\n", GetLastError());
738 
739  ret = WaitForSingleObject(sem, 5000);
740  ok(ret == WAIT_OBJECT_0, "Wait for the IO completion callback failed\n");
741  CloseHandle(sem);
742 
743  retb = p_BindIoCompletionCallback(hFile, iocp_callback, 0);
744  ok(retb == FALSE, "BindIoCompletionCallback succeeded when setting the same callback on the file again\n");
745  ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
746  retb = p_BindIoCompletionCallback(hFile, NULL, 0);
747  ok(retb == FALSE, "BindIoCompletionCallback succeeded when setting the callback to NULL\n");
748  ok(GetLastError() == ERROR_INVALID_PARAMETER, "Last error is %d\n", GetLastError());
749 
750  ret = CloseHandle(hFile);
751  ok( ret, "CloseHandle: error %d\n", GetLastError());
752  ret = DeleteFileA(filename);
753  ok( ret, "DeleteFileA: error %d\n", GetLastError());
754 
755  /* win2k3 requires the Flags parameter to be zero */
756  SetLastError(0xdeadbeef);
757  hFile = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
759  ok(hFile != INVALID_HANDLE_VALUE, "CreateFileA: error %d\n", GetLastError());
760  retb = p_BindIoCompletionCallback(hFile, iocp_callback, 12345);
761  if (!retb)
763  "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
764  else
765  ok(retb == TRUE, "BindIoCompletionCallback failed with Flags != 0\n");
766  ret = CloseHandle(hFile);
767  ok( ret, "CloseHandle: error %d\n", GetLastError());
768  ret = DeleteFileA(filename);
769  ok( ret, "DeleteFileA: error %d\n", GetLastError());
770 
771  retb = p_BindIoCompletionCallback(NULL, iocp_callback, 0);
772  ok(retb == FALSE, "BindIoCompletionCallback succeeded on a NULL file\n");
774  GetLastError() == ERROR_INVALID_PARAMETER, /* vista */
775  "Last error is %d\n", GetLastError());
776 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
GLuint buffer
Definition: glext.h:5915
const char * filename
Definition: ioapi.h:135
#define ERROR_IO_PENDING
Definition: dderror.h:15
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
#define ok(value,...)
Definition: CComObject.cpp:34
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define MAX_PATH
Definition: compat.h:26
#define SetLastError(x)
Definition: compat.h:409
int ret
const XML_Char * prefix
Definition: expat.h:380
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:818
#define GENERIC_READ
Definition: compat.h:124
_In_ HANDLE hFile
Definition: mswsock.h:90
static PEXPLICIT_ACCESSW *static HMODULE hmod
Definition: security.c:141
GLenum GLsizei GLuint GLint * bytesWritten
Definition: glext.h:11123
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED * overlapped
Definition: sock.c:82
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD *typedef HANDLE
Definition: winlogon.h:52
DWORD WINAPI GetTempPathA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
Definition: path.c:2054
static HANDLE sem
Definition: sync.c:677
static void CALLBACK iocp_callback(DWORD dwErrorCode, DWORD dwNumberOfBytesTransferred, LPOVERLAPPED lpOverlapped)
Definition: sync.c:679
HANDLE HMODULE
Definition: typedefs.h:75
#define GetProcAddress(x, y)
Definition: compat.h:410
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:141
UINT WINAPI GetTempFileNameA(IN LPCSTR lpPathName, IN LPCSTR lpPrefixString, IN UINT uUnique, OUT LPSTR lpTempFileName)
Definition: filename.c:26
#define FILE_FLAG_RANDOM_ACCESS
Definition: disk.h:44
static void test_mutex ( void  )
static

Definition at line 189 of file sync.c.

Referenced by START_TEST().

190 {
191  DWORD wait_ret;
192  BOOL ret;
193  HANDLE hCreated;
194  HANDLE hOpened;
195  int i;
196  DWORD failed = 0;
197 
198  SetLastError(0xdeadbeef);
199  hOpened = OpenMutexA(0, FALSE, "WineTestMutex");
200  ok(hOpened == NULL, "OpenMutex succeeded\n");
201  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
202 
203  SetLastError(0xdeadbeef);
204  hCreated = CreateMutexA(NULL, FALSE, "WineTestMutex");
205  ok(hCreated != NULL, "CreateMutex failed with error %d\n", GetLastError());
206 
207  SetLastError(0xdeadbeef);
208  hOpened = OpenMutexA(0, FALSE, "WineTestMutex");
209 todo_wine
210  ok(hOpened == NULL, "OpenMutex succeeded\n");
211 todo_wine
212  ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError());
213 
214  SetLastError(0xdeadbeef);
215  hOpened = OpenMutexA(GENERIC_EXECUTE, FALSE, "WineTestMutex");
216  ok(hOpened != NULL, "OpenMutex failed with error %d\n", GetLastError());
217  wait_ret = WaitForSingleObject(hOpened, INFINITE);
218  ok(wait_ret == WAIT_OBJECT_0, "WaitForSingleObject failed with error %d\n", GetLastError());
219  CloseHandle(hOpened);
220 
221  for(i=0; i < 31; i++)
222  {
223  wait_ret = WaitForSingleObject(hCreated, INFINITE);
224  ok(wait_ret == WAIT_OBJECT_0, "WaitForSingleObject failed with error 0x%08x\n", wait_ret);
225  }
226 
227  SetLastError(0xdeadbeef);
228  hOpened = OpenMutexA(GENERIC_READ | GENERIC_WRITE, FALSE, "WineTestMutex");
229  ok(hOpened != NULL, "OpenMutex failed with error %d\n", GetLastError());
230  wait_ret = WaitForSingleObject(hOpened, INFINITE);
231  ok(wait_ret == WAIT_FAILED, "WaitForSingleObject succeeded\n");
232  CloseHandle(hOpened);
233 
234  for (i = 0; i < 32; i++)
235  {
236  SetLastError(0xdeadbeef);
237  hOpened = OpenMutexA(0x1 << i, FALSE, "WineTestMutex");
238  if(hOpened != NULL)
239  {
240  SetLastError(0xdeadbeef);
241  ret = ReleaseMutex(hOpened);
242  ok(ret, "ReleaseMutex failed with error %d, access %x\n", GetLastError(), 1 << i);
243  CloseHandle(hOpened);
244  }
245  else
246  {
247  if ((1 << i) == ACCESS_SYSTEM_SECURITY)
248  todo_wine ok(GetLastError() == ERROR_PRIVILEGE_NOT_HELD, "wrong error %u, access %x\n", GetLastError(), 1 << i);
249  else
250  todo_wine ok(GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u, , access %x\n", GetLastError(), 1 << i);
251  ReleaseMutex(hCreated);
252  failed |=0x1 << i;
253  }
254  }
255 
256 todo_wine
257  ok( failed == 0x0de0fffe, "open succeeded when it shouldn't: %x\n", failed);
258 
259  SetLastError(0xdeadbeef);
260  ret = ReleaseMutex(hCreated);
261  ok(!ret && (GetLastError() == ERROR_NOT_OWNER),
262  "ReleaseMutex should have failed with ERROR_NOT_OWNER instead of %d\n", GetLastError());
263 
264  /* test case sensitivity */
265 
266  SetLastError(0xdeadbeef);
267  hOpened = OpenMutexA(READ_CONTROL, FALSE, "WINETESTMUTEX");
268  ok(!hOpened, "OpenMutex succeeded\n");
269  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
270 
271  SetLastError(0xdeadbeef);
272  hOpened = OpenMutexA(READ_CONTROL, FALSE, "winetestmutex");
273  ok(!hOpened, "OpenMutex succeeded\n");
274  ok(GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
275 
276  SetLastError(0xdeadbeef);
277  hOpened = OpenMutexA(READ_CONTROL, FALSE, NULL);
278  ok(!hOpened, "OpenMutex succeeded\n");
279  ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
280 
281  SetLastError(0xdeadbeef);
282  hOpened = OpenMutexW(READ_CONTROL, FALSE, NULL);
283  ok(!hOpened, "OpenMutex succeeded\n");
284  ok(GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
285 
286  SetLastError(0xdeadbeef);
287  hOpened = CreateMutexA(NULL, FALSE, "WineTestMutex");
288  ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError());
289  ok(GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
290  CloseHandle(hOpened);
291 
292  SetLastError(0xdeadbeef);
293  hOpened = CreateMutexA(NULL, FALSE, "WINETESTMUTEX");
294  ok(hOpened != NULL, "CreateMutex failed with error %d\n", GetLastError());
295  ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
296  CloseHandle(hOpened);
297 
298  CloseHandle(hCreated);
299 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define CloseHandle
Definition: compat.h:398
#define ACCESS_SYSTEM_SECURITY
Definition: nt_native.h:77
#define ERROR_PRIVILEGE_NOT_HELD
Definition: winerror.h:796
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:538
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
#define ERROR_ACCESS_DENIED
Definition: compat.h:87
#define GENERIC_WRITE
Definition: nt_native.h:90
HANDLE WINAPI DECLSPEC_HOTPATCH OpenMutexW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:551
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_NOT_OWNER
Definition: winerror.h:301
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
#define WAIT_FAILED
Definition: winbase.h:394
#define SetLastError(x)
Definition: compat.h:409
#define READ_CONTROL
Definition: nt_native.h:58
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseMutex(IN HANDLE hMutex)
Definition: synch.c:564
int ret
#define todo_wine
Definition: test.h:154
#define GENERIC_READ
Definition: compat.h:124
DWORD *typedef HANDLE
Definition: winlogon.h:52
HANDLE WINAPI DECLSPEC_HOTPATCH CreateMutexA(IN LPSECURITY_ATTRIBUTES lpMutexAttributes OPTIONAL, IN BOOL bInitialOwner, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:509
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define INFINITE
Definition: serial.h:102
#define GENERIC_EXECUTE
Definition: nt_native.h:91
static void test_semaphore ( void  )
static

Definition at line 585 of file sync.c.

Referenced by START_TEST().

586 {
587  HANDLE handle, handle2;
588 
589  /* test case sensitivity */
590 
591  SetLastError(0xdeadbeef);
592  handle = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": Test Semaphore");
593  ok(handle != NULL, "CreateSemaphore failed with error %u\n", GetLastError());
594  ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
595 
596  SetLastError(0xdeadbeef);
597  handle2 = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": Test Semaphore");
598  ok( handle2 != NULL, "CreateSemaphore failed with error %d\n", GetLastError());
599  ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
600  CloseHandle( handle2 );
601 
602  SetLastError(0xdeadbeef);
603  handle2 = CreateSemaphoreA(NULL, 0, 1, __FILE__ ": TEST SEMAPHORE");
604  ok( handle2 != NULL, "CreateSemaphore failed with error %d\n", GetLastError());
605  ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
606  CloseHandle( handle2 );
607 
608  SetLastError(0xdeadbeef);
609  handle2 = OpenSemaphoreA( SEMAPHORE_ALL_ACCESS, FALSE, __FILE__ ": Test Semaphore");
610  ok( handle2 != NULL, "OpenSemaphore failed with error %d\n", GetLastError());
611  CloseHandle( handle2 );
612 
613  SetLastError(0xdeadbeef);
614  handle2 = OpenSemaphoreA( SEMAPHORE_ALL_ACCESS, FALSE, __FILE__ ": TEST SEMAPHORE");
615  ok( !handle2, "OpenSemaphore succeeded\n");
616  ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
617 
618  SetLastError(0xdeadbeef);
620  ok( !handle2, "OpenSemaphore succeeded\n");
621  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
622 
623  SetLastError(0xdeadbeef);
625  ok( !handle2, "OpenSemaphore succeeded\n");
626  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
627 
628  CloseHandle( handle );
629 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define CloseHandle
Definition: compat.h:398
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCSTR lpName OPTIONAL)
Definition: synch.c:430
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define ok(value,...)
Definition: CComObject.cpp:34
#define SetLastError(x)
Definition: compat.h:409
DWORD *typedef HANDLE
Definition: winlogon.h:52
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpName)
Definition: synch.c:462
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
#define SEMAPHORE_ALL_ACCESS
Definition: winbase.h:160
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:475
static void test_signalandwait ( void  )
static

Definition at line 111 of file sync.c.

Referenced by START_TEST().

112 {
113  DWORD r;
114  HANDLE event[2], semaphore[2], file;
115  int i;
116 
117  /* invalid parameters */
118  r = SignalObjectAndWait(NULL, NULL, 0, 0);
119  ok( r == WAIT_FAILED, "should fail\n");
120 
121  event[0] = CreateEventW(NULL, 0, 0, NULL);
122  event[1] = CreateEventW(NULL, 1, 1, NULL);
123 
124  ok( event[0] && event[1], "failed to create event flags\n");
125 
126  r = SignalObjectAndWait(event[0], NULL, 0, FALSE);
127  ok( r == WAIT_FAILED, "should fail\n");
128 
129  r = SignalObjectAndWait(NULL, event[0], 0, FALSE);
130  ok( r == WAIT_FAILED, "should fail\n");
131 
132 
133  /* valid parameters */
134  r = SignalObjectAndWait(event[0], event[1], 0, FALSE);
135  ok( r == WAIT_OBJECT_0, "should succeed\n");
136 
137  /* event[0] is now signalled - we repeat this test multiple times
138  * to ensure that the wineserver handles this situation properly. */
139  for (i = 0; i < 10000; i++)
140  {
141  r = SignalObjectAndWait(event[0], event[0], 0, FALSE);
142  ok(r == WAIT_OBJECT_0, "should succeed\n");
143  }
144 
145  /* event[0] is not signalled */
146  r = WaitForSingleObject(event[0], 0);
147  ok( r == WAIT_TIMEOUT, "event was signalled\n");
148 
149  r = SignalObjectAndWait(event[0], event[0], 0, FALSE);
150  ok( r == WAIT_OBJECT_0, "should succeed\n");
151 
152  /* clear event[1] and check for a timeout */
153  ok(ResetEvent(event[1]), "failed to clear event[1]\n");
154  r = SignalObjectAndWait(event[0], event[1], 0, FALSE);
155  ok( r == WAIT_TIMEOUT, "should timeout\n");
156 
157  CloseHandle(event[0]);
158  CloseHandle(event[1]);
159 
160  /* semaphores */
161  semaphore[0] = CreateSemaphoreW( NULL, 0, 1, NULL );
162  semaphore[1] = CreateSemaphoreW( NULL, 1, 1, NULL );
163  ok( semaphore[0] && semaphore[1], "failed to create semaphore\n");
164 
165  r = SignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
166  ok( r == WAIT_OBJECT_0, "should succeed\n");
167 
168  r = SignalObjectAndWait(semaphore[0], semaphore[1], 0, FALSE);
169  ok( r == WAIT_FAILED, "should fail\n");
170 
171  r = ReleaseSemaphore(semaphore[0],1,NULL);
172  ok( r == FALSE, "should fail\n");
173 
174  r = ReleaseSemaphore(semaphore[1],1,NULL);
175  ok( r == TRUE, "should succeed\n");
176 
177  CloseHandle(semaphore[0]);
178  CloseHandle(semaphore[1]);
179 
180  /* try a registry key */
183  r = SignalObjectAndWait(file, file, 0, FALSE);
184  ok( r == WAIT_FAILED, "should fail\n");
185  ok( ERROR_INVALID_HANDLE == GetLastError(), "should return invalid handle error\n");
186  CloseHandle(file);
187 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD DWORD
Definition: winlogon.h:75
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define FALSE
Definition: types.h:117
#define GENERIC_WRITE
Definition: nt_native.h:90
DWORD WINAPI SignalObjectAndWait(IN HANDLE hObjectToSignal, IN HANDLE hObjectToWaitOn, IN DWORD dwMilliseconds, IN BOOL bAlertable)
Definition: synch.c:269
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
HANDLE semaphore
Definition: loader.c:2140
#define WAIT_OBJECT_0
Definition: winbase.h:387
const char file[]
Definition: icontest.c:11
#define FILE_FLAG_DELETE_ON_CLOSE
Definition: disk.h:42
#define WAIT_FAILED
Definition: winbase.h:394
#define WAIT_TIMEOUT
Definition: dderror.h:14
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
#define GENERIC_READ
Definition: compat.h:124
struct _cl_event * event
Definition: glext.h:7739
#define CREATE_ALWAYS
Definition: disk.h:72
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:660
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:488
#define CreateFileA(a, b, c, d, e, f, g)
Definition: compat.h:399
static void test_slist ( void  )
static

Definition at line 301 of file sync.c.

Referenced by main(), and START_TEST().

302 {
303  struct item
304  {
306  int value;
307  } item1, item2, item3, *item;
308  SLIST_HEADER slist_header;
310  USHORT size;
311  int i;
312 
313  item1.value = 1;
314  item2.value = 2;
315  item3.value = 3;
316 
317  memset(&slist_header, 0xff, sizeof(slist_header));
318  InitializeSListHead(&slist_header);
319  size = QueryDepthSList(&slist_header);
320  ok(size == 0, "Expected size == 0, got %u\n", size);
321 
322  /* test PushEntry, PopEntry and Flush */
323  entry = InterlockedPushEntrySList(&slist_header, &item1.entry);
324  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
325  size = QueryDepthSList(&slist_header);
326  ok(size == 1, "Expected size == 1, got %u\n", size);
327 
328  entry = InterlockedPushEntrySList(&slist_header, &item2.entry);
329  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
330  item = CONTAINING_RECORD(entry, struct item, entry);
331  ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
332  size = QueryDepthSList(&slist_header);
333  ok(size == 2, "Expected size == 2, got %u\n", size);
334 
335  entry = InterlockedPushEntrySList(&slist_header, &item3.entry);
336  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
337  item = CONTAINING_RECORD(entry, struct item, entry);
338  ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
339  size = QueryDepthSList(&slist_header);
340  ok(size == 3, "Expected size == 3, got %u\n", size);
341 
342  entry = InterlockedPopEntrySList(&slist_header);
343  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
344  item = CONTAINING_RECORD(entry, struct item, entry);
345  ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
346  size = QueryDepthSList(&slist_header);
347  ok(size == 2, "Expected size == 2, got %u\n", size);
348 
349  entry = InterlockedFlushSList(&slist_header);
350  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
351  item = CONTAINING_RECORD(entry, struct item, entry);
352  ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
353  item = CONTAINING_RECORD(item->entry.Next, struct item, entry);
354  ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
355  size = QueryDepthSList(&slist_header);
356  ok(size == 0, "Expected size == 0, got %u\n", size);
357  entry = InterlockedPopEntrySList(&slist_header);
358  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
359 
360  /* test RtlInterlockedPushListSList */
361  entry = InterlockedPushEntrySList(&slist_header, &item3.entry);
362  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
363  entry = call_func4(pRtlInterlockedPushListSList, &slist_header, &item2.entry, &item1.entry, 42);
364  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
365  item = CONTAINING_RECORD(entry, struct item, entry);
366  ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
367  size = QueryDepthSList(&slist_header);
368  ok(size == 43, "Expected size == 43, got %u\n", size);
369 
370  entry = InterlockedPopEntrySList(&slist_header);
371  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
372  item = CONTAINING_RECORD(entry, struct item, entry);
373  ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
374  size = QueryDepthSList(&slist_header);
375  ok(size == 42, "Expected size == 42, got %u\n", size);
376 
377  entry = InterlockedPopEntrySList(&slist_header);
378  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
379  item = CONTAINING_RECORD(entry, struct item, entry);
380  ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
381  size = QueryDepthSList(&slist_header);
382  ok(size == 41, "Expected size == 41, got %u\n", size);
383 
384  entry = InterlockedPopEntrySList(&slist_header);
385  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
386  item = CONTAINING_RECORD(entry, struct item, entry);
387  ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
388  size = QueryDepthSList(&slist_header);
389  ok(size == 40, "Expected size == 40, got %u\n", size);
390 
391  entry = InterlockedPopEntrySList(&slist_header);
392  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
393  size = QueryDepthSList(&slist_header);
394  ok(size == 40, "Expected size == 40, got %u\n", size);
395 
396  entry = InterlockedFlushSList(&slist_header);
397  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
398  size = QueryDepthSList(&slist_header);
399  ok(size == 40 || broken(size == 0) /* >= Win 8 */, "Expected size == 40, got %u\n", size);
400 
401  entry = InterlockedPushEntrySList(&slist_header, &item1.entry);
402  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
403  entry = InterlockedFlushSList(&slist_header);
404  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
405  item = CONTAINING_RECORD(entry, struct item, entry);
406  ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
407  size = QueryDepthSList(&slist_header);
408  ok(size == 0, "Expected size == 0, got %u\n", size);
409 
410  /* test RtlInterlockedPushListSListEx */
411  if (pRtlInterlockedPushListSListEx)
412  {
413  entry = InterlockedPushEntrySList(&slist_header, &item3.entry);
414  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
415  entry = pRtlInterlockedPushListSListEx(&slist_header, &item2.entry, &item1.entry, 42);
416  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
417  item = CONTAINING_RECORD(entry, struct item, entry);
418  ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
419  size = QueryDepthSList(&slist_header);
420  ok(size == 43, "Expected size == 43, got %u\n", size);
421 
422  entry = InterlockedFlushSList(&slist_header);
423  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
424  item = CONTAINING_RECORD(entry, struct item, entry);
425  ok(item->value == 2, "Expected item->value == 2, got %u\n", item->value);
426  item = CONTAINING_RECORD(item->entry.Next, struct item, entry);
427  ok(item->value == 1, "Expected item->value == 1, got %u\n", item->value);
428  item = CONTAINING_RECORD(item->entry.Next, struct item, entry);
429  ok(item->value == 3, "Expected item->value == 3, got %u\n", item->value);
430  size = QueryDepthSList(&slist_header);
431  ok(size == 0, "Expected size == 0, got %u\n", size);
432  }
433  else
434  win_skip("RtlInterlockedPushListSListEx not available, skipping tests\n");
435 
436  /* test with a lot of items */
437  for (i = 0; i < 65536; i++)
438  {
439  item = HeapAlloc(GetProcessHeap(), 0, sizeof(*item));
440  item->value = i + 1;
441  entry = InterlockedPushEntrySList(&slist_header, &item->entry);
442  if (i)
443  {
444  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
445  item = CONTAINING_RECORD(entry, struct item, entry);
446  ok(item->value == i, "Expected item->value == %u, got %u\n", i, item->value);
447  }
448  else
449  {
450  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
451  }
452  size = QueryDepthSList(&slist_header);
453  ok(size == ((i + 1) & 0xffff), "Expected size == %u, got %u\n", (i + 1) & 0xffff, size);
454  }
455 
456  entry = InterlockedFlushSList(&slist_header);
457  for (i = 65536; i > 0; i--)
458  {
459  ok(entry != NULL, "Expected entry != NULL, got %p\n", entry);
460  item = CONTAINING_RECORD(entry, struct item, entry);
461  ok(item->value == i, "Expected item->value == %u, got %u\n", i, item->value);
462  entry = item->entry.Next;
463  HeapFree(GetProcessHeap(), 0, item);
464  }
465  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
466  size = QueryDepthSList(&slist_header);
467  ok(size == 0, "Expected size == 0, got %u\n", size);
468  entry = InterlockedPopEntrySList(&slist_header);
469  ok(entry == NULL, "Expected entry == NULL, got %p\n", entry);
470 }
uint8_t entry
Definition: isohybrid.c:63
#define QueryDepthSList(SListHead)
Definition: rtlfuncs.h:3402
PSLIST_ENTRY WINAPI InterlockedPopEntrySList(PSLIST_HEADER ListHead)
Definition: interlocked.c:55
static const struct metadata_item item3[]
Definition: metadata.c:2807
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define ok(value,...)
Definition: CComObject.cpp:34
#define call_func4(func, a, b, c, d)
Definition: sync.c:107
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static const struct metadata_item item2[]
Definition: metadata.c:2800
#define InterlockedFlushSList(SListHead)
Definition: rtlfuncs.h:3397
NTKERNELAPI PSLIST_ENTRY FASTCALL InterlockedPushEntrySList(IN PSLIST_HEADER ListHead, IN PSLIST_ENTRY ListEntry)
Definition: interlocked.c:82
GLsizei const GLfloat * value
Definition: glext.h:6069
#define broken(x)
Definition: _sntprintf.h:21
static ATOM item
Definition: dde.c:856
unsigned short USHORT
Definition: pedump.c:61
#define SLIST_ENTRY(type)
Definition: queue.h:102
static const struct metadata_item item1[]
Definition: metadata.c:2795
#define memset(x, y, z)
Definition: compat.h:39
#define win_skip
Definition: test.h:141
#define HeapFree(x, y, z)
Definition: compat.h:394
WINBASEAPI VOID WINAPI InitializeSListHead(_Out_ PSLIST_HEADER ListHead)
Definition: rtlfuncs.h:3353
static void test_srwlock_base ( void  )
static

Definition at line 2324 of file sync.c.

Referenced by START_TEST().

2325 {
2326  HANDLE h1, h2, h3;
2327  DWORD dummy;
2328 
2329  if (!pInitializeSRWLock)
2330  {
2331  /* function is not yet in XP, only in newer Windows */
2332  win_skip("no srw lock support.\n");
2333  return;
2334  }
2335 
2336  pInitializeSRWLock(&srwlock_base);
2338 
2339  h1 = CreateThread(NULL, 0, srwlock_base_thread1, NULL, 0, &dummy);
2340  h2 = CreateThread(NULL, 0, srwlock_base_thread2, NULL, 0, &dummy);
2341  h3 = CreateThread(NULL, 0, srwlock_base_thread3, NULL, 0, &dummy);
2342 
2343  srwlock_seq = 1; /* go */
2344  while (srwlock_seq < 31)
2345  Sleep(5);
2346 
2347  WaitForSingleObject(h1, 100);
2348  WaitForSingleObject(h2, 100);
2349  WaitForSingleObject(h3, 100);
2350 
2351  ok(!srwlock_base_errors.wrong_execution_order,
2352  "thread commands were executed in the wrong order (occurred %d times).\n",
2353  srwlock_base_errors.wrong_execution_order);
2354 
2355  ok(!srwlock_base_errors.samethread_excl_excl,
2356  "AcquireSRWLockExclusive didn't block when called multiple times from the same thread (occurred %d times).\n",
2357  srwlock_base_errors.samethread_excl_excl);
2358 
2359  ok(!srwlock_base_errors.samethread_excl_shared,
2360  "AcquireSRWLockShared didn't block when the same thread holds an exclusive lock (occurred %d times).\n",
2361  srwlock_base_errors.samethread_excl_shared);
2362 
2363  ok(!srwlock_base_errors.samethread_shared_excl,
2364  "AcquireSRWLockExclusive didn't block when the same thread holds a shared lock (occurred %d times).\n",
2365  srwlock_base_errors.samethread_shared_excl);
2366 
2367  ok(!srwlock_base_errors.multithread_excl_excl,
2368  "AcquireSRWLockExclusive didn't block when a second thread holds the exclusive lock (occurred %d times).\n",
2369  srwlock_base_errors.multithread_excl_excl);
2370 
2371  ok(!srwlock_base_errors.excl_not_preferred,
2372  "thread waiting for exclusive access to the SHMLock was not preferred (occurred %d times).\n",
2373  srwlock_base_errors.excl_not_preferred);
2374 
2375  ok(!srwlock_base_errors.trylock_excl,
2376  "TryAcquireSRWLockExclusive didn't behave as expected (occurred %d times).\n",
2377  srwlock_base_errors.trylock_excl);
2378 
2379  ok(!srwlock_base_errors.trylock_shared,
2380  "TryAcquireSRWLockShared didn't behave as expected (occurred %d times).\n",
2381  srwlock_base_errors.trylock_shared);
2382 
2383 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_seq
Definition: sync.c:1941
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static SRWLOCK srwlock_base
Definition: sync.c:1942
static DWORD WINAPI srwlock_base_thread2(LPVOID x)
Definition: sync.c:2153
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:416
static struct @1539 srwlock_base_errors
#define ok(value,...)
Definition: CComObject.cpp:34
static DWORD WINAPI srwlock_base_thread1(LPVOID x)
Definition: sync.c:2026
DWORD *typedef HANDLE
Definition: winlogon.h:52
unsigned char dummy
Definition: maze.c:118
#define memset(x, y, z)
Definition: compat.h:39
static DWORD WINAPI srwlock_base_thread3(LPVOID x)
Definition: sync.c:2296
#define win_skip
Definition: test.h:141
static void test_srwlock_example ( void  )
static

Definition at line 2429 of file sync.c.

Referenced by START_TEST().

2430 {
2431  HANDLE h1, h2, h3;
2432  DWORD dummy;
2433  DWORD cnt1, cnt2, cnt3;
2434 
2435  if (!pInitializeSRWLock) {
2436  /* function is not yet in XP, only in newer Windows */
2437  win_skip("no srw lock support.\n");
2438  return;
2439  }
2440 
2441  pInitializeSRWLock(&srwlock_example);
2442 
2443  cnt1 = cnt2 = cnt3 = 0;
2444 
2445  h1 = CreateThread(NULL, 0, srwlock_example_thread, &cnt1, 0, &dummy);
2446  h2 = CreateThread(NULL, 0, srwlock_example_thread, &cnt2, 0, &dummy);
2447  h3 = CreateThread(NULL, 0, srwlock_example_thread, &cnt3, 0, &dummy);
2448 
2449  /* limit run to 1 second. */
2450  Sleep(1000);
2451 
2452  /* tear down start */
2453  srwlock_stop = TRUE;
2454 
2455  WaitForSingleObject(h1, 1000);
2456  WaitForSingleObject(h2, 1000);
2457  WaitForSingleObject(h3, 1000);
2458 
2459  ok(!srwlock_inside, "threads didn't terminate properly, srwlock_inside is %d.\n", srwlock_inside);
2460  ok(!srwlock_example_errors, "errors occurred while running SRWLock example test (number of errors: %d)\n",
2462 
2463  trace("number of shared accesses per thread are c1 %d, c2 %d, c3 %d\n", cnt1, cnt2, cnt3);
2464  trace("number of total exclusive accesses is %d\n", srwlock_protected_value);
2465 }
#define trace(...)
Definition: kmt_test.h:217
#define TRUE
Definition: types.h:120
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
static LONG srwlock_example_errors
Definition: sync.c:2387
static BOOL srwlock_stop
Definition: sync.c:2388
static LONG srwlock_inside
Definition: sync.c:2387
DWORD DWORD
Definition: winlogon.h:75
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static LONG srwlock_protected_value
Definition: sync.c:2386
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:135
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
DWORD *typedef HANDLE
Definition: winlogon.h:52
unsigned char dummy
Definition: maze.c:118
static SRWLOCK srwlock_example
Definition: sync.c:2385
static DWORD WINAPI srwlock_example_thread(LPVOID x)
Definition: sync.c:2390
#define win_skip
Definition: test.h:141
static void test_timer_queue ( void  )
static

Definition at line 880 of file sync.c.

Referenced by START_TEST().

881 {
882  HANDLE q, t0, t1, t2, t3, t4, t5;
883  int n0, n1, n2, n3, n4, n5;
884  struct timer_queue_data1 d1, d2, d3, d4;
885  HANDLE e, et1, et2;
886  BOOL ret, ret0;
887 
888  /* Test asynchronous deletion of the queue. */
889  q = CreateTimerQueue();
890  ok(q != NULL, "CreateTimerQueue\n");
891 
892  SetLastError(0xdeadbeef);
893  ret = DeleteTimerQueueEx(q, NULL);
894  ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
895  "DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
896  GetLastError());
897 
898  /* Test synchronous deletion of the queue and running timers. */
899  q = CreateTimerQueue();
900  ok(q != NULL, "CreateTimerQueue\n");
901 
902  /* Not called. */
903  t0 = NULL;
904  n0 = 0;
905  ret = CreateTimerQueueTimer(&t0, q, timer_queue_cb1, &n0, 0, 300, 0);
906  ok(ret, "CreateTimerQueueTimer\n");
907  ok(t0 != NULL, "CreateTimerQueueTimer\n");
908  ret0 = DeleteTimerQueueTimer(q, t0, NULL);
909  ok((!ret0 && GetLastError() == ERROR_IO_PENDING) ||
910  broken(ret0), /* Win 2000 & XP & 2003 */
911  "DeleteTimerQueueTimer ret=%d le=%u\n", ret0, GetLastError());
912 
913  /* Called once. */
914  t1 = NULL;
915  n1 = 0;
916  ret = CreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 0, 0, 0);
917  ok(ret, "CreateTimerQueueTimer\n");
918  ok(t1 != NULL, "CreateTimerQueueTimer\n");
919 
920  /* A slow one. */
921  t2 = NULL;
922  n2 = 0;
923  ret = CreateTimerQueueTimer(&t2, q, timer_queue_cb1, &n2, 0, 100, 0);
924  ok(ret, "CreateTimerQueueTimer\n");
925  ok(t2 != NULL, "CreateTimerQueueTimer\n");
926 
927  /* A fast one. */
928  t3 = NULL;
929  n3 = 0;
930  ret = CreateTimerQueueTimer(&t3, q, timer_queue_cb1, &n3, 0, 10, 0);
931  ok(ret, "CreateTimerQueueTimer\n");
932  ok(t3 != NULL, "CreateTimerQueueTimer\n");
933 
934  /* Start really late (it won't start). */
935  t4 = NULL;
936  n4 = 0;
937  ret = CreateTimerQueueTimer(&t4, q, timer_queue_cb1, &n4, 10000, 10, 0);
938  ok(ret, "CreateTimerQueueTimer\n");
939  ok(t4 != NULL, "CreateTimerQueueTimer\n");
940 
941  /* Start soon, but delay so long it won't run again. */
942  t5 = NULL;
943  n5 = 0;
944  ret = CreateTimerQueueTimer(&t5, q, timer_queue_cb1, &n5, 0, 10000, 0);
945  ok(ret, "CreateTimerQueueTimer\n");
946  ok(t5 != NULL, "CreateTimerQueueTimer\n");
947 
948  /* Give them a chance to do some work. */
949  Sleep(500);
950 
951  /* Test deleting a once-only timer. */
953  ok(ret, "DeleteTimerQueueTimer\n");
954 
955  /* A periodic timer. */
957  ok(ret, "DeleteTimerQueueTimer\n");
958 
960  ok(ret, "DeleteTimerQueueEx\n");
961  todo_wine
962  ok(n0 == 1 || broken(ret0 && n0 == 0), "Timer callback 0 expected 1 got %d\n", n0);
963  ok(n1 == 1, "Timer callback 1 expected 1 got %d\n", n1);
964  ok(n2 < n3, "Timer callback 2 & 3 expected %d < %d\n", n2, n3);
965  ok(n4 == 0, "Timer callback 4 expected 0 got %d\n", n4);
966  ok(n5 == 1, "Timer callback 5 expected 1 got %d\n", n5);
967 
968  /* Test synchronous deletion of the timer/queue with event trigger. */
969  e = CreateEventW(NULL, TRUE, FALSE, NULL);
970  et1 = CreateEventW(NULL, TRUE, FALSE, NULL);
971  et2 = CreateEventW(NULL, TRUE, FALSE, NULL);
972  if (!e || !et1 || !et2)
973  {
974  skip("Failed to create timer queue descruction event\n");
975  return;
976  }
977 
978  q = CreateTimerQueue();
979  ok(q != NULL, "CreateTimerQueue\n");
980 
981  /* Run once and finish quickly (should be done when we delete it). */
982  t1 = NULL;
983  ret = CreateTimerQueueTimer(&t1, q, timer_queue_cb5, NULL, 0, 0, 0);
984  ok(ret, "CreateTimerQueueTimer\n");
985  ok(t1 != NULL, "CreateTimerQueueTimer\n");
986 
987  /* Run once and finish slowly (shouldn't be done when we delete it). */
988  t2 = NULL;
989  ret = CreateTimerQueueTimer(&t2, q, timer_queue_cb5, (PVOID) 1000, 0, 0, 0);
990  ok(ret, "CreateTimerQueueTimer\n");
991  ok(t2 != NULL, "CreateTimerQueueTimer\n");
992 
993  /* Run once and finish quickly (should be done when we delete it). */
994  t3 = NULL;
995  ret = CreateTimerQueueTimer(&t3, q, timer_queue_cb5, NULL, 0, 0, 0);
996  ok(ret, "CreateTimerQueueTimer\n");
997  ok(t3 != NULL, "CreateTimerQueueTimer\n");
998 
999  /* Run once and finish slowly (shouldn't be done when we delete it). */
1000  t4 = NULL;
1001  ret = CreateTimerQueueTimer(&t4, q, timer_queue_cb5, (PVOID) 1000, 0, 0, 0);
1002  ok(ret, "CreateTimerQueueTimer\n");
1003  ok(t4 != NULL, "CreateTimerQueueTimer\n");
1004 
1005  /* Give them a chance to start. */
1006  Sleep(400);
1007 
1008  /* DeleteTimerQueueTimer always returns PENDING with a NULL event,
1009  even if the timer is finished. */
1010  SetLastError(0xdeadbeef);
1011  ret = DeleteTimerQueueTimer(q, t1, NULL);
1012  ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
1013  "DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1014  GetLastError());
1015 
1016  SetLastError(0xdeadbeef);
1017  ret = DeleteTimerQueueTimer(q, t2, NULL);
1018  ok(!ret, "DeleteTimerQueueTimer call was expected to fail\n");
1020  "DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1021  GetLastError());
1022 
1023  SetLastError(0xdeadbeef);
1024  ret = DeleteTimerQueueTimer(q, t3, et1);
1025  ok(ret, "DeleteTimerQueueTimer call was expected to fail\n");
1026  ok(GetLastError() == 0xdeadbeef,
1027  "DeleteTimerQueueTimer, GetLastError: expected 0xdeadbeef, got %d\n",
1028  GetLastError());
1029  ok(WaitForSingleObject(et1, 250) == WAIT_OBJECT_0,
1030  "Timer destruction event not triggered\n");
1031 
1032  SetLastError(0xdeadbeef);
1033  ret = DeleteTimerQueueTimer(q, t4, et2);
1034  ok(!ret, "DeleteTimerQueueTimer call was expected to fail\n");
1036  "DeleteTimerQueueTimer, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1037  GetLastError());
1038  ok(WaitForSingleObject(et2, 1000) == WAIT_OBJECT_0,
1039  "Timer destruction event not triggered\n");
1040 
1041  SetLastError(0xdeadbeef);
1042  ret = DeleteTimerQueueEx(q, e);
1043  ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
1044  "DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1045  GetLastError());
1047  "Queue destruction event not triggered\n");
1048  CloseHandle(e);
1049 
1050  /* Test deleting/changing a timer in execution. */
1051  q = CreateTimerQueue();
1052  ok(q != NULL, "CreateTimerQueue\n");
1053 
1054  /* Test changing a once-only timer before it fires (this is allowed,
1055  whereas after it fires you cannot). */
1056  n1 = 0;
1057  ret = CreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 10000, 0, 0);
1058  ok(ret, "CreateTimerQueueTimer\n");
1059  ok(t1 != NULL, "CreateTimerQueueTimer\n");
1060  ret = ChangeTimerQueueTimer(q, t1, 0, 0);
1061  ok(ret, "ChangeTimerQueueTimer\n");
1062 
1063  d2.t = t2 = NULL;
1064  d2.num_calls = 0;
1065  d2.max_calls = 3;
1066  d2.q = q;
1067  ret = CreateTimerQueueTimer(&t2, q, timer_queue_cb2, &d2, 10, 10, 0);
1068  d2.t = t2;
1069  ok(ret, "CreateTimerQueueTimer\n");
1070  ok(t2 != NULL, "CreateTimerQueueTimer\n");
1071 
1072  d3.t = t3 = NULL;
1073  d3.num_calls = 0;
1074  d3.max_calls = 4;
1075  d3.q = q;
1076  ret = CreateTimerQueueTimer(&t3, q, timer_queue_cb3, &d3, 10, 10, 0);
1077  d3.t = t3;
1078  ok(ret, "CreateTimerQueueTimer\n");
1079  ok(t3 != NULL, "CreateTimerQueueTimer\n");
1080 
1081  d4.t = t4 = NULL;
1082  d4.num_calls = 0;
1083  d4.q = q;
1084  ret = CreateTimerQueueTimer(&t4, q, timer_queue_cb4, &d4, 10, 0, 0);
1085  d4.t = t4;
1086  ok(ret, "CreateTimerQueueTimer\n");
1087  ok(t4 != NULL, "CreateTimerQueueTimer\n");
1088 
1089  Sleep(500);
1090 
1092  ok(ret, "DeleteTimerQueueEx\n");
1093  ok(n1 == 1, "ChangeTimerQueueTimer\n");
1094  ok(d2.num_calls == d2.max_calls, "DeleteTimerQueueTimer\n");
1095  ok(d3.num_calls == d3.max_calls, "ChangeTimerQueueTimer\n");
1096  ok(d4.num_calls == 1, "Timer flagged for deletion incorrectly\n");
1097 
1098  /* Test an obscure bug that was in the original implementation. */
1099  q = CreateTimerQueue();
1100  ok(q != NULL, "CreateTimerQueue\n");
1101 
1102  /* All the work is done in the callback. */
1103  d1.t = t1 = NULL;
1104  d1.num_calls = 0;
1105  d1.q = q;
1106  ret = CreateTimerQueueTimer(&t1, q, timer_queue_cb6, &d1, 100, 100, WT_EXECUTELONGFUNCTION);
1107  d1.t = t1;
1108  ok(ret, "CreateTimerQueueTimer\n");
1109  ok(t1 != NULL, "CreateTimerQueueTimer\n");
1110 
1111  Sleep(750);
1112 
1113  SetLastError(0xdeadbeef);
1114  ret = DeleteTimerQueueEx(q, NULL);
1115  ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
1116  "DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1117  GetLastError());
1118  ok(d1.num_calls == 1, "DeleteTimerQueueTimer\n");
1119 
1120  /* Test functions on the default timer queue. */
1121  t1 = NULL;
1122  n1 = 0;
1123  ret = CreateTimerQueueTimer(&t1, NULL, timer_queue_cb1, &n1, 1000, 1000, 0);
1124  ok(ret, "CreateTimerQueueTimer, default queue\n");
1125  ok(t1 != NULL, "CreateTimerQueueTimer, default queue\n");
1126 
1127  ret = ChangeTimerQueueTimer(NULL, t1, 2000, 2000);
1128  ok(ret, "ChangeTimerQueueTimer, default queue\n");
1129 
1131  ok(ret, "DeleteTimerQueueTimer, default queue\n");
1132 
1133  /* Try mixing default and non-default queues. Apparently this works. */
1134  q = CreateTimerQueue();
1135  ok(q != NULL, "CreateTimerQueue\n");
1136 
1137  t1 = NULL;
1138  n1 = 0;
1139  ret = CreateTimerQueueTimer(&t1, q, timer_queue_cb1, &n1, 1000, 1000, 0);
1140  ok(ret, "CreateTimerQueueTimer\n");
1141  ok(t1 != NULL, "CreateTimerQueueTimer\n");
1142 
1143  t2 = NULL;
1144  n2 = 0;
1145  ret = CreateTimerQueueTimer(&t2, NULL, timer_queue_cb1, &n2, 1000, 1000, 0);
1146  ok(ret, "CreateTimerQueueTimer\n");
1147  ok(t2 != NULL, "CreateTimerQueueTimer\n");
1148 
1149  ret = ChangeTimerQueueTimer(NULL, t1, 2000, 2000);
1150  ok(ret, "ChangeTimerQueueTimer\n");
1151 
1152  ret = ChangeTimerQueueTimer(q, t2, 2000, 2000);
1153  ok(ret, "ChangeTimerQueueTimer\n");
1154 
1156  ok(ret, "DeleteTimerQueueTimer\n");
1157 
1159  ok(ret, "DeleteTimerQueueTimer\n");
1160 
1161  /* Try to delete the default queue? In any case: not allowed. */
1162  SetLastError(0xdeadbeef);
1163  ret = DeleteTimerQueueEx(NULL, NULL);
1164  ok(!ret, "DeleteTimerQueueEx call was expected to fail\n");
1166  "DeleteTimerQueueEx, GetLastError: expected ERROR_INVALID_HANDLE, got %d\n",
1167  GetLastError());
1168 
1169  SetLastError(0xdeadbeef);
1170  ret = DeleteTimerQueueEx(q, NULL);
1171  ok(ret /* vista */ || GetLastError() == ERROR_IO_PENDING,
1172  "DeleteTimerQueueEx, GetLastError: expected ERROR_IO_PENDING, got %d\n",
1173  GetLastError());
1174 }
DWORD *typedef PVOID
Definition: winlogon.h:52
static void CALLBACK timer_queue_cb3(PVOID p, BOOLEAN timedOut)
Definition: sync.c:808
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
static void CALLBACK timer_queue_cb1(PVOID p, BOOLEAN timedOut)
Definition: sync.c:778
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define ERROR_IO_PENDING
Definition: dderror.h:15
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
#define e
Definition: ke_i.h:82
static void CALLBACK timer_queue_cb4(PVOID p, BOOLEAN timedOut)
Definition: sync.c:821
HANDLE WINAPI CreateTimerQueue(VOID)
Definition: timerqueue.c:117
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
#define WT_EXECUTELONGFUNCTION
Definition: winnt_old.h:1076
unsigned int BOOL
Definition: ntddk_ex.h:94
#define WAIT_OBJECT_0
Definition: winbase.h:387
int n3
Definition: dwarfget.c:148
BOOL WINAPI ChangeTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
Definition: timerqueue.c:82
#define SetLastError(x)
Definition: compat.h:409
int n1
Definition: dwarfget.c:148
GLdouble GLdouble GLdouble GLdouble q
Definition: gl.h:2063
int ret
#define todo_wine
Definition: test.h:154
#define broken(x)
Definition: _sntprintf.h:21
DWORD *typedef HANDLE
Definition: winlogon.h:52
int n2
Definition: dwarfget.c:148
#define skip(...)
Definition: CString.cpp:57
BOOL WINAPI DeleteTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
Definition: timerqueue.c:240
int n4
Definition: dwarfget.c:148
int n5
Definition: dwarfget.c:148
static void CALLBACK timer_queue_cb5(PVOID p, BOOLEAN timedOut)
Definition: sync.c:838
static void CALLBACK timer_queue_cb6(PVOID p, BOOLEAN timedOut)
Definition: sync.c:846
BOOL WINAPI DeleteTimerQueueEx(IN HANDLE TimerQueue, IN HANDLE CompletionEvent)
Definition: timerqueue.c:205
BOOL WINAPI CreateTimerQueueTimer(OUT PHANDLE phNewTimer, IN HANDLE TimerQueue, IN WAITORTIMERCALLBACK Callback, IN PVOID Parameter, IN DWORD DueTime, IN DWORD Period, IN ULONG Flags)
Definition: timerqueue.c:138
static void CALLBACK timer_queue_cb2(PVOID p, BOOLEAN timedOut)
Definition: sync.c:792
static void test_waitable_timer ( void  )
static

Definition at line 631 of file sync.c.

Referenced by START_TEST().

632 {
633  HANDLE handle, handle2;
634 
635  /* test case sensitivity */
636 
637  SetLastError(0xdeadbeef);
638  handle = CreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer");
639  ok(handle != NULL, "CreateWaitableTimer failed with error %u\n", GetLastError());
640  ok(GetLastError() == 0, "wrong error %u\n", GetLastError());
641 
642  SetLastError(0xdeadbeef);
643  handle2 = CreateWaitableTimerA(NULL, FALSE, __FILE__ ": Test WaitableTimer");
644  ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError());
645  ok( GetLastError() == ERROR_ALREADY_EXISTS, "wrong error %u\n", GetLastError());
646  CloseHandle( handle2 );
647 
648  SetLastError(0xdeadbeef);
649  handle2 = CreateWaitableTimerA(NULL, FALSE, __FILE__ ": TEST WAITABLETIMER");
650  ok( handle2 != NULL, "CreateWaitableTimer failed with error %d\n", GetLastError());
651  ok( GetLastError() == 0, "wrong error %u\n", GetLastError());
652  CloseHandle( handle2 );
653 
654  SetLastError(0xdeadbeef);
655  handle2 = OpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": Test WaitableTimer");
656  ok( handle2 != NULL, "OpenWaitableTimer failed with error %d\n", GetLastError());
657  CloseHandle( handle2 );
658 
659  SetLastError(0xdeadbeef);
660  handle2 = OpenWaitableTimerA( TIMER_ALL_ACCESS, FALSE, __FILE__ ": TEST WAITABLETIMER");
661  ok( !handle2, "OpenWaitableTimer succeeded\n");
662  ok( GetLastError() == ERROR_FILE_NOT_FOUND, "wrong error %u\n", GetLastError());
663 
664  SetLastError(0xdeadbeef);
666  ok( !handle2, "OpenWaitableTimer failed with error %d\n", GetLastError());
667  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
668 
669  SetLastError(0xdeadbeef);
671  ok( !handle2, "OpenWaitableTimer failed with error %d\n", GetLastError());
672  ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError());
673 
674  CloseHandle( handle );
675 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define CloseHandle
Definition: compat.h:398
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
HANDLE WINAPI OpenWaitableTimerW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpTimerName)
Definition: synch.c:358
HANDLE WINAPI OpenWaitableTimerA(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCSTR lpTimerName)
Definition: synch.c:370
#define FALSE
Definition: types.h:117
smooth NULL
Definition: ftsmooth.c:416
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define ok(value,...)
Definition: CComObject.cpp:34
HANDLE WINAPI CreateWaitableTimerA(IN LPSECURITY_ATTRIBUTES lpTimerAttributes OPTIONAL, IN BOOL bManualReset, IN LPCSTR lpTimerName OPTIONAL)
Definition: synch.c:346
#define TIMER_ALL_ACCESS
Definition: extypes.h:116
#define SetLastError(x)
Definition: compat.h:409
DWORD *typedef HANDLE
Definition: winlogon.h:52
#define ERROR_ALREADY_EXISTS
Definition: disk.h:80
static void test_WaitForMultipleObjects ( void  )
static

Definition at line 1276 of file sync.c.

Referenced by START_TEST().

1277 {
1279  NTSTATUS status;
1280  DWORD r;
1281  int i;
1282  HANDLE maxevents[MAXIMUM_WAIT_OBJECTS];
1283 
1284  /* create the maximum number of events and make sure
1285  * we can wait on that many */
1286  for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
1287  {
1288  maxevents[i] = CreateEventW(NULL, i==0, TRUE, NULL);
1289  ok( maxevents[i] != 0, "should create enough events\n");
1290  }
1291 
1292  /* a manual-reset event remains signaled, an auto-reset event is cleared */
1293  r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0);
1294  ok( r == WAIT_OBJECT_0, "should signal lowest handle first, got %d\n", r);
1295  r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0);
1296  ok( r == WAIT_OBJECT_0, "should signal handle #0 first, got %d\n", r);
1297  ok(ResetEvent(maxevents[0]), "ResetEvent\n");
1298  for (i=1; i<MAXIMUM_WAIT_OBJECTS; i++)
1299  {
1300  /* the lowest index is checked first and remaining events are untouched */
1301  r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, FALSE, 0);
1302  ok( r == WAIT_OBJECT_0+i, "should signal handle #%d first, got %d\n", i, r);
1303  }
1304 
1305  /* run same test with Nt* call */
1306  for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
1307  SetEvent(maxevents[i]);
1308 
1309  /* a manual-reset event remains signaled, an auto-reset event is cleared */
1310  status = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL);
1311  ok(status == STATUS_WAIT_0, "should signal lowest handle first, got %08x\n", status);
1312  status = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL);
1313  ok(status == STATUS_WAIT_0, "should signal handle #0 first, got %08x\n", status);
1314  ok(ResetEvent(maxevents[0]), "ResetEvent\n");
1315  for (i=1; i<MAXIMUM_WAIT_OBJECTS; i++)
1316  {
1317  /* the lowest index is checked first and remaining events are untouched */
1318  status = pNtWaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, TRUE, FALSE, NULL);
1319  ok(status == STATUS_WAIT_0 + i, "should signal handle #%d first, got %08x\n", i, status);
1320  }
1321 
1322  for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
1323  if (maxevents[i]) CloseHandle(maxevents[i]);
1324 
1325  /* in contrast to WaitForSingleObject, pseudo handles are not allowed in
1326  * WaitForMultipleObjects and NtWaitForMultipleObjects */
1327  maxevents[0] = GetCurrentProcess();
1328  SetLastError(0xdeadbeef);
1329  r = WaitForMultipleObjects(1, maxevents, FALSE, 100);
1330  todo_wine ok(r == WAIT_FAILED, "expected WAIT_FAILED, got %u\n", r);
1332  "expected ERROR_INVALID_HANDLE, got %u\n", GetLastError());
1333 
1334  maxevents[0] = GetCurrentThread();
1335  SetLastError(0xdeadbeef);
1336  r = WaitForMultipleObjects(1, maxevents, FALSE, 100);
1337  todo_wine ok(r == WAIT_FAILED, "expected WAIT_FAILED, got %u\n", r);
1339  "expected ERROR_INVALID_HANDLE, got %u\n", GetLastError());
1340 
1341  timeout.QuadPart = -1000000;
1342  maxevents[0] = GetCurrentProcess();
1343  status = pNtWaitForMultipleObjects(1, maxevents, TRUE, FALSE, &timeout);
1344  todo_wine ok(status == STATUS_INVALID_HANDLE, "expected STATUS_INVALID_HANDLE, got %08x\n", status);
1345 
1346  timeout.QuadPart = -1000000;
1347  maxevents[0] = GetCurrentThread();
1348  status = pNtWaitForMultipleObjects(1, maxevents, TRUE, FALSE, &timeout);
1349  todo_wine ok(status == STATUS_INVALID_HANDLE, "expected STATUS_INVALID_HANDLE, got %08x\n", status);
1350 }
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define MAXIMUM_WAIT_OBJECTS
Definition: winbase.h:385
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
GLbitfield GLuint64 timeout
Definition: glext.h:7164
DWORD DWORD
Definition: winlogon.h:75
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define STATUS_WAIT_0
Definition: ntstatus.h:223
#define FALSE
Definition: types.h:117
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1205
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
#define WAIT_OBJECT_0
Definition: winbase.h:387
LONG NTSTATUS
Definition: precomp.h:26
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1195
#define WAIT_FAILED
Definition: winbase.h:394
#define SetLastError(x)
Definition: compat.h:409
#define todo_wine
Definition: test.h:154
DWORD *typedef HANDLE
Definition: winlogon.h:52
BOOL WINAPI DECLSPEC_HOTPATCH ResetEvent(IN HANDLE hEvent)
Definition: synch.c:660
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:112
static void test_WaitForSingleObject ( void  )
static

Definition at line 1183 of file sync.c.

Referenced by START_TEST().

1184 {
1185  HANDLE signaled, nonsignaled, invalid;
1187  NTSTATUS status;
1188  DWORD ret;
1189 
1190  signaled = CreateEventW(NULL, TRUE, TRUE, NULL);
1191  nonsignaled = CreateEventW(NULL, TRUE, FALSE, NULL);
1192  invalid = (HANDLE) 0xdeadbee0;
1193 
1194  /* invalid handle with different values for lower 2 bits */
1195  SetLastError(0xdeadbeef);
1196  ret = WaitForSingleObject(invalid, 0);
1197  ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret);
1198  ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1199 
1200  SetLastError(0xdeadbeef);
1201  ret = WaitForSingleObject(modify_handle(invalid, 1), 0);
1202  ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret);
1203  ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1204 
1205  SetLastError(0xdeadbeef);
1206  ret = WaitForSingleObject(modify_handle(invalid, 2), 0);
1207  ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret);
1208  ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1209 
1210  SetLastError(0xdeadbeef);
1211  ret = WaitForSingleObject(modify_handle(invalid, 3), 0);
1212  ok(ret == WAIT_FAILED, "expected WAIT_FAILED, got %d\n", ret);
1213  ok(GetLastError() == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
1214 
1215  /* valid handle with different values for lower 2 bits */
1216  SetLastError(0xdeadbeef);
1217  ret = WaitForSingleObject(nonsignaled, 0);
1218  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret);
1219  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1220 
1221  SetLastError(0xdeadbeef);
1222  ret = WaitForSingleObject(modify_handle(nonsignaled, 1), 0);
1223  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret);
1224  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1225 
1226  SetLastError(0xdeadbeef);
1227  ret = WaitForSingleObject(modify_handle(nonsignaled, 2), 0);
1228  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret);
1229  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1230 
1231  SetLastError(0xdeadbeef);
1232  ret = WaitForSingleObject(modify_handle(nonsignaled, 3), 0);
1233  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %d\n", ret);
1234  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1235 
1236  /* valid handle with different values for lower 2 bits */
1237  SetLastError(0xdeadbeef);
1238  ret = WaitForSingleObject(signaled, 0);
1239  ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret);
1240  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1241 
1242  SetLastError(0xdeadbeef);
1243  ret = WaitForSingleObject(modify_handle(signaled, 1), 0);
1244  ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret);
1245  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1246 
1247  SetLastError(0xdeadbeef);
1248  ret = WaitForSingleObject(modify_handle(signaled, 2), 0);
1249  ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret);
1250  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1251 
1252  SetLastError(0xdeadbeef);
1253  ret = WaitForSingleObject(modify_handle(signaled, 3), 0);
1254  ok(ret == WAIT_OBJECT_0, "expected WAIT_OBJECT_0, got %d\n", ret);
1255  ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %d\n", GetLastError());
1256 
1257  /* pseudo handles are allowed in WaitForSingleObject and NtWaitForSingleObject */
1258  ret = WaitForSingleObject(GetCurrentProcess(), 100);
1259  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", ret);
1260 
1261  ret = WaitForSingleObject(GetCurrentThread(), 100);
1262  ok(ret == WAIT_TIMEOUT, "expected WAIT_TIMEOUT, got %u\n", ret);
1263 
1264  timeout.QuadPart = -1000000;
1265  status = pNtWaitForSingleObject(GetCurrentProcess(), FALSE, &timeout);
1266  ok(status == STATUS_TIMEOUT, "expected STATUS_TIMEOUT, got %08x\n", status);
1267 
1268  timeout.QuadPart = -1000000;
1269  status = pNtWaitForSingleObject(GetCurrentThread(), FALSE, &timeout);
1270  ok(status == STATUS_TIMEOUT, "expected STATUS_TIMEOUT, got %08x\n", status);
1271 
1272  CloseHandle(signaled);
1273  CloseHandle(nonsignaled);
1274 }
static const WCHAR invalid[]
Definition: assoc.c:39
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
static HANDLE(WINAPI *pCreateMemoryResourceNotification)(MEMORY_RESOURCE_NOTIFICATION_TYPE)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
GLbitfield GLuint64 timeout
Definition: glext.h:7164
DWORD DWORD
Definition: winlogon.h:75
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
HANDLE WINAPI GetCurrentThread(VOID)
Definition: proc.c:1205
smooth NULL
Definition: ftsmooth.c:416
#define ok(value,...)
Definition: CComObject.cpp:34
#define WAIT_OBJECT_0
Definition: winbase.h:387
LONG NTSTATUS
Definition: precomp.h:26
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1195
#define WAIT_FAILED
Definition: winbase.h:394
#define SetLastError(x)
Definition: compat.h:409
#define WAIT_TIMEOUT
Definition: dderror.h:14
static HANDLE modify_handle(HANDLE handle, DWORD modify)
Definition: sync.c:1176
int ret
DWORD *typedef HANDLE
Definition: winlogon.h:52
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:112
static void CALLBACK timer_queue_cb1 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 778 of file sync.c.

Referenced by test_timer_queue(), and timer_queue_cb6().

779 {
780  int *pn = p;
781  ok(timedOut, "Timer callbacks should always time out\n");
782  ++*pn;
783 }
#define ok(value,...)
Definition: CComObject.cpp:34
GLfloat GLfloat p
Definition: glext.h:8902
static void CALLBACK timer_queue_cb2 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 792 of file sync.c.

Referenced by test_timer_queue().

793 {
794  struct timer_queue_data1 *d = p;
795  ok(timedOut, "Timer callbacks should always time out\n");
796  if (d->t && ++d->num_calls == d->max_calls)
797  {
798  BOOL ret;
799  SetLastError(0xdeadbeef);
800  /* Note, XP SP2 does *not* do any deadlock checking, so passing
801  INVALID_HANDLE_VALUE here will just hang. */
802  ret = DeleteTimerQueueTimer(d->q, d->t, NULL);
803  ok(!ret, "DeleteTimerQueueTimer\n");
804  ok(GetLastError() == ERROR_IO_PENDING, "DeleteTimerQueueTimer\n");
805  }
806 }
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1056
#define ERROR_IO_PENDING
Definition: dderror.h:15
HANDLE q
Definition: sync.c:789
smooth NULL
Definition: ftsmooth.c:416
HANDLE t
Definition: sync.c:789
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define d
Definition: ke_i.h:81
#define SetLastError(x)
Definition: compat.h:409
int ret
BOOL WINAPI DeleteTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN HANDLE CompletionEvent)
Definition: timerqueue.c:240
GLfloat GLfloat p
Definition: glext.h:8902
static void CALLBACK timer_queue_cb3 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 808 of file sync.c.

Referenced by test_timer_queue().

809 {
810  struct timer_queue_data1 *d = p;
811  ok(timedOut, "Timer callbacks should always time out\n");
812  if (d->t && ++d->num_calls == d->max_calls)
813  {
814  /* Basically kill the timer since it won't have time to run
815  again. */
816  BOOL ret = ChangeTimerQueueTimer(d->q, d->t, 10000, 0);
817  ok(ret, "ChangeTimerQueueTimer\n");
818  }
819 }
HANDLE q
Definition: sync.c:789
HANDLE t
Definition: sync.c:789
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define d
Definition: ke_i.h:81
BOOL WINAPI ChangeTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
Definition: timerqueue.c:82
int ret
GLfloat GLfloat p
Definition: glext.h:8902
static void CALLBACK timer_queue_cb4 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 821 of file sync.c.

Referenced by test_timer_queue().

822 {
823  struct timer_queue_data1 *d = p;
824  ok(timedOut, "Timer callbacks should always time out\n");
825  if (d->t)
826  {
827  /* This tests whether a timer gets flagged for deletion before
828  or after the callback runs. If we start this timer with a
829  period of zero (run once), then ChangeTimerQueueTimer will
830  fail if the timer is already flagged. Hence we really run
831  only once. Otherwise we will run multiple times. */
832  BOOL ret = ChangeTimerQueueTimer(d->q, d->t, 50, 50);
833  ok(ret, "ChangeTimerQueueTimer\n");
834  ++d->num_calls;
835  }
836 }
HANDLE q
Definition: sync.c:789
HANDLE t
Definition: sync.c:789
#define ok(value,...)
Definition: CComObject.cpp:34
unsigned int BOOL
Definition: ntddk_ex.h:94
#define d
Definition: ke_i.h:81
BOOL WINAPI ChangeTimerQueueTimer(IN HANDLE TimerQueue, IN HANDLE Timer, IN ULONG DueTime, IN ULONG Period)
Definition: timerqueue.c:82
int ret
GLfloat GLfloat p
Definition: glext.h:8902
static void CALLBACK timer_queue_cb5 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 838 of file sync.c.

Referenced by test_timer_queue().

839 {
841  ok(timedOut, "Timer callbacks should always time out\n");
842  if (delay)
843  Sleep(delay);
844 }
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:736
#define ok(value,...)
Definition: CComObject.cpp:34
void delay(unsigned msec)
Definition: i386rtl.c:32
uint32_t DWORD_PTR
Definition: typedefs.h:63
#define DWORD_PTR
Definition: generated.c:24
GLfloat GLfloat p
Definition: glext.h:8902
static void CALLBACK timer_queue_cb6 ( PVOID  p,
BOOLEAN  timedOut 
)
static

Definition at line 846 of file sync.c.

Referenced by test_timer_queue().

847 {
848  struct timer_queue_data1 *d = p;
849  ok(timedOut, "Timer callbacks should always time out\n");
850  /* This tests an original implementation bug where a deleted timer may get
851  to run, but it is tricky to set up. */
852  if (d->q && d->num_calls++ == 0)
853  {
854  /* First run: delete ourselves, then insert and remove a timer
855  that goes in front of us in the sorted timeout list. Once
856  removed, we will still timeout at the faster timer's due time,
857  but this should be a no-op if we are bug-free. There should
858  not be a second run. We can test the value of num_calls later. */
859  BOOL ret;
860  HANDLE t;
861 
862  /* The delete will pend while we are in this callback. */
863  SetLastError(0xdeadbeef);
864  ret = DeleteTimerQueueTimer(d->q, d->t, NULL);
865  ok(!ret, "DeleteTimerQueueTimer\n");
866  ok(GetLastError() == ERROR_IO_PENDING, "DeleteTimerQueueTimer\n");
867 
868  ret = CreateTimerQueueTimer(&t, d->q, timer_queue_cb1, NULL, 100, 0, 0);
869  ok(ret, "CreateTimerQueueTimer\n");
870  ok(t != NULL, "CreateTimerQueueTimer\n");
871 
873  ok(ret, "DeleteTimerQueueTimer\n");
874 
875  /* Now we stay alive by hanging around in the callback. */</