geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
SharedMemoryImp.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef SHAREDMEMORYIMP_HPP_INCLUDE
7 #define SHAREDMEMORYIMP_HPP_INCLUDE
8 
9 #include "geopm/SharedMemory.hpp"
10 
11 namespace geopm
12 {
14  {
15  public:
18  virtual ~SharedMemoryImp();
19  SharedMemoryImp(SharedMemoryImp &other) = delete;
20  SharedMemoryImp &operator=(const SharedMemoryImp &other) = delete;
23  void *pointer(void) const override;
26  std::string key(void) const override;
27  size_t size(void) const override;
28  void unlink(void) override;
29  std::unique_ptr<SharedMemoryScopedLock> get_scoped_lock(void) override;
35  void create_memory_region(const std::string &shm_key, size_t size, bool is_secure);
43  void attach_memory_region(const std::string &shm_key, unsigned int timeout);
45  // and uid if current permissions allow for the change.
48  void chown(const unsigned int uid, const unsigned int gid) const override;
50  static std::string construct_shm_path(const std::string &key);
51 
52  private:
54  std::string m_shm_key;
56  std::string m_shm_path;
58  size_t m_size;
60  void *m_ptr;
63  bool m_is_linked;
67  bool m_do_unlink_check;
68  };
69 }
70 
71 #endif
This class encapsulates an inter-process shared memory region.
Definition: SharedMemory.hpp:22
Definition: SharedMemoryImp.hpp:14
SharedMemoryImp(SharedMemoryImp &other)=delete
void * pointer(void) const override
Retrieve a pointer to the shared memory region.
Definition: SharedMemory.cpp:191
size_t size(void) const override
Retrieve the size of the shared memory region.
Definition: SharedMemory.cpp:201
SharedMemoryImp()
Definition: SharedMemory.cpp:101
static std::string construct_shm_path(const std::string &key)
Construct the file path to use for the provided key.
Definition: SharedMemory.cpp:328
std::unique_ptr< SharedMemoryScopedLock > get_scoped_lock(void) override
Attempt to lock the mutex for the shared memory region and return a scoped mutex object that will unl...
Definition: SharedMemory.cpp:206
void unlink(void) override
Unlink the shared memory region.
Definition: SharedMemory.cpp:176
void chown(const unsigned int uid, const unsigned int gid) const override
Modifies the shared memory to be owned by the specified gid.
Definition: SharedMemory.cpp:296
SharedMemoryImp & operator=(const SharedMemoryImp &other)=delete
void create_memory_region(const std::string &shm_key, size_t size, bool is_secure)
Takes a key and a size and creates an inter-process shared memory region.
Definition: SharedMemory.cpp:110
virtual ~SharedMemoryImp()
Destructor destroys and unlinks the shared memory region.
Definition: SharedMemory.cpp:165
std::string key(void) const override
Retrieve the key to the shared memory region.
Definition: SharedMemory.cpp:196
void attach_memory_region(const std::string &shm_key, unsigned int timeout)
Takes a key and attempts to attach to a inter-process shared memory region. This version of the const...
Definition: SharedMemory.cpp:211
Definition: Agg.cpp:20