2020-04-24 02:46:54 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2020-04-24 02:46:54 -05:00
|
|
|
* 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 <cassert>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
|
2021-09-01 03:11:55 -05:00
|
|
|
#include "Log.hpp"
|
2020-04-24 02:46:54 -05:00
|
|
|
#include "MobileApp.hpp"
|
|
|
|
|
|
|
|
#if MOBILEAPP
|
|
|
|
|
2021-09-01 03:11:55 -05:00
|
|
|
static std::map<unsigned, DocumentData*> idToDocDataMap;
|
2020-04-24 02:46:54 -05:00
|
|
|
static std::mutex idToDocDataMapMutex;
|
|
|
|
|
2021-09-01 03:11:55 -05:00
|
|
|
DocumentData &DocumentData::allocate(unsigned docId)
|
2020-04-24 02:46:54 -05:00
|
|
|
{
|
|
|
|
const std::lock_guard<std::mutex> lock(idToDocDataMapMutex);
|
|
|
|
|
|
|
|
assert(idToDocDataMap.find(docId) == idToDocDataMap.end());
|
2021-09-01 03:11:55 -05:00
|
|
|
auto p = new DocumentData();
|
|
|
|
idToDocDataMap[docId] = p;
|
|
|
|
return *p;
|
2020-04-24 02:46:54 -05:00
|
|
|
}
|
|
|
|
|
2021-09-01 03:11:55 -05:00
|
|
|
DocumentData & DocumentData::get(unsigned docId)
|
2020-04-24 02:46:54 -05:00
|
|
|
{
|
|
|
|
const std::lock_guard<std::mutex> lock(idToDocDataMapMutex);
|
|
|
|
|
|
|
|
assert(idToDocDataMap.find(docId) != idToDocDataMap.end());
|
2021-09-01 03:11:55 -05:00
|
|
|
return *idToDocDataMap[docId];
|
2020-04-24 02:46:54 -05:00
|
|
|
}
|
|
|
|
|
2021-09-01 03:11:55 -05:00
|
|
|
void DocumentData::deallocate(unsigned docId)
|
2020-04-24 02:46:54 -05:00
|
|
|
{
|
|
|
|
assert(idToDocDataMap.find(docId) != idToDocDataMap.end());
|
2023-05-15 13:35:45 -05:00
|
|
|
// Does get() really need to called during the destructor?
|
|
|
|
get(docId);
|
2021-09-01 03:11:55 -05:00
|
|
|
auto p = idToDocDataMap.find(docId);
|
|
|
|
delete p->second;
|
2020-04-24 02:46:54 -05:00
|
|
|
idToDocDataMap.erase(docId);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|