Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / osl / conditn.hxx
blob07d6979480777e7a908766c76ab290c6b54b8e05
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_OSL_CONDITN_HXX
21 #define INCLUDED_OSL_CONDITN_HXX
23 #include <sal/config.h>
25 #include <cstddef>
27 #include <osl/time.h>
29 #include <osl/conditn.h>
31 #if defined(MACOSX) && defined(__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES)
32 # if __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES == 1
33 # undef check
34 # endif
35 #endif
37 namespace osl
39 /**
40 * A deprecated condition.
42 * @deprecated use C++11's std::condition_variable instead
43 * for a more robust and helpful condition.
45 * Warning: the Condition abstraction is inadequate for any
46 * situation where there may be multiple threads setting,
47 * waiting, and resetting the same condition. It can only be
48 * used to synchronise interactions between two threads
49 * cf. lost wakeups in:
50 * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html
52 class Condition
54 public:
56 enum Result
58 result_ok = osl_cond_result_ok,
59 result_error = osl_cond_result_error,
60 result_timeout = osl_cond_result_timeout
63 /**
64 * Create a condition.
66 * @deprecated use C++11's std::condition_variable instead
67 * for a more robust and helpful condition.
69 Condition()
71 condition = osl_createCondition();
74 /* Release the OS-structures and free condition data-structure.
76 ~Condition()
78 osl_destroyCondition(condition);
81 /* Release all waiting threads, check returns true.
83 void set()
85 osl_setCondition(condition);
88 /* Reset condition to false: wait() will block, check() returns false.
90 void reset() {
91 osl_resetCondition(condition);
94 /** Blocks the calling thread until condition is set.
96 Result wait(const TimeValue *pTimeout = NULL)
98 return (Result) osl_waitCondition(condition, pTimeout);
101 #if defined LIBO_INTERNAL_ONLY
102 Result wait(TimeValue const & timeout) { return wait(&timeout); }
103 #endif
105 /** Checks if the condition is set without blocking.
107 bool check()
109 return osl_checkCondition(condition);
113 private:
114 oslCondition condition;
116 /** The underlying oslCondition has no reference count.
118 Since the underlying oslCondition is not a reference counted object, copy
119 constructed Condition may work on an already destructed oslCondition object.
122 Condition(const Condition&) SAL_DELETED_FUNCTION;
124 /** This assignment operator is deleted for the same reason as
125 the copy constructor.
127 Condition& operator= (const Condition&) SAL_DELETED_FUNCTION;
132 #endif // INCLUDED_OSL_CONDITN_HXX
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */