12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Runtime.InteropServices;
- namespace Haukcode.HighResolutionTimer
- {
- // Disable these StyleCop rules for this file, as we are using native names here.
- #pragma warning disable SA1300 // Element should begin with upper-case letter
- internal partial class Interop
- {
- private const string LibcLibrary = "libc";
- public enum ClockIds : int
- {
- CLOCK_REALTIME = 0,
- CLOCK_MONOTONIC = 1,
- CLOCK_PROCESS_CPUTIME_ID = 2,
- CLOCK_THREAD_CPUTIME_ID = 3,
- CLOCK_MONOTONIC_RAW = 4,
- CLOCK_REALTIME_COARSE = 5,
- CLOCK_MONOTONIC_COARSE = 6,
- CLOCK_BOOTTIME = 7,
- CLOCK_REALTIME_ALARM = 8,
- CLOCK_BOOTTIME_ALARM = 9
- }
- [StructLayout(LayoutKind.Explicit)]
- public class Timespec
- {
- [FieldOffset(0)]
- public uint tv_sec; /* seconds */
- [FieldOffset(4)]
- public uint tv_nsec; /* nanoseconds */
- };
- [StructLayout(LayoutKind.Explicit)]
- public class Itimerspec
- {
- [FieldOffset(0)]
- public Timespec it_interval= new Timespec(); /* timer period */
- [FieldOffset(8)]
- public Timespec it_value=new Timespec(); /* timer expiration */
- };
- [DllImport(LibcLibrary, SetLastError = true,EntryPoint = "timerfd_create")]
- internal static extern int Timerfd_Create(ClockIds clockId, int flags);
- [DllImport(LibcLibrary, SetLastError = true,EntryPoint = "timerfd_settime")]
- internal static extern int Timerfd_Settime(int fd, int flags, Itimerspec new_value, Itimerspec old_value);
- [DllImport(LibcLibrary, SetLastError = true,EntryPoint ="read")]
- internal static extern int Read(int fd, IntPtr buf, int count);
- [DllImport(LibcLibrary,EntryPoint ="close")]
- internal static extern int Close(int fd);
- }
- }
|