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
)
40 Condition::~Condition()
45 /******************************************************************
49 ******************************************************************/
51 ConditionModifier::ConditionModifier(Condition
& aCond
)
54 m_aCond
.m_aMutex
.acquire();
58 ConditionModifier::~ConditionModifier()
61 m_aCond
.m_aCondition
.set();
63 m_aCond
.m_aMutex
.release();
67 /******************************************************************
71 ******************************************************************/
73 ConditionWaiter::timedout::timedout() {}
75 ConditionWaiter::timedout::timedout(timedout
const &) {}
77 ConditionWaiter::timedout::~timedout() {}
79 ConditionWaiter::timedout
&
80 ConditionWaiter::timedout::operator =(timedout
const &) { return *this; }
82 ConditionWaiter::ConditionWaiter(Condition
& aCond
)
86 m_aCond
.m_aCondition
.wait();
87 m_aCond
.m_aMutex
.acquire();
92 m_aCond
.m_aCondition
.reset();
93 m_aCond
.m_aMutex
.release();
99 ConditionWaiter::ConditionWaiter(Condition
& aCond
,sal_uInt32 milliSec
)
103 aTime
.Seconds
= milliSec
/ 1000;
104 aTime
.Nanosec
= 1000000 * ( milliSec
% 1000 );
107 if( m_aCond
.m_aCondition
.wait(&aTime
) ==
108 osl::Condition::result_timeout
)
111 m_aCond
.m_aMutex
.acquire();
113 if(m_aCond
.applies())
116 m_aCond
.m_aCondition
.reset();
117 m_aCond
.m_aMutex
.release();
123 ConditionWaiter::~ConditionWaiter()
125 if(! m_aCond
.applies())
126 m_aCond
.m_aCondition
.reset();
127 m_aCond
.m_aMutex
.release();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */