Пример #1
0
	Semaphore::Semaphore()
	{
#if BX_PLATFORM_XBOXONE || BX_PLATFORM_WINRT
		m_handle = CreateSemaphoreExW(NULL, 0, LONG_MAX, NULL, 0, SEMAPHORE_ALL_ACCESS);
#else
		m_handle = CreateSemaphoreA(NULL, 0, LONG_MAX, NULL);
#endif
		BX_CHECK(NULL != m_handle, "Failed to create Semaphore!");
	}
Пример #2
0
int sem_init(sem_t* sem, int pshared, unsigned int value)
{
	if(!sem)
	{
		return EINVAL;
	}
	UNREFERENCED_PARAMETER(pshared);

	*sem = CreateSemaphoreExW(NULL, value, LONG_MAX, NULL, 0, SEMAPHORE_ALL_ACCESS);
	return 0;
}
Пример #3
0
/*
 * @implemented
 */
HANDLE
WINAPI
CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
                 IN LONG lInitialCount,
                 IN LONG lMaximumCount,
                 IN LPCWSTR lpName  OPTIONAL)
{
    return CreateSemaphoreExW(lpSemaphoreAttributes,
                              lInitialCount,
                              lMaximumCount,
                              lpName,
                              0,
                              SEMAPHORE_ALL_ACCESS);
}
Пример #4
0
/*
 * @implemented
 */
HANDLE
WINAPI
CreateSemaphoreExA(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes  OPTIONAL,
                   IN LONG lInitialCount,
                   IN LONG lMaximumCount,
                   IN LPCSTR lpName  OPTIONAL,
                   IN DWORD dwFlags,
                   IN DWORD dwDesiredAccess)
{
    NTSTATUS Status;
    ANSI_STRING AnsiName;
    PUNICODE_STRING UnicodeCache;
    LPCWSTR UnicodeName = NULL;

    /* Check for a name */
    if (lpName)
    {
        /* Use TEB Cache */
        UnicodeCache = &NtCurrentTeb()->StaticUnicodeString;

        /* Convert to unicode */
        RtlInitAnsiString(&AnsiName, lpName);
        Status = RtlAnsiStringToUnicodeString(UnicodeCache, &AnsiName, FALSE);
        if (!NT_SUCCESS(Status))
        {
            /* Conversion failed */
            SetLastErrorByStatus(Status);
            return NULL;
        }

        /* Otherwise, save the buffer */
        UnicodeName = (LPCWSTR)UnicodeCache->Buffer;
    }

    /* Call the Unicode API */
    return CreateSemaphoreExW(lpSemaphoreAttributes,
                              lInitialCount,
                              lMaximumCount,
                              UnicodeName,
                              dwFlags,
                              dwDesiredAccess);
}
Пример #5
0
asCThreadReadWriteLock::asCThreadReadWriteLock()
{
#if defined AS_POSIX_THREADS
	int r = pthread_rwlock_init(&lock, 0);
	asASSERT( r == 0 );
	UNUSED_VAR(r);
#elif defined AS_WINDOWS_THREADS
#if defined(_MSC_VER) && (WINAPI_FAMILY & WINAPI_FAMILY_PHONE_APP)
	// Only the Ex versions are available on Windows Store

	// Create a semaphore to allow up to maxReaders simultaneous readers
	readLocks = CreateSemaphoreExW(NULL, maxReaders, maxReaders, 0, 0, 0);
	// Create a critical section to synchronize writers
	InitializeCriticalSectionEx(&writeLock, 4000, 0);
#else
	readLocks = CreateSemaphoreW(NULL, maxReaders, maxReaders, 0);
	InitializeCriticalSection(&writeLock);
#endif
#endif
}