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