public unsafe void Start() { lock (stateLock) { if (!Enabled) { sigEvent = new SigEvent { notify = SigEv.Thread, thread = new SigEvThread { function = Marshal.GetFunctionPointerForDelegate(callbackDelegate), attribute = IntPtr.Zero }, value = new SigVal() }; var createErr = TimerCreate(ClockID.Monotonic, ref sigEvent, out timerID); if (createErr != ERRNO.NONE) { Log.Write("LinuxTimer", $"Failed creating timer: {(ERRNO)Marshal.GetLastWin32Error()}", LogLevel.Error); } double interval = Interval * 1000 * 1000; timeSpec = new TimerSpec { interval = new TimeSpec { sec = 0, nsec = (long)interval }, value = new TimeSpec { sec = 0, nsec = 100 } }; var oldTimeSpec = new TimerSpec(); var setErr = TimerSetTime(timerID, TimerFlag.Default, ref timeSpec, ref oldTimeSpec); if (setErr != ERRNO.NONE) { Log.Write("LinuxTimer", $"Failed activating the timer: ${(ERRNO)Marshal.GetLastWin32Error()}", LogLevel.Error); } Enabled = true; } } }
public static extern ERRNO TimerCreate(ClockID clockID, ref SigEvent eventPtr, out IntPtr timerID);