Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _OSL_CONDITN_HXX_
30 : : #define _OSL_CONDITN_HXX_
31 : :
32 : : #ifdef __cplusplus
33 : :
34 : : #include <osl/time.h>
35 : :
36 : : #include <osl/conditn.h>
37 : :
38 : :
39 : : namespace osl
40 : : {
41 : :
42 : : class Condition
43 : : {
44 : : public:
45 : :
46 : : enum Result
47 : : {
48 : : result_ok = osl_cond_result_ok,
49 : : result_error = osl_cond_result_error,
50 : : result_timeout = osl_cond_result_timeout
51 : : };
52 : :
53 : : /* Create a condition.
54 : : */
55 : 55600 : Condition()
56 : : {
57 : 55600 : condition = osl_createCondition();
58 : 55600 : }
59 : :
60 : : /* Release the OS-structures and free condition data-structure.
61 : : */
62 : 54792 : ~Condition()
63 : : {
64 : 54792 : osl_destroyCondition(condition);
65 : 54792 : }
66 : :
67 : : /* Release all waiting threads, check returns sal_True.
68 : : */
69 : 1388425 : void set()
70 : : {
71 : 1388425 : osl_setCondition(condition);
72 : 1388425 : }
73 : :
74 : : /* Reset condition to false: wait() will block, check() returns sal_False.
75 : : */
76 : 1337709 : void reset() {
77 : 1337709 : osl_resetCondition(condition);
78 : 1337709 : }
79 : :
80 : : /** Blocks the calling thread until condition is set.
81 : : */
82 : 494791 : Result wait(const TimeValue *pTimeout = 0)
83 : : {
84 : 494791 : return (Result) osl_waitCondition(condition, pTimeout);
85 : : }
86 : :
87 : : /** Checks if the condition is set without blocking.
88 : : */
89 : 1115123 : sal_Bool check()
90 : : {
91 : 1115123 : return osl_checkCondition(condition);
92 : : }
93 : :
94 : :
95 : : private:
96 : : oslCondition condition;
97 : :
98 : : /** The underlying oslCondition has no reference count.
99 : :
100 : : Since the underlying oslCondition is not a reference counted object, copy
101 : : constructed Condition may work on an already destructed oslCondition object.
102 : :
103 : : */
104 : : Condition(const Condition&);
105 : :
106 : : /** The underlying oslCondition has no reference count.
107 : :
108 : : When destructed, the Condition object destroys the undelying oslCondition,
109 : : which might cause severe problems in case it's a temporary object.
110 : :
111 : : */
112 : : Condition(oslCondition condition);
113 : :
114 : : /** This assignment operator is private for the same reason as
115 : : the copy constructor.
116 : : */
117 : : Condition& operator= (const Condition&);
118 : :
119 : : /** This assignment operator is private for the same reason as
120 : : the constructor taking a oslCondition argument.
121 : : */
122 : : Condition& operator= (oslCondition);
123 : : };
124 : :
125 : : }
126 : :
127 : : #endif /* __cplusplus */
128 : : #endif /* _OSL_CONDITN_HXX_ */
129 : :
130 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|