mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
b02427417c
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@5614 21ef857c-d57f-4fe0-8362-d861dc6d29cd
92 lines
2.9 KiB
C#
92 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using System.Security;
|
|
using System.Text;
|
|
|
|
namespace ProcessHacker.Common.Threading
|
|
{
|
|
[SuppressUnmanagedCodeSecurity]
|
|
internal class NativeMethods
|
|
{
|
|
public const int WaitObject0 = 0x0;
|
|
public const int WaitAbandoned = 0x80;
|
|
public const int WaitTimeout = 0x102;
|
|
public const int WaitFailed = -1;
|
|
|
|
public static readonly int SpinCount = Environment.ProcessorCount != 1 ? 4000 : 0;
|
|
public static readonly bool SpinEnabled = Environment.ProcessorCount != 1;
|
|
|
|
// We need to import some stuff. We can't use
|
|
// ProcessHacker.Native because it depends on this library.
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool CloseHandle(
|
|
[In] IntPtr Handle
|
|
);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
public static extern IntPtr CreateEvent(
|
|
[In] [Optional] IntPtr EventAttributes,
|
|
[In] bool ManualReset,
|
|
[In] bool InitialState,
|
|
[In] [Optional] string Name
|
|
);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
public static extern IntPtr CreateSemaphore(
|
|
[In] [Optional] IntPtr SemaphoreAttributes,
|
|
[In] int InitialCount,
|
|
[In] int MaximumCount,
|
|
[In] [Optional] string Name
|
|
);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool ReleaseSemaphore(
|
|
[In] IntPtr SemaphoreHandle,
|
|
[In] int ReleaseCount,
|
|
[In] IntPtr PreviousCount // out int
|
|
);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool ResetEvent(
|
|
[In] IntPtr EventHandle
|
|
);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool SetEvent(
|
|
[In] IntPtr EventHandle
|
|
);
|
|
|
|
[DllImport("kernel32.dll")]
|
|
public static extern int WaitForSingleObject(
|
|
[In] IntPtr Handle,
|
|
[In] int Milliseconds
|
|
);
|
|
|
|
[DllImport("ntdll.dll")]
|
|
public static extern int NtCreateKeyedEvent(
|
|
[Out] out IntPtr KeyedEventHandle,
|
|
[In] int DesiredAccess,
|
|
[In] [Optional] IntPtr ObjectAttributes,
|
|
[In] int Flags
|
|
);
|
|
|
|
[DllImport("ntdll.dll")]
|
|
public static extern int NtReleaseKeyedEvent(
|
|
[In] IntPtr KeyedEventHandle,
|
|
[In] IntPtr KeyValue,
|
|
[In] bool Alertable,
|
|
[In] [Optional] IntPtr Timeout
|
|
);
|
|
|
|
[DllImport("ntdll.dll")]
|
|
public static extern int NtWaitForKeyedEvent(
|
|
[In] IntPtr KeyedEventHandle,
|
|
[In] IntPtr KeyValue,
|
|
[In] bool Alertable,
|
|
[In] [Optional] IntPtr Timeout
|
|
);
|
|
}
|
|
}
|