summaryrefslogtreecommitdiffstats
path: root/sc/source/core/tool/sharedstringpoolpurge.cxx
blob: 7b8749006efc0bfaca8ede9790852ad18625b091 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 */

#include <sharedstringpoolpurge.hxx>

#include <algorithm>

#include <vcl/svapp.hxx>

namespace sc
{
SharedStringPoolPurge::SharedStringPoolPurge()
    : mTimer("SharedStringPoolPurge")
{
    mTimer.SetPriority(TaskPriority::LOWEST);
    mTimer.SetTimeout(10000); // 10 sec
    mTimer.SetInvokeHandler(LINK(this, SharedStringPoolPurge, timerHandler));
}

SharedStringPoolPurge::~SharedStringPoolPurge() { cleanup(); }

void SharedStringPoolPurge::delayedPurge(const std::shared_ptr<svl::SharedStringPool>& pool)
{
    if (std::find(mPoolsToPurge.begin(), mPoolsToPurge.end(), pool) == mPoolsToPurge.end())
    {
        mPoolsToPurge.push_back(pool);
        SolarMutexGuard guard;
        mTimer.Start();
    }
}

void SharedStringPoolPurge::cleanup()
{
    for (std::shared_ptr<svl::SharedStringPool>& pool : mPoolsToPurge)
    {
        if (pool.use_count() > 1)
            pool->purge();
    }
    mPoolsToPurge.clear();
}

IMPL_LINK_NOARG(SharedStringPoolPurge, timerHandler, Timer*, void)
{
    SolarMutexGuard guard;
    mTimer.Stop();
    cleanup();
}

} // namespace

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */