LibreOffice Module salhelper (master) 1
condition.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
22#include <osl/time.h>
23#include <osl/mutex.hxx>
24
25using namespace salhelper;
26
27
28/******************************************************************
29 * *
30 * Condition *
31 * *
32 ******************************************************************/
33
34Condition::Condition(osl::Mutex& aMutex)
36{
37}
38
39
41{
42}
43
44
45/******************************************************************
46 * *
47 * ConditionModifier *
48 * *
49 ******************************************************************/
50
52 : m_aCond(aCond)
53{
54 m_aCond.m_aMutex.acquire();
55}
56
57
59{
60 if(m_aCond.applies())
62
63 m_aCond.m_aMutex.release();
64}
65
66
67/******************************************************************
68 * *
69 * ConditionWaiter *
70 * *
71 ******************************************************************/
72
74
76
78
81
83 : m_aCond(aCond)
84{
85 while(true) {
86 m_aCond.m_aCondition.wait();
87 m_aCond.m_aMutex.acquire();
88
89 if(m_aCond.applies())
90 break;
91 else {
92 m_aCond.m_aCondition.reset();
93 m_aCond.m_aMutex.release();
94 }
95 }
96}
97
98
100 : m_aCond(aCond)
101{
102 TimeValue aTime;
103 aTime.Seconds = milliSec / 1000;
104 aTime.Nanosec = 1000000 * ( milliSec % 1000 );
105
106 while(true) {
107 if( m_aCond.m_aCondition.wait(&aTime) ==
108 osl::Condition::result_timeout )
109 throw timedout();
110
111 m_aCond.m_aMutex.acquire();
112
113 if(m_aCond.applies())
114 break;
115 else {
116 m_aCond.m_aCondition.reset();
117 m_aCond.m_aMutex.release();
118 }
119 }
120}
121
122
124{
125 if(! m_aCond.applies())
126 m_aCond.m_aCondition.reset();
127 m_aCond.m_aMutex.release();
128}
129
130/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConditionModifier(Condition &aCond)
Definition: condition.cxx:51
ConditionWaiter(Condition &aCond)
Definition: condition.cxx:82
osl::Mutex & m_aMutex
Definition: condition.hxx:57
virtual ~Condition()
Definition: condition.cxx:40
virtual bool applies() const =0
osl::Condition m_aCondition
Definition: condition.hxx:58
std::mutex m_aMutex
std::mutex aMutex
timedout & operator=(timedout const &)
Definition: condition.cxx:80