ntsem.c (981B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * NT-specific semaphore handling code. 8 * 9 */ 10 11 #include "primpl.h" 12 13 void _PR_MD_NEW_SEM(_MDSemaphore* md, PRUintn value) { 14 md->sem = CreateSemaphore(NULL, value, 0x7fffffff, NULL); 15 } 16 17 void _PR_MD_DESTROY_SEM(_MDSemaphore* md) { CloseHandle(md->sem); } 18 19 PRStatus _PR_MD_TIMED_WAIT_SEM(_MDSemaphore* md, PRIntervalTime ticks) { 20 int rv; 21 22 rv = WaitForSingleObject(md->sem, PR_IntervalToMilliseconds(ticks)); 23 24 if (rv == WAIT_OBJECT_0) { 25 return PR_SUCCESS; 26 } else { 27 return PR_FAILURE; 28 } 29 } 30 31 PRStatus _PR_MD_WAIT_SEM(_MDSemaphore* md) { 32 return _PR_MD_TIMED_WAIT_SEM(md, PR_INTERVAL_NO_TIMEOUT); 33 } 34 35 void _PR_MD_POST_SEM(_MDSemaphore* md) { ReleaseSemaphore(md->sem, 1, NULL); }