geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
SharedMemory.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 SHAREDMEMORY_HPP_INCLUDE
7 #define SHAREDMEMORY_HPP_INCLUDE
8 
9 #include <stdlib.h>
10 
11 #include <memory>
12 #include <string>
13 
14 #include "geopm_public.h"
15 
17 
18 namespace geopm
19 {
22  {
23  public:
24  SharedMemory() = default;
25  SharedMemory(const SharedMemory &other) = default;
26  SharedMemory &operator=(const SharedMemory &other) = default;
27  virtual ~SharedMemory() = default;
31  virtual void *pointer(void) const = 0;
35  virtual std::string key(void) const = 0;
39  virtual size_t size(void) const = 0;
41  virtual void unlink(void) = 0;
48  virtual std::unique_ptr<SharedMemoryScopedLock> get_scoped_lock(void) = 0;
52  static std::unique_ptr<SharedMemory> make_unique_owner(const std::string &shm_key, size_t size);
56  static std::unique_ptr<SharedMemory> make_unique_owner_secure(const std::string &shm_key, size_t size);
62  static std::unique_ptr<SharedMemory> make_unique_user(const std::string &shm_key, unsigned int timeout);
64  // and uid if current permissions allow for the change.
65  virtual void chown(const unsigned int uid, const unsigned int gid) const = 0;
66  static void cleanup_shmem(void);
67  };
68 }
69 
70 #endif
This class encapsulates an inter-process shared memory region.
Definition: SharedMemory.hpp:22
virtual void * pointer(void) const =0
Retrieve a pointer to the shared memory region.
virtual std::string key(void) const =0
Retrieve the key to the shared memory region.
virtual size_t size(void) const =0
Retrieve the size of the shared memory region.
SharedMemory & operator=(const SharedMemory &other)=default
SharedMemory(const SharedMemory &other)=default
virtual void chown(const unsigned int uid, const unsigned int gid) const =0
Modifies the shared memory to be owned by the specified gid.
virtual ~SharedMemory()=default
virtual void unlink(void)=0
Unlink the shared memory region.
virtual std::unique_ptr< SharedMemoryScopedLock > get_scoped_lock(void)=0
Attempt to lock the mutex for the shared memory region and return a scoped mutex object that will unl...
SharedMemory()=default
#define GEOPM_PUBLIC
Definition: geopm_public.h:10
Definition: Agg.cpp:20