Mercurial > sdl-ios-xcode
diff src/thread/win32/win_ce_semaphore.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
line wrap: on
line diff
--- a/src/thread/win32/win_ce_semaphore.c Mon May 29 03:53:21 2006 +0000 +++ b/src/thread/win32/win_ce_semaphore.c Mon May 29 04:04:35 2006 +0000 @@ -33,13 +33,13 @@ #include "win_ce_semaphore.h" -static SYNCHHANDLE CleanUp (SYNCHHANDLE hSynch, DWORD Flags); +static SYNCHHANDLE CleanUp(SYNCHHANDLE hSynch, DWORD Flags); SYNCHHANDLE -CreateSemaphoreCE (LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, /* pointer to security attributes */ - LONG lInitialCount, /* initial count */ - LONG lMaximumCount, /* maximum count */ - LPCTSTR lpName) +CreateSemaphoreCE(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes, /* pointer to security attributes */ + LONG lInitialCount, /* initial count */ + LONG lMaximumCount, /* maximum count */ + LPCTSTR lpName) /* Semaphore for use with Windows CE that does not support them directly. Requires a counter, a mutex to protect the counter, and an autoreset event. @@ -62,13 +62,12 @@ if (lInitialCount > lMaximumCount || lMaximumCount < 0 || lInitialCount < 0) { /* Bad parameters */ - SetLastError (SYNCH_ERROR); + SetLastError(SYNCH_ERROR); __leave; } hSynch = - HeapAlloc (GetProcessHeap (), HEAP_ZERO_MEMORY, - SYNCH_HANDLE_SIZE); + HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, SYNCH_HANDLE_SIZE); if (hSynch == NULL) __leave; @@ -76,30 +75,29 @@ hSynch->CurCount = lInitialCount; hSynch->lpName = lpName; - hSynch->hMutex = CreateMutex (lpSemaphoreAttributes, FALSE, NULL); + hSynch->hMutex = CreateMutex(lpSemaphoreAttributes, FALSE, NULL); - WaitForSingleObject (hSynch->hMutex, INFINITE); + WaitForSingleObject(hSynch->hMutex, INFINITE); /* Create the event. It is initially signaled if and only if the initial count is > 0 */ - hSynch->hEvent = CreateEvent (lpSemaphoreAttributes, FALSE, - lInitialCount > 0, NULL); - ReleaseMutex (hSynch->hMutex); + hSynch->hEvent = CreateEvent(lpSemaphoreAttributes, FALSE, + lInitialCount > 0, NULL); + ReleaseMutex(hSynch->hMutex); hSynch->hSemph = NULL; } __finally { /* Return with the handle, or, if there was any error, return a null after closing any open handles and freeing any allocated memory. */ result = - CleanUp (hSynch, - 6 /* An event and a mutex, but no semaphore. */ ); + CleanUp(hSynch, 6 /* An event and a mutex, but no semaphore. */ ); } return result; } BOOL -ReleaseSemaphoreCE (SYNCHHANDLE hSemCE, LONG cReleaseCount, - LPLONG lpPreviousCount) +ReleaseSemaphoreCE(SYNCHHANDLE hSemCE, LONG cReleaseCount, + LPLONG lpPreviousCount) /* Windows CE equivalent to ReleaseSemaphore. */ { BOOL Result = TRUE; @@ -108,13 +106,13 @@ would not cause the total count to exceed the maximum. */ __try { - WaitForSingleObject (hSemCE->hMutex, INFINITE); + WaitForSingleObject(hSemCE->hMutex, INFINITE); /* reply only if asked to */ if (lpPreviousCount != NULL) *lpPreviousCount = hSemCE->CurCount; if (hSemCE->CurCount + cReleaseCount > hSemCE->MaxCount || cReleaseCount <= 0) { - SetLastError (SYNCH_ERROR); + SetLastError(SYNCH_ERROR); Result = FALSE; __leave; } @@ -123,22 +121,22 @@ /* Set the autoreset event, releasing exactly one waiting thread, now or in the future. */ - SetEvent (hSemCE->hEvent); + SetEvent(hSemCE->hEvent); } __finally { - ReleaseMutex (hSemCE->hMutex); + ReleaseMutex(hSemCE->hMutex); } return Result; } DWORD -WaitForSemaphoreCE (SYNCHHANDLE hSemCE, DWORD dwMilliseconds) +WaitForSemaphoreCE(SYNCHHANDLE hSemCE, DWORD dwMilliseconds) /* Windows CE semaphore equivalent of WaitForSingleObject. */ { DWORD WaitResult; - WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); + WaitResult = WaitForSingleObject(hSemCE->hMutex, dwMilliseconds); if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) return WaitResult; while (hSemCE->CurCount <= 0) { @@ -148,14 +146,14 @@ available. First, of course, the mutex must be released so that another thread will be capable of setting the event. */ - ReleaseMutex (hSemCE->hMutex); + ReleaseMutex(hSemCE->hMutex); /* Wait for the event to be signaled, indicating a semaphore state change. The event is autoreset and signaled with a SetEvent (not PulseEvent) so exactly one waiting thread (whether or not there is currently a waiting thread) is released as a result of the SetEvent. */ - WaitResult = WaitForSingleObject (hSemCE->hEvent, dwMilliseconds); + WaitResult = WaitForSingleObject(hSemCE->hEvent, dwMilliseconds); if (WaitResult != WAIT_OBJECT_0) return WaitResult; @@ -168,7 +166,7 @@ a defect which could appear if the semaphore state changed between the two waits. */ - WaitResult = WaitForSingleObject (hSemCE->hMutex, dwMilliseconds); + WaitResult = WaitForSingleObject(hSemCE->hMutex, dwMilliseconds); if (WaitResult != WAIT_OBJECT_0 && WaitResult != WAIT_ABANDONED_0) return WaitResult; @@ -181,29 +179,29 @@ before releasing the mutex. */ if (hSemCE->CurCount > 0) - SetEvent (hSemCE->hEvent); - ReleaseMutex (hSemCE->hMutex); + SetEvent(hSemCE->hEvent); + ReleaseMutex(hSemCE->hMutex); return WaitResult; } BOOL -CloseSynchHandle (SYNCHHANDLE hSynch) +CloseSynchHandle(SYNCHHANDLE hSynch) /* Close a synchronization handle. Improvement: Test for a valid handle before dereferencing the handle. */ { BOOL Result = TRUE; if (hSynch->hEvent != NULL) - Result = Result && CloseHandle (hSynch->hEvent); + Result = Result && CloseHandle(hSynch->hEvent); if (hSynch->hMutex != NULL) - Result = Result && CloseHandle (hSynch->hMutex); + Result = Result && CloseHandle(hSynch->hMutex); if (hSynch->hSemph != NULL) - Result = Result && CloseHandle (hSynch->hSemph); - HeapFree (GetProcessHeap (), 0, hSynch); + Result = Result && CloseHandle(hSynch->hSemph); + HeapFree(GetProcessHeap(), 0, hSynch); return (Result); } static SYNCHHANDLE -CleanUp (SYNCHHANDLE hSynch, DWORD Flags) +CleanUp(SYNCHHANDLE hSynch, DWORD Flags) { /* Prepare to return from a create of a synchronization handle. If there was any failure, free any allocated resources. "Flags" indicates which Win32 objects are required in the @@ -220,7 +218,7 @@ if ((Flags & 1) == 1 && (hSynch->hEvent == NULL)) ok = FALSE; if (!ok) { - CloseSynchHandle (hSynch); + CloseSynchHandle(hSynch); return NULL; } /* Everything worked */