示例#1
0
        /// <summary>
        /// Tries to open a shared memory map.
        /// </summary>
        /// <param name="globalMemoryRegion"></param>
        /// <param name="memoryRegionId"></param>
        /// <param name="sharedMemoryMapView"></param>
        /// <returns></returns>
        public static bool TryOpenExisting(
            this GlobalMemoryRegion globalMemoryRegion,
            MlosInternal.MemoryRegionId memoryRegionId,
            out SharedMemoryMapView sharedMemoryMapView)
        {
            MlosInternal.RegisteredMemoryRegionConfig.CodegenKey registeredMemoryLookupKey = default;
            registeredMemoryLookupKey.MemoryRegionId = memoryRegionId;

            // Locate shared memory region config.
            //
            SharedConfig <MlosProxyInternal.RegisteredMemoryRegionConfig> registeredMemoryRegionSharedConfig =
                SharedConfigManager.Lookup(globalMemoryRegion.SharedConfigDictionary, registeredMemoryLookupKey);

            if (!registeredMemoryRegionSharedConfig.HasSharedConfig)
            {
                sharedMemoryMapView = null;
                return(false);
            }

            // Config exists, create a shared config memory region.
            //
            MlosProxyInternal.RegisteredMemoryRegionConfig registeredMemoryRegionConfig = registeredMemoryRegionSharedConfig.Config;

            sharedMemoryMapView = SharedMemoryMapView.OpenExisting(
                registeredMemoryRegionConfig.MemoryMapName.Value,
                registeredMemoryRegionConfig.MemoryRegionSize);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Tries to open a named event.
        /// </summary>
        /// <param name="globalMemoryRegion"></param>
        /// <param name="memoryRegionId"></param>
        /// <param name="namedEvent"></param>
        /// <returns></returns>
        public static bool TryOpenExisting(
            this GlobalMemoryRegion globalMemoryRegion,
            MlosInternal.MemoryRegionId memoryRegionId,
            out NamedEvent namedEvent)
        {
            MlosInternal.RegisteredNamedEventConfig.CodegenKey namedEventLookupKey = default;
            namedEventLookupKey.MemoryRegionId = memoryRegionId;

            // Locate named event config.
            //
            SharedConfig <MlosProxyInternal.RegisteredNamedEventConfig> registeredNamedEventSharedConfig =
                SharedConfigManager.Lookup(globalMemoryRegion.SharedConfigDictionary, namedEventLookupKey);

            if (!registeredNamedEventSharedConfig.HasSharedConfig)
            {
                namedEvent = null;
                return(false);
            }

            // Config exists, create a named event.
            //
            MlosProxyInternal.RegisteredNamedEventConfig registeredNamedEventConfig = registeredNamedEventSharedConfig.Config;

            namedEvent = NamedEvent.CreateOrOpen(registeredNamedEventConfig.EventName.Value);

            return(true);
        }
示例#3
0
        /// <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);
        }