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>
25 using namespace salhelper
;
28 /******************************************************************
32 ******************************************************************/
34 Condition::Condition(osl::Mutex
& aMutex
)
36 m_aCondition(osl_createCondition())
41 Condition::~Condition()
43 osl_destroyCondition(m_aCondition
);
47 /******************************************************************
51 ******************************************************************/
53 ConditionModifier::ConditionModifier(Condition
& aCond
)
56 m_aCond
.m_aMutex
.acquire();
60 ConditionModifier::~ConditionModifier()
63 osl_setCondition(m_aCond
.m_aCondition
);
65 m_aCond
.m_aMutex
.release();
70 /******************************************************************
74 ******************************************************************/
76 ConditionWaiter::timedout::timedout() {}
78 ConditionWaiter::timedout::timedout(timedout
const &) {}
80 ConditionWaiter::timedout::~timedout() {}
82 ConditionWaiter::timedout
&
83 ConditionWaiter::timedout::operator =(timedout
const &) { return *this; }
85 ConditionWaiter::ConditionWaiter(Condition
& aCond
)
89 osl_waitCondition(m_aCond
.m_aCondition
,0);
90 m_aCond
.m_aMutex
.acquire();
95 osl_resetCondition(m_aCond
.m_aCondition
);
96 m_aCond
.m_aMutex
.release();
102 ConditionWaiter::ConditionWaiter(Condition
& aCond
,sal_uInt32 milliSec
)
104 ConditionWaiter::timedout
109 aTime
.Seconds
= milliSec
/ 1000;
110 aTime
.Nanosec
= 1000000 * ( milliSec
% 1000 );
113 if( osl_waitCondition(m_aCond
.m_aCondition
,&aTime
) ==
114 osl_cond_result_timeout
)
117 m_aCond
.m_aMutex
.acquire();
119 if(m_aCond
.applies())
122 osl_resetCondition(m_aCond
.m_aCondition
);
123 m_aCond
.m_aMutex
.release();
129 ConditionWaiter::~ConditionWaiter()
131 if(! m_aCond
.applies())
132 osl_resetCondition(m_aCond
.m_aCondition
);
133 m_aCond
.m_aMutex
.release();
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */