delay, collect and compress LOK invalidations for Writer views
[LibreOffice.git] / salhelper / source / condition.cxx
blob9f1408debcdfd7d0d6f286a590f4a607da79a0b3
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)
40 Condition::~Condition()
45 /******************************************************************
46 * *
47 * ConditionModifier *
48 * *
49 ******************************************************************/
51 ConditionModifier::ConditionModifier(Condition& aCond)
52 : m_aCond(aCond)
54 m_aCond.m_aMutex.acquire();
58 ConditionModifier::~ConditionModifier()
60 if(m_aCond.applies())
61 m_aCond.m_aCondition.set();
63 m_aCond.m_aMutex.release();
67 /******************************************************************
68 * *
69 * ConditionWaiter *
70 * *
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)
83 : m_aCond(aCond)
85 while(true) {
86 m_aCond.m_aCondition.wait();
87 m_aCond.m_aMutex.acquire();
89 if(m_aCond.applies())
90 break;
91 else {
92 m_aCond.m_aCondition.reset();
93 m_aCond.m_aMutex.release();
99 ConditionWaiter::ConditionWaiter(Condition& aCond,sal_uInt32 milliSec)
100 : m_aCond(aCond)
102 TimeValue aTime;
103 aTime.Seconds = milliSec / 1000;
104 aTime.Nanosec = 1000000 * ( milliSec % 1000 );
106 while(true) {
107 if( m_aCond.m_aCondition.wait(&aTime) ==
108 osl::Condition::result_timeout )
109 throw timedout();
111 m_aCond.m_aMutex.acquire();
113 if(m_aCond.applies())
114 break;
115 else {
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: */