1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: semaphor.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _OSL_SEMAPHORE_HXX_
32 #define _OSL_SEMAPHORE_HXX_
36 #include <osl/semaphor.h>
46 /** Creates a semaphore.<BR>
47 @param InitialCount denotes the starting value the semaphore. If you set it to
48 zero, the first acquire() blocks. Otherwise InitialCount acquire()s are
49 immedeatly successfull.
50 @return 0 if the semaphore could not be created, otherwise a handle to the sem.
53 Semaphore(sal_uInt32 initialCount
)
55 semaphore
= osl_createSemaphore(initialCount
);
58 /** Release the OS-structures and free semaphore data-structure
63 osl_destroySemaphore(semaphore
);
66 /** acquire() decreases the count. It will block if it tries to
68 @return False if the system-call failed.
72 return osl_acquireSemaphore(semaphore
);
75 /** tryToAcquire() tries to decreases the count. It will
76 return with False if it would decrease the count below zero.
77 (When acquire() would block.) If it could successfully
78 decrease the count, it will return True.
80 sal_Bool
tryToAcquire()
82 return osl_tryToAcquireSemaphore(semaphore
);
85 /** release() increases the count.
86 @return False if the system-call failed.
90 return osl_releaseSemaphore(semaphore
);
94 oslSemaphore semaphore
;
96 /** The underlying oslSemaphore has no reference count.
98 Since the underlying oslSemaphore is not a reference counted object, copy
99 constructed Semaphore may work on an already destructed oslSemaphore object.
102 Semaphore(const Semaphore
&);
104 /** The underlying oslSemaphore has no reference count.
106 When destructed, the Semaphore object destroys the undelying oslSemaphore,
107 which might cause severe problems in case it's a temporary object.
110 Semaphore(oslSemaphore Semaphore
);
112 /** This assignment operator is private for the same reason as
113 the copy constructor.
115 Semaphore
& operator= (const Semaphore
&);
117 /** This assignment operator is private for the same reason as
118 the constructor taking a oslSemaphore argument.
120 Semaphore
& operator= (oslSemaphore
);
124 #endif /* __cplusplus */
125 #endif /* _OSL_SEMAPHORE_HXX_ */