libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNFileShield.cpp
Go to the documentation of this file.
1 /* Copyright 2011-2016 CoReNum, INSA-Lyon
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNFileShield.cpp
19  * \author Yann LEYDIER
20  */
21 
22 #include <CRNIO/CRNFileShield.h>
23 
24 using namespace crn;
25 
27 FileShield::FileShield()
28 {
29 }
30 
34 FileShield& FileShield::getInstance()
35 {
36  static FileShield fs;
37  return fs;
38 }
39 
44 std::mutex& FileShield::GetMutex(const Path &fname)
45 {
46  FileShield &fs(getInstance());
47  auto it = fs.shields.find(fname);
48  if (it == fs.shields.end())
49  {
50 
51  return *(fs.shields.insert(std::make_pair(fname, std::unique_ptr<std::mutex>(new std::mutex))).first->second);
52  }
53  else
54  {
55  return *(it->second);
56  }
57 }
58 
static std::mutex & GetMutex(const Path &fname)
Gets the mutex associated to a file.
A convenience class for file paths.
Definition: CRNPath.h:39
A mutex manager for file access.
Definition: CRNFileShield.h:46