bump product version to 6.3.0.0.beta1
[LibreOffice.git] / salhelper / source / condition.cxx
bloba83cc753e0a7096dd810128a960cf85cf8d5c5eb
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 .
21 #include <salhelper/condition.hxx>
22 #include <osl/time.h>
23 #include <osl/mutex.hxx>
25 using namespace salhelper;
28 /******************************************************************
29 * *
30 * Condition *
31 * *
32 ******************************************************************/
34 Condition::Condition(osl::Mutex& aMutex)
35 : m_aMutex(aMutex),
36 m_aCondition()
41 Condition::~Condition()
46 /******************************************************************
47 * *
48 * ConditionModifier *
49 * *
50 ******************************************************************/
52 ConditionModifier::ConditionModifier(Condition& aCond)
53 : m_aCond(aCond)
55 m_aCond.m_aMutex.acquire();
59 ConditionModifier::~ConditionModifier()
61 if(m_aCond.applies())
62 m_aCond.m_aCondition.set();
64 m_aCond.m_aMutex.release();
68 /******************************************************************
69 * *
70 * ConditionWaiter *
71 * *
72 ******************************************************************/
74 ConditionWaiter::timedout::timedout() {}
76 ConditionWaiter::timedout::timedout(timedout const &) {}
78 ConditionWaiter::timedout::~timedout() {}
80 ConditionWaiter::timedout &
81 ConditionWaiter::timedout::operator =(timedout const &) { return *this; }
83 ConditionWaiter::ConditionWaiter(Condition& aCond)
84 : m_aCond(aCond)
86 while(true) {
87 m_aCond.m_aCondition.wait();
88 m_aCond.m_aMutex.acquire();
90 if(m_aCond.applies())
91 break;
92 else {
93 m_aCond.m_aCondition.reset();
94 m_aCond.m_aMutex.release();
100 ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
101 : m_aCond(aCond)
103 TimeValue aTime;
104 aTime.Seconds = milliSec / 1000;
105 aTime.Nanosec = 1000000 * ( milliSec % 1000 );
107 while(true) {
108 if( m_aCond.m_aCondition.wait(&aTime) ==
109 osl::Condition::result_timeout )
110 throw timedout();
112 m_aCond.m_aMutex.acquire();
114 if(m_aCond.applies())
115 break;
116 else {
117 m_aCond.m_aCondition.reset();
118 m_aCond.m_aMutex.release();
124 ConditionWaiter::~ConditionWaiter()
126 if(! m_aCond.applies())
127 m_aCond.m_aCondition.reset();
128 m_aCond.m_aMutex.release();
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */