-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMapLockManager.h
More file actions
53 lines (37 loc) · 1.65 KB
/
MapLockManager.h
File metadata and controls
53 lines (37 loc) · 1.65 KB
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
// -*- c++ -*-
// Copyright 2009 Isis Innovation Limited
/********************************************************************
A Class to manage the locking and unlocking of maps
Author: Robert Castle, 2008, bob@robots.ox.ac.uk
********************************************************************/
#ifndef __MAP_LOCK_MANAGER__
#define __MAP_LOCK_MANAGER__
#include <map>
#include <cvd/thread.h>
namespace PTAMM {
/**
* This class is to be used by any thread that want to gain a sole
* lock on a map to use it. Typically this used by the mapserializer.
* But other threads my need to use it in the future.
*
* @TODO on unregister, check for stale locks and release.
*/
class MapLockManager
{
public:
MapLockManager() : mLockingThread(NULL), mbLocked(false) {}
~MapLockManager() {}
void Register( void * t ); // call when switching to a map
void UnRegister( void * t); // call when leaving a map
bool IsRegistered( void * t); // check if thread is registered
bool IsLocked() { return mbLocked; } // check if map is locked
bool CheckLockAndWait( void * t, int nTimeout = 0); // if locked wait for release
bool LockMap( void * t, int nTimeout = 0 ); // lock a map. waits until all thread ack
bool UnlockMap( void * t); // unlock a map. only if thread is the owner
private:
std::map< void *, bool > mLockRecords; // which threads are currently using this map
void * mLockingThread; // who want to lock / has locked the thread
bool mbLocked; // is the map locked
};
}
#endif