FairMQ  1.3.9
C++ Message Passing Framework
Common.h
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 #ifndef FAIR_MQ_SHMEM_COMMON_H_
9 #define FAIR_MQ_SHMEM_COMMON_H_
10 
11 #include <atomic>
12 #include <string>
13 
14 #include <boost/interprocess/managed_shared_memory.hpp>
15 #include <boost/functional/hash.hpp>
16 
17 #include <unistd.h>
18 #include <sys/types.h>
19 
20 namespace fair
21 {
22 namespace mq
23 {
24 namespace shmem
25 {
26 
28 {
29  DeviceCounter(unsigned int c)
30  : fCount(c)
31  {}
32 
33  std::atomic<unsigned int> fCount;
34 };
35 
37 {
38  RegionCounter(unsigned int c)
39  : fCount(c)
40  {}
41 
42  std::atomic<unsigned int> fCount;
43 };
44 
46 {
48  : fActive(true)
49  {}
50 
51  bool fActive;
52 };
53 
54 struct MetaHeader
55 {
56  size_t fSize;
57  size_t fRegionId;
58  boost::interprocess::managed_shared_memory::handle_t fHandle;
59  size_t fHint;
60 };
61 
63 {
64  RegionBlock()
65  : fHandle()
66  , fSize(0)
67  , fHint(0)
68  {}
69 
70  RegionBlock(boost::interprocess::managed_shared_memory::handle_t handle, size_t size, size_t hint)
71  : fHandle(handle)
72  , fSize(size)
73  , fHint(hint)
74  {}
75 
76  boost::interprocess::managed_shared_memory::handle_t fHandle;
77  size_t fSize;
78  size_t fHint;
79 };
80 
81 // find id for unique shmem name:
82 // a hash of user id + session id, truncated to 8 characters (to accommodate for name size limit on some systems (MacOS)).
83 inline std::string buildShmIdFromSessionIdAndUserId(const std::string& sessionId)
84 {
85  boost::hash<std::string> stringHash;
86  std::string shmId(std::to_string(stringHash(std::string((std::to_string(geteuid()) + sessionId)))));
87  shmId.resize(8, '_');
88  return shmId;
89 }
90 
91 } // namespace shmem
92 } // namespace mq
93 } // namespace fair
94 
95 #endif /* FAIR_MQ_SHMEM_COMMON_H_ */
Definition: Common.h:45
Definition: Common.h:36
Definition: Common.h:62
Definition: Common.h:27
Tools for interfacing containers to the transport via polymorphic allocators.
Definition: DeviceRunner.h:23
Definition: Common.h:54

privacy