1565d668cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3565d668cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4565d668cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5565d668cSAndrew Rist * distributed with this work for additional information 6565d668cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7565d668cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8565d668cSAndrew Rist * "License"); you may not use this file except in compliance 9565d668cSAndrew Rist * with the License. You may obtain a copy of the License at 10565d668cSAndrew Rist * 11565d668cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12565d668cSAndrew Rist * 13565d668cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14565d668cSAndrew Rist * software distributed under the License is distributed on an 15565d668cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16565d668cSAndrew Rist * KIND, either express or implied. See the License for the 17565d668cSAndrew Rist * specific language governing permissions and limitations 18565d668cSAndrew Rist * under the License. 19565d668cSAndrew Rist * 20565d668cSAndrew Rist *************************************************************/ 21565d668cSAndrew Rist 22565d668cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _OSL_SEMAPHORE_HXX_ 25cdf0e10cSrcweir #define _OSL_SEMAPHORE_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifdef __cplusplus 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <osl/semaphor.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace osl 33cdf0e10cSrcweir { 34cdf0e10cSrcweir /** C++ wrapper class around C semaphore functions. 35cdf0e10cSrcweir 36cdf0e10cSrcweir @deprecated 37cdf0e10cSrcweir Must not be used, as unnamed semaphores are not supported on Mac OS X. 38cdf0e10cSrcweir */ 39cdf0e10cSrcweir class Semaphore { 40cdf0e10cSrcweir 41cdf0e10cSrcweir public: 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** Creates a semaphore.<BR> 44cdf0e10cSrcweir @param InitialCount denotes the starting value the semaphore. If you set it to 45cdf0e10cSrcweir zero, the first acquire() blocks. Otherwise InitialCount acquire()s are 46*211c5700SPedro Giffuni immediately successful. 47cdf0e10cSrcweir @return 0 if the semaphore could not be created, otherwise a handle to the sem. 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir Semaphore(sal_uInt32 initialCount)50cdf0e10cSrcweir Semaphore(sal_uInt32 initialCount) 51cdf0e10cSrcweir { 52cdf0e10cSrcweir semaphore = osl_createSemaphore(initialCount); 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** Release the OS-structures and free semaphore data-structure 56cdf0e10cSrcweir @return fbbb 57cdf0e10cSrcweir */ ~Semaphore()58cdf0e10cSrcweir ~Semaphore() 59cdf0e10cSrcweir { 60cdf0e10cSrcweir osl_destroySemaphore(semaphore); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir /** acquire() decreases the count. It will block if it tries to 64cdf0e10cSrcweir decrease below zero. 65cdf0e10cSrcweir @return False if the system-call failed. 66cdf0e10cSrcweir */ acquire()67cdf0e10cSrcweir sal_Bool acquire() 68cdf0e10cSrcweir { 69cdf0e10cSrcweir return osl_acquireSemaphore(semaphore); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** tryToAcquire() tries to decreases the count. It will 73cdf0e10cSrcweir return with False if it would decrease the count below zero. 74cdf0e10cSrcweir (When acquire() would block.) If it could successfully 75cdf0e10cSrcweir decrease the count, it will return True. 76cdf0e10cSrcweir */ tryToAcquire()77cdf0e10cSrcweir sal_Bool tryToAcquire() 78cdf0e10cSrcweir { 79cdf0e10cSrcweir return osl_tryToAcquireSemaphore(semaphore); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir /** release() increases the count. 83cdf0e10cSrcweir @return False if the system-call failed. 84cdf0e10cSrcweir */ release()85cdf0e10cSrcweir sal_Bool release() 86cdf0e10cSrcweir { 87cdf0e10cSrcweir return osl_releaseSemaphore(semaphore); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir private: 91cdf0e10cSrcweir oslSemaphore semaphore; 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** The underlying oslSemaphore has no reference count. 94cdf0e10cSrcweir 95cdf0e10cSrcweir Since the underlying oslSemaphore is not a reference counted object, copy 96cdf0e10cSrcweir constructed Semaphore may work on an already destructed oslSemaphore object. 97cdf0e10cSrcweir 98cdf0e10cSrcweir */ 99cdf0e10cSrcweir Semaphore(const Semaphore&); 100cdf0e10cSrcweir 101cdf0e10cSrcweir /** The underlying oslSemaphore has no reference count. 102cdf0e10cSrcweir 103cdf0e10cSrcweir When destructed, the Semaphore object destroys the undelying oslSemaphore, 104cdf0e10cSrcweir which might cause severe problems in case it's a temporary object. 105cdf0e10cSrcweir 106cdf0e10cSrcweir */ 107cdf0e10cSrcweir Semaphore(oslSemaphore Semaphore); 108cdf0e10cSrcweir 109cdf0e10cSrcweir /** This assignment operator is private for the same reason as 110cdf0e10cSrcweir the copy constructor. 111cdf0e10cSrcweir */ 112cdf0e10cSrcweir Semaphore& operator= (const Semaphore&); 113cdf0e10cSrcweir 114cdf0e10cSrcweir /** This assignment operator is private for the same reason as 115cdf0e10cSrcweir the constructor taking a oslSemaphore argument. 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir Semaphore& operator= (oslSemaphore); 118cdf0e10cSrcweir }; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir #endif /* __cplusplus */ 122cdf0e10cSrcweir #endif /* _OSL_SEMAPHORE_HXX_ */ 123