/// <summary> /// Initialize GlobalMemoryRegion. /// </summary> /// <param name="globalMemoryRegion"></param> /// <returns></returns> public static GlobalMemoryRegion InitializeMemoryRegion(this GlobalMemoryRegion globalMemoryRegion) { // Initialize properties. // globalMemoryRegion.GlobalMemoryRegionIndex = 1; globalMemoryRegion.RegisteredSettingsAssemblyCount.Store(1); MemoryRegion memoryHeader = globalMemoryRegion.MemoryHeader; MemoryRegionId memoryRegionId = memoryHeader.MemoryRegionId; memoryRegionId.Type = MemoryRegionType.Global; SharedConfigDictionary sharedConfigDictionary = globalMemoryRegion.SharedConfigDictionary; ArenaAllocator allocator = sharedConfigDictionary.Allocator; // Initialize memory allocator. // allocator.InitializeArenaAllocator(memoryHeader, (int)globalMemoryRegion.CodegenTypeSize()); // Initialize shared config dictionary. // sharedConfigDictionary.InitializeSharedConfigDictionary(); return(globalMemoryRegion); }
/// <summary> /// Creates InterProcessMlosContext. /// </summary> /// <returns></returns> public static AnonymousMemoryMlosContext Create() { var fdExchangeServer = new FileDescriptorExchangeServer(FdUnitDomainSocketName, FdExchangeSemaphoreName); fdExchangeServer.HandleRequests(); MemoryRegionId memoryRegionId = new MemoryRegionId { Type = MemoryRegionType.Global }; SharedMemoryRegionView <MlosProxyInternal.GlobalMemoryRegion> globalMemoryRegionView = SharedMemoryRegionView.OpenAnonymousFromFileDescriptor <MlosProxyInternal.GlobalMemoryRegion>( fdExchangeServer.GetSharedMemoryFd(memoryRegionId), fdExchangeServer.GetSharedMemorySize(memoryRegionId)); memoryRegionId = new MemoryRegionId { Type = MemoryRegionType.ControlChannel }; SharedMemoryMapView controlChannelMemoryMapView = SharedMemoryMapView.OpenAnonymousFromFileDescriptor( fdExchangeServer.GetSharedMemoryFd(memoryRegionId), fdExchangeServer.GetSharedMemorySize(memoryRegionId)); memoryRegionId = new MemoryRegionId { Type = MemoryRegionType.FeedbackChannel }; SharedMemoryMapView feedbackChannelMemoryMapView = SharedMemoryMapView.OpenAnonymousFromFileDescriptor( fdExchangeServer.GetSharedMemoryFd(memoryRegionId), fdExchangeServer.GetSharedMemorySize(memoryRegionId)); memoryRegionId = new MemoryRegionId { Type = MemoryRegionType.SharedConfig }; SharedMemoryRegionView <MlosProxyInternal.SharedConfigMemoryRegion> sharedConfigMemoryRegionView = SharedMemoryRegionView.OpenAnonymousFromFileDescriptor <MlosProxyInternal.SharedConfigMemoryRegion>( fdExchangeServer.GetSharedMemoryFd(memoryRegionId), fdExchangeServer.GetSharedMemorySize(memoryRegionId)); // Create channel synchronization primitives. // NamedEvent controlChannelNamedEvent = NamedEvent.CreateOrOpen(ControlChannelSemaphoreName); NamedEvent feedbackChannelNamedEvent = NamedEvent.CreateOrOpen(FeedbackChannelSemaphoreName); return(new AnonymousMemoryMlosContext( globalMemoryRegionView, controlChannelMemoryMapView, feedbackChannelMemoryMapView, sharedConfigMemoryRegionView, controlChannelNamedEvent, feedbackChannelNamedEvent, fdExchangeServer)); }
/// <summary> /// Initialize SharedConfigMemoryRegion. /// </summary> /// <param name="sharedConfigMemoryRegion"></param> /// <returns></returns> public static SharedConfigMemoryRegion InitializeMemoryRegion(this SharedConfigMemoryRegion sharedConfigMemoryRegion) { SharedConfigDictionary sharedConfigDictionary = sharedConfigMemoryRegion.SharedConfigDictionary; ArenaAllocator allocator = sharedConfigDictionary.Allocator; MemoryRegion memoryHeader = sharedConfigMemoryRegion.MemoryHeader; MemoryRegionId memoryRegionId = memoryHeader.MemoryRegionId; memoryRegionId.Type = MemoryRegionType.SharedConfig; // Initialize memory allocator. // allocator.InitializeArenaAllocator(sharedConfigMemoryRegion.MemoryHeader, (int)sharedConfigMemoryRegion.CodegenTypeSize()); // Initialize shared config dictionary. // sharedConfigDictionary.InitializeSharedConfigDictionary(); return(sharedConfigMemoryRegion); }
/// <summary> /// Returns memory region size for given memory region id. /// </summary> /// <param name="memoryRegionId"></param> /// <returns></returns> public ulong GetSharedMemorySize(MemoryRegionId memoryRegionId) { return(fileDescriptors[memoryRegionId].SharedMemorySize); }
/// <summary> /// Returns file descriptor for given memory region id. /// </summary> /// <param name="memoryRegionId"></param> /// <returns></returns> public IntPtr GetSharedMemoryFd(MemoryRegionId memoryRegionId) { return(fileDescriptors[memoryRegionId].SharedMemoryFd); }