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_CONDITN_HXX_ 25 #define _OSL_CONDITN_HXX_ 26 27 #ifdef __cplusplus 28 29 #include <osl/time.h> 30 31 #include <osl/conditn.h> 32 33 34 namespace osl 35 { 36 37 class Condition 38 { 39 public: 40 41 enum Result 42 { 43 result_ok = osl_cond_result_ok, 44 result_error = osl_cond_result_error, 45 result_timeout = osl_cond_result_timeout 46 }; 47 48 /* Create a condition. 49 */ Condition()50 Condition() 51 { 52 condition = osl_createCondition(); 53 } 54 55 /* Release the OS-structures and free condition data-structure. 56 */ ~Condition()57 ~Condition() 58 { 59 osl_destroyCondition(condition); 60 } 61 62 /* Release all waiting threads, check returns sal_True. 63 */ set()64 void set() 65 { 66 osl_setCondition(condition); 67 } 68 69 /* Reset condition to false: wait() will block, check() returns sal_False. 70 */ reset()71 void reset() { 72 osl_resetCondition(condition); 73 } 74 75 /** Blocks the calling thread until condition is set. 76 */ wait(const TimeValue * pTimeout=0)77 Result wait(const TimeValue *pTimeout = 0) 78 { 79 return (Result) osl_waitCondition(condition, pTimeout); 80 } 81 82 /** Checks if the condition is set without blocking. 83 */ check()84 sal_Bool check() 85 { 86 return osl_checkCondition(condition); 87 } 88 89 90 private: 91 oslCondition condition; 92 93 /** The underlying oslCondition has no reference count. 94 95 Since the underlying oslCondition is not a reference counted object, copy 96 constructed Condition may work on an already destructed oslCondition object. 97 98 */ 99 Condition(const Condition&); 100 101 /** The underlying oslCondition has no reference count. 102 103 When destructed, the Condition object destroys the undelying oslCondition, 104 which might cause severe problems in case it's a temporary object. 105 106 */ 107 Condition(oslCondition condition); 108 109 /** This assignment operator is private for the same reason as 110 the copy constructor. 111 */ 112 Condition& operator= (const Condition&); 113 114 /** This assignment operator is private for the same reason as 115 the constructor taking a oslCondition argument. 116 */ 117 Condition& operator= (oslCondition); 118 }; 119 120 } 121 122 #endif /* __cplusplus */ 123 #endif /* _OSL_CONDITN_HXX_ */ 124 125