xref: /aoo41x/main/sal/inc/osl/semaphor.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _OSL_SEMAPHORE_HXX_
29 #define _OSL_SEMAPHORE_HXX_
30 
31 #ifdef __cplusplus
32 
33 #include <osl/semaphor.h>
34 
35 
36 namespace osl
37 {
38     /** C++ wrapper class around C semaphore functions.
39 
40         @deprecated
41         Must not be used, as unnamed semaphores are not supported on Mac OS X.
42     */
43 	class Semaphore {
44 
45 	public:
46 
47 		/** Creates a semaphore.<BR>
48 			@param InitialCount denotes the starting value the semaphore. If you set it to
49 			zero, the first acquire() blocks. Otherwise InitialCount acquire()s  are
50 			immedeatly  successfull.
51 			@return 0 if the semaphore could not be created, otherwise a handle to the sem.
52 		*/
53 
54 		Semaphore(sal_uInt32 initialCount)
55 		{
56 			semaphore = osl_createSemaphore(initialCount);
57 		}
58 
59 		/** Release the OS-structures and free semaphore data-structure
60 			@return fbbb
61 		*/
62 		~Semaphore()
63 		{
64 			osl_destroySemaphore(semaphore);
65 		}
66 
67 		/** acquire() decreases the count. It will block if it tries to
68 			decrease below zero.
69 			@return False if the system-call failed.
70 		*/
71 		sal_Bool acquire()
72 		{
73 			return osl_acquireSemaphore(semaphore);
74 		}
75 
76 		/** tryToAcquire() tries to decreases the count. It will
77 			return with False if it would decrease the count below zero.
78 			(When acquire() would block.) If it could successfully
79 			decrease the count, it will return True.
80 		*/
81 		sal_Bool tryToAcquire()
82 		{
83 			return osl_tryToAcquireSemaphore(semaphore);
84 		}
85 
86 		/** release() increases the count.
87 			@return False if the system-call failed.
88 		*/
89 		sal_Bool release()
90 		{
91 			return osl_releaseSemaphore(semaphore);
92 		}
93 
94 	private:
95         oslSemaphore semaphore;
96 
97         /** The underlying oslSemaphore has no reference count.
98 
99         Since the underlying oslSemaphore is not a reference counted object, copy
100         constructed Semaphore may work on an already destructed oslSemaphore object.
101 
102         */
103         Semaphore(const Semaphore&);
104 
105         /** The underlying oslSemaphore has no reference count.
106 
107         When destructed, the Semaphore object destroys the undelying oslSemaphore,
108         which might cause severe problems in case it's a temporary object.
109 
110         */
111         Semaphore(oslSemaphore Semaphore);
112 
113         /** This assignment operator is private for the same reason as
114             the copy constructor.
115         */
116         Semaphore& operator= (const Semaphore&);
117 
118         /** This assignment operator is private for the same reason as
119             the constructor taking a oslSemaphore argument.
120         */
121         Semaphore& operator= (oslSemaphore);
122 	};
123 }
124 
125 #endif  /* __cplusplus */
126 #endif  /* _OSL_SEMAPHORE_HXX_  */
127