コード例 #1
0
        public static PosixSemaphore Open(string name)
        {
            IntPtr semPtr = sem_open(name, (int)OpenFlags.O_CREAT, //TODO: fix OFlag
                                     (uint)(FilePermissions.S_IRUSR | FilePermissions.S_IWUSR), 0);

            if (semPtr == IntPtr.Zero)
            {
                throw new Exception($"Open PosixSemaphore failed. error = {Marshal.GetLastWin32Error()}");
            }

            var ps = new PosixSemaphore();

            ps.name = name;
            ps.sem  = semPtr;
            ps.own  = false;
            return(ps);
        }
コード例 #2
0
        /// <summary>
        /// Attempts to create the <see cref="EventWaitHandle"/> handles and initialise the node header and buffers.
        /// </summary>
        /// <returns>True if the events and nodes were initialised successfully.</returns>
        protected override bool DoOpen()
        {
            // Create signal events
#if Linux
            if (IsOwnerOfSharedMemory)
            {
                DataExists    = PosixSemaphore.Create(Name + "_evt_dataexists");
                NodeAvailable = PosixSemaphore.Create(Name + "_evt_nodeavail");
            }
            else
            {
                DataExists    = PosixSemaphore.Open(Name + "_evt_dataexists");
                NodeAvailable = PosixSemaphore.Open(Name + "_evt_nodeavail");
            }
#else
            DataExists    = new EventWaitHandle(false, EventResetMode.AutoReset, Name + "_evt_dataexists");
            NodeAvailable = new EventWaitHandle(false, EventResetMode.AutoReset, Name + "_evt_nodeavail");
#endif

            if (IsOwnerOfSharedMemory)
            {
                // Retrieve pointer to node header
                _nodeHeader = (NodeHeader *)(BufferStartPtr + NodeHeaderOffset);

                // Initialise the node header
                InitialiseNodeHeader();

                // Initialise nodes entries
                InitialiseLinkedListNodes();
            }
            else
            {
                // Load the NodeHeader
                _nodeHeader    = (NodeHeader *)(BufferStartPtr + NodeHeaderOffset);
                NodeCount      = _nodeHeader->NodeCount;
                NodeBufferSize = _nodeHeader->NodeBufferSize;
            }

            return(true);
        }