Main Page · Modules · All Classes · Class Hierarchy
MAContainerLocker.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include <string>
25 
26 #include <boost/shared_ptr.hpp>
27 #include <boost/unordered_map.hpp>
28 
29 #include "MACoreTypes.hpp"
30 #include "MASignal.hpp"
31 
37 #define MA_CALL_CONTAINER_LOCKER_CTOR \
39  MAContainerLocker(MCGetClassName(this), std::string(__FILE__))
40 
42 #define MA_CONTAINER_LOCK_ID_VARIABLE(_container) \
43  protected: \
44  int _container##LockID; \
45  public:
46 
48 #define MA_GET_CONTAINER_LOCK_ID(_container) \
49  _container##LockID = RegisterContainer(std::string(#_container));
50 
52 #define MA_CONTAINER_LOCK_OTHER_FILE(_container) \
53  for (int LockIi = Lock(_container##LockID, __LINE__, __FILE__); LockIi < 1; \
54  LockIi += Unlock(_container##LockID, __LINE__, __FILE__))
55 #define MA_CONTAINER_LOCK(_container) \
57  for (int LockIi = Lock(_container##LockID, __LINE__); LockIi < 1; \
58  LockIi += Unlock(_container##LockID, __LINE__))
59 
64 {
65 public:
66 
78  MAContainerLocker(const std::string& class_name, const std::string& file_name);
79 
92  int RegisterContainer(const std::string& container_name);
93 
108  int Lock(int container_id, int line, const char* file_name = nullptr);
109 
124  int Unlock(int container_id, int line, const char* file_name = nullptr);
125 
126 private:
128  std::string ClassName;
129 };
130 
Container locker class.
std::string ClassName
Class name.
MAContainerLocker(const std::string &class_name, const std::string &file_name)
Class constructor.
int Lock(int container_id, int line, const char *file_name=nullptr)
Lock a container.
int Unlock(int container_id, int line, const char *file_name=nullptr)
Unlock a container.
int RegisterContainer(const std::string &container_name)
Register a container for locking.