UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IPC.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*==============================================================================
4 IPC.h: Public interface for inteprocess communication module
5==============================================================================*/
6
7#pragma once
8
9#include "CoreMinimal.h"
10#include "HAL/PlatformProcess.h"
11
12namespace IPC
13{
18 {
21
24
29 : Mutex(InMutex)
31 {
32 check(Mutex);
34 }
35
36 public:
37
55
82
105
114 bool Write(const FString& String, uint32 MaxMillisecondsToWait = 0)
115 {
116 check(Mutex);
117 check(Memory);
118
119 // acquire
121 {
122 Mutex->Lock();
123 }
124 else
125 {
126 if (!Mutex->TryLock(MaxMillisecondsToWait * 1000000ULL)) // 1ms = 10^6 ns
127 {
128 return false;
129 }
130 }
131
132 // we have exclusive ownership now!
133 TCHAR* RawMemory = reinterpret_cast< TCHAR* >(Memory->GetAddress() );
134 FCString::Strncpy(RawMemory, *String, Memory->GetSize());
135
136 // relinquish
137 Mutex->Unlock();
138
139 return true;
140 }
141
150 bool Read(FString& OutString, uint32 MaxMillisecondsToWait = 0)
151 {
152 check(Mutex);
153 check(Memory);
154
155 // acquire
157 {
158 Mutex->Lock();
159 }
160 else
161 {
162 if (!Mutex->TryLock(MaxMillisecondsToWait * 1000000ULL)) // 1ms = 10^6 ns
163 {
164 return false;
165 }
166 }
167
168 // we have exclusive ownership now!
169 const TCHAR* RawMemory = reinterpret_cast< const TCHAR* >( Memory->GetAddress() );
170 OutString = FString(RawMemory);
171
172 // relinquish
173 Mutex->Unlock();
174
175 return true;
176 }
177 };
178}; // namespace IPC
#define NULL
Definition oodle2base.h:134
#define check(expr)
Definition AssertionMacros.h:314
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
static FSynchronizedInterprocessMemory * Create(const TCHAR *Name, SIZE_T Size)
Definition IPC.h:59
bool Read(FString &OutString, uint32 MaxMillisecondsToWait=0)
Definition IPC.h:150
static FSynchronizedInterprocessMemory * OpenExisting(const TCHAR *Name, SIZE_T Size)
Definition IPC.h:86
bool Write(const FString &String, uint32 MaxMillisecondsToWait=0)
Definition IPC.h:114
~FSynchronizedInterprocessMemory()
Definition IPC.h:41
UE_API void Lock()
Definition RecursiveMutex.cpp:40
UE_API bool TryLock()
Definition RecursiveMutex.cpp:13
UE_API void Unlock()
Definition RecursiveMutex.cpp:115
Definition IPC.h:13
Definition GenericPlatformMemory.h:293
static CORE_API FSharedMemoryRegion * MapNamedSharedMemoryRegion(const FString &Name, bool bCreate, uint32 AccessMode, SIZE_T Size)
Definition GenericPlatformMemory.cpp:545
static CORE_API bool UnmapNamedSharedMemoryRegion(FSharedMemoryRegion *MemoryRegion)
Definition GenericPlatformMemory.cpp:551
@ Read
Definition GenericPlatformMemory.h:285
@ Write
Definition GenericPlatformMemory.h:286
Definition GenericPlatformProcess.h:254
static CORE_API FSemaphore * NewInterprocessSynchObject(const FString &Name, bool bCreate, uint32 MaxLocks=1)
Definition GenericPlatformProcess.cpp:684
static CORE_API bool DeleteInterprocessSynchObject(FSemaphore *Object)
Definition GenericPlatformProcess.cpp:695
static UE_FORCEINLINE_HINT void * Memzero(void *Dest, SIZE_T Count)
Definition UnrealMemory.h:131
static CharType * Strncpy(CharType *Dest, const CharType *Src, SIZE_T MaxLen)
Definition CString.h:991