Realm
A distributed, event-based tasking library
Loading...
Searching...
No Matches
shm.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Stanford University, NVIDIA Corporation
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef REALM_SHM_H
19#define REALM_SHM_H
20#include "realm/realm_config.h"
21#include "realm/utils.h"
22#include <string>
23
24namespace Realm {
25
32 public:
39
43
44 // disable copying of SharedMemoryInfo
47
50 template <typename T>
51 T *get_ptr() const
52 {
53 return reinterpret_cast<T *>(base);
54 }
55 OsHandle get_handle() const { return handle; }
56 size_t get_size() const { return size; }
57 std::string get_name() const { return name; }
58 explicit operator bool() const { return base != nullptr; }
60
64 void unlink(void);
65
75 static bool create(SharedMemoryInfo &info, size_t size, const char *name = nullptr,
76 int numa_node = -1);
77
85 static bool open(SharedMemoryInfo &info, const std::string &name, size_t size);
86
94 static bool open(SharedMemoryInfo &info, OsHandle handle, size_t size);
95
96 private:
97 std::string name; // name of the shared memory object, if applicable
98 void *base; // base address of the mapped memory object
99 size_t size; // Size of the mapped memory object
100 OsHandle handle; // OS-native handle to mapped memory object
101 bool owner; // True if this SharedMemoryInfo was created via
102 // \sa SharedMemoryInfo::create, false otherwise
103 };
104
105}; // namespace Realm
106
107#endif // ifndef REALM_SHM_H
Holds a reference to a mapped shared memory region and all the information used to create/open it....
Definition shm.h:31
static bool create(SharedMemoryInfo &info, size_t size, const char *name=nullptr, int numa_node=-1)
Creates a shared memory region accessible via handle.
SharedMemoryInfo & operator=(const SharedMemoryInfo &)=delete
OsHandle get_handle() const
Definition shm.h:55
SharedMemoryInfo(const SharedMemoryInfo &)=delete
std::string get_name() const
Definition shm.h:57
void unlink(void)
Removes the name from the shared memory region such that it can't be opened by it's name any more and...
T * get_ptr() const
Definition shm.h:51
SharedMemoryInfo & operator=(SharedMemoryInfo &&other)
size_t get_size() const
Definition shm.h:56
static bool open(SharedMemoryInfo &info, OsHandle handle, size_t size)
Opens a previously created shared memory region given it's associated handle and size.
~SharedMemoryInfo(void)
On destruction, the SharedMemoryInfo will unmap the memory associated with this shared region,...
static bool open(SharedMemoryInfo &info, const std::string &name, size_t size)
Opens a previously created shared memory region given it's name and size.
SharedMemoryInfo(SharedMemoryInfo &&other)
Definition activemsg.h:38
int OsHandle
Definition utils.h:399