using System; using System.Collections.Generic; using System.Text; using ProcessHacker.Native.Api; using ProcessHacker.Native.Objects; using ProcessHacker.Native.Security; namespace ProcessHacker.Native.Threading { /// /// Represents a mutant which can be used to synchronize access to a shared resource. /// public class Mutant : NativeObject { /// /// Creates a mutant. /// public Mutant() : this(null) { } /// /// Creates a mutant. /// /// /// Whether the mutant should become owned by the current /// thread when it is created. /// public Mutant(bool owned) : this(null, owned) { } /// /// Creates or opens a mutant. /// /// /// The name of the new mutant, or the name of an existing mutant to open. /// public Mutant(string name) : this(name, false) { } /// /// Creates a mutant. /// /// /// The name of the new mutant. /// /// /// Whether the mutant should become owned by the current /// thread when it is created. /// public Mutant(string name, bool owned) { this.Handle = MutantHandle.Create( MutantAccess.All, name, ObjectFlags.OpenIf, null, owned ); } /// /// Gets whether the mutant is currently owned. /// public bool Owned { get { return this.Handle.GetBasicInformation().CurrentCount > 0; } } /// /// Releases the mutant, allowing other waiting threads to own it. /// public void Release() { this.Handle.Release(); } } }