OpenDDS  Snapshot(2023/04/28-20:55)
DataBlockLockPool.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_DATABLOCKLOCKPOOL_H
9 #define OPENDDS_DCPS_DATABLOCKLOCKPOOL_H
10 
11 #include "Atomic.h"
12 #include "dcps_export.h"
13 #include "PoolAllocationBase.h"
14 
15 #include <ace/Lock_Adapter_T.h>
16 #include <ace/Thread_Mutex.h>
17 #include <ace/Containers_T.h>
18 
19 /**
20  * @class DataBlockLockPool
21  *
22  * @brief Holds and distributes locks to be used for locking
23  * ACE_Data_Blocks. Currently it does not require returning the
24  * locks.
25  *
26  * @NOTE: The lock returned is not guaranteed to be unique.
27  *
28  * @NOTE: This class is thread safe.
29  */
31 public:
33 
34  DataBlockLockPool(unsigned long size)
35  : pool_(size),
36  size_(size),
37  iterator_(0)
38  {
39  }
40 
42 
43  DataBlockLock * get_lock() {
44  const unsigned long index = iterator_++ % size_;
45  return &(pool_[index]);
46  }
47 
48 private:
50 
51  Pool pool_;
52  const unsigned long size_;
53  /// Counter used to track which lock to give out next (modulus size_)
55 };
56 
57 #endif /* DATABLOCKLOCKPOOL_H */
ACE_Lock_Adapter< ACE_Thread_Mutex > DataBlockLock
OpenDDS::DCPS::Atomic< unsigned long > iterator_
Counter used to track which lock to give out next (modulus size_)
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
Holds and distributes locks to be used for locking ACE_Data_Blocks. Currently it does not require ret...
DataBlockLock * get_lock()
size_t size_
DataBlockLockPool(unsigned long size)
ACE_Array< DataBlockLock > Pool
const unsigned long size_