public void Initialize_CreatedNew_ReturnsTrue() { using (var mutex = new GlobalMutex("test")) { mutex.Unlink(); Assert.That(mutex.Initialize(), Is.True); } }
public void InitializeAndLock_CreatedNew_ReturnsTrue() { using (var mutex = new GlobalMutex("test")) { mutex.Unlink(); bool createdNew; using (mutex.InitializeAndLock(out createdNew)) {} Assert.That(createdNew, Is.True); } }
protected override void ShutdownInternal() { if (m_commitLogMutex != null && m_commitLogMetadata != null) { CompleteAllCommits(); using (m_commitLogMutex.Lock()) { #if __MonoCS__ bool delete = false; #endif using (MemoryMappedViewStream stream = m_commitLogMetadata.CreateViewStream()) { CommitLogMetadata metadata; if (TryGetMetadata(stream, out metadata)) { if (metadata.Master == m_peerID) { // commit any unseen foreign changes List <ICmObjectSurrogate> foreignNewbies; List <ICmObjectSurrogate> foreignDirtballs; List <ICmObjectId> foreignGoners; if (GetUnseenForeignChanges(metadata, out foreignNewbies, out foreignDirtballs, out foreignGoners)) { var newObjects = new HashSet <ICmObjectOrSurrogate>(foreignNewbies); var editedObjects = new HashSet <ICmObjectOrSurrogate>(foreignDirtballs); var removedObjects = new HashSet <ICmObjectId>(foreignGoners); IEnumerable <CustomFieldInfo> fields; if (HaveAnythingToCommit(newObjects, editedObjects, removedObjects, out fields) && (StartupVersionNumber == ModelVersion)) { base.WriteCommitWork(new CommitWork(newObjects, editedObjects, removedObjects, fields)); } } // XML file is now totally up-to-date metadata.FileGeneration = metadata.CurrentGeneration; } RemovePeer(metadata, m_peerID); #if __MonoCS__ delete = metadata.Peers.Count == 0; #endif SaveMetadata(stream, metadata); } } base.UnlockProject(); m_commitLog.Dispose(); m_commitLog = null; m_commitLogMetadata.Dispose(); m_commitLogMetadata = null; #if __MonoCS__ if (delete) { File.Delete(Path.Combine(m_commitLogDir, CommitLogMetadataName)); File.Delete(Path.Combine(m_commitLogDir, CommitLogName)); m_commitLogMutex.Unlink(); } #endif } } if (m_commitLogMutex != null) { m_commitLogMutex.Dispose(); m_commitLogMutex = null; } if (CommitThread != null) { CommitThread.Stop(); CommitThread.Dispose(); CommitThread = null; } foreach (Process peerProcess in m_peerProcesses.Values) { peerProcess.Close(); } m_peerProcesses.Clear(); }