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