private void InitializePoll(ProcessorPin pin)
        {
            lock (polls)
            {
                PinPoll poll;
                if (polls.TryGetValue(pin, out poll))
                {
                    return;
                }

                var pinPoll = new PinPoll();

                pinPoll.PollDescriptor = Interop.epoll_create(1);
                if (pinPoll.PollDescriptor < 0)
                {
                    throw new IOException("Call to epoll_create(1) API failed with the following return value: " + pinPoll.PollDescriptor);
                }

                var valuePath = Path.Combine(gpioPath, string.Format("gpio{0}/value", (int)pin));

                pinPoll.FileDescriptor = UnixFile.OpenFileDescriptor(valuePath, UnixFileMode.ReadOnly | UnixFileMode.NonBlocking);

                var ev = new Interop.epoll_event
                {
                    events = (Interop.EPOLLIN | Interop.EPOLLET | Interop.EPOLLPRI),
                    data   = new Interop.epoll_data {
                        fd = pinPoll.FileDescriptor
                    }
                };

                pinPoll.InEventPtr = Marshal.AllocHGlobal(64);
                Marshal.StructureToPtr(ev, pinPoll.InEventPtr, false);

                var controlResult = Interop.epoll_ctl(pinPoll.PollDescriptor, Interop.EPOLL_CTL_ADD, pinPoll.FileDescriptor, pinPoll.InEventPtr);
                if (controlResult != 0)
                {
                    throw new IOException("Call to epoll_ctl(EPOLL_CTL_ADD) API failed with the following return value: " + controlResult);
                }

                pinPoll.OutEventPtr = Marshal.AllocHGlobal(64);
                polls[pin]          = pinPoll;
            }
        }
        private void InitializePoll(ProcessorPin pin)
        {
            lock (pinPolls)
            {
                PinPoll poll;
                if (pinPolls.TryGetValue(pin, out poll))
                    return;

                var pinPoll = new PinPoll();

                pinPoll.PollDescriptor = Interop.epoll_create(1);
                if (pinPoll.PollDescriptor < 0)
                    throw new IOException("Call to epoll_create(1) API failed with the following return value: " + pinPoll.PollDescriptor);

                var valuePath = Path.Combine(gpioPath, string.Format("gpio{0}/value", (int)pin));

                pinPoll.FileDescriptor = UnixFile.OpenFileDescriptor(valuePath, UnixFileMode.ReadOnly | UnixFileMode.NonBlocking);

                var ev = new Interop.epoll_event
                {
                    events = (Interop.EPOLLIN | Interop.EPOLLET | Interop.EPOLLPRI),
                    data = new Interop.epoll_data { fd = pinPoll.FileDescriptor }
                };

                pinPoll.InEventPtr = Marshal.AllocHGlobal(64);
                Marshal.StructureToPtr(ev, pinPoll.InEventPtr, false);

                var controlResult = Interop.epoll_ctl(pinPoll.PollDescriptor, Interop.EPOLL_CTL_ADD, pinPoll.FileDescriptor, pinPoll.InEventPtr);
                if (controlResult != 0)
                    throw new IOException("Call to epoll_ctl(EPOLL_CTL_ADD) API failed with the following return value: " + controlResult);

                pinPoll.OutEventPtr = Marshal.AllocHGlobal(64);
                pinPolls[pin] = pinPoll;
            }
        }