1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
23 #include <osl/mutex.hxx>
25 using namespace salhelper
;
28 /******************************************************************
32 ******************************************************************/
34 Condition::Condition(osl::Mutex
& aMutex
)
41 Condition::~Condition()
46 /******************************************************************
50 ******************************************************************/
52 ConditionModifier::ConditionModifier(Condition
& aCond
)
55 m_aCond
.m_aMutex
.acquire();
59 ConditionModifier::~ConditionModifier()
62 m_aCond
.m_aCondition
.set();
64 m_aCond
.m_aMutex
.release();
68 /******************************************************************
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
)
87 m_aCond
.m_aCondition
.wait();
88 m_aCond
.m_aMutex
.acquire();
93 m_aCond
.m_aCondition
.reset();
94 m_aCond
.m_aMutex
.release();
100 ConditionWaiter::ConditionWaiter(Condition
& aCond
,sal_uInt32 milliSec
)
104 aTime
.Seconds
= milliSec
/ 1000;
105 aTime
.Nanosec
= 1000000 * ( milliSec
% 1000 );
108 if( m_aCond
.m_aCondition
.wait(&aTime
) ==
109 osl::Condition::result_timeout
)
112 m_aCond
.m_aMutex
.acquire();
114 if(m_aCond
.applies())
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: */