public void DropTable(string location) { if (string.IsNullOrWhiteSpace(location)) { throw new ArgumentNullException(nameof(location)); } // https://issues.apache.org/jira/browse/CASSANDRA-10699 // https://issues.apache.org/jira/browse/CASSANDRA-11429 if (@lock.Lock(location, lockTtl)) { try { var statement = CreatePreparedStatements.GetOrAdd(location, x => BuildDropPreparedStatemnt(x)); statement.SetConsistencyLevel(ConsistencyLevel.All); sessionForSchemaChanges.Execute(statement.Bind()); } finally { @lock.Unlock(location); } } else { log.Warn($"[Projections] Could not acquire lock for `{location}` to drop snapshots table"); } }
override public void Execute(Action executeFunction) { try { m_lock.Lock(); executeFunction(); } finally { m_lock.Release(); } }
public virtual void TestLock() { l.Lock(); var latch = new CountdownEvent(1); Task.Factory.StartNew(() => { if (!l.TryLock()) { latch.Signal(); } }); Assert.IsTrue(latch.Wait(TimeSpan.FromSeconds(5))); l.ForceUnlock(); }
/// <summary> /// <inheritDoc/> /// /// </summary> public override void Run() { try { while (doRun) { // Wait for a request IBiConsumer <StanfordCoreNLPClient.Backend, IConsumer <StanfordCoreNLPClient.Backend> > request; StanfordCoreNLPClient.Backend annotator; stateLock.Lock(); try { while (queue.IsEmpty()) { enqueued.Await(); if (!doRun) { return; } } // Get the actual request request = queue.Poll(); // We have a request // Find a free annotator while (freeAnnotators.IsEmpty()) { newlyFree.Await(); } annotator = freeAnnotators.Poll(); } finally { stateLock.Unlock(); } // We have an annotator // Run the annotation request.Accept(annotator, null); } } catch (Exception e) { // ASYNC: we've freed this annotator // add it back to the queue and register it as available // If the queue is empty, and all the annotators have returned, we're done // Annotator is running (in parallel, most likely) throw new Exception(e); } }
private static long CheckMutualExclusion(ILock @lock, int count, int cyclesCount) { var buckets = new long[count]; var finished = new bool[count]; var total = 0L; ThreadId.ZeroOut(); var threads = Enumerable.Range(0, count).Select(i => { return(new Thread(() => { for (var j = 0; j < cyclesCount; j++) { @lock.Lock(); buckets[i]++; total++; @lock.Unlock(); } finished[i] = true; })); }); foreach (var thread in threads) { thread.Start(); } while (finished.Any(f => !f)) { } return(total); }
void CreateTable(string cqlQuery, string tableName) { if (@lock.Lock(tableName, lockTtl)) { try { log.Debug(() => $"[EventStore] Creating table `{tableName}` with `{session.Cluster.AllHosts().First().Address}` in keyspace `{session.Keyspace}`..."); var createEventsTable = string.Format(cqlQuery, tableName).ToLower(); session.Execute(createEventsTable); log.Debug(() => $"[EventStore] Created table `{tableName}` in keyspace `{session.Keyspace}`..."); } catch (Exception) { throw; } finally { @lock.Unlock(tableName); } } else { log.Warn($"[EventStore] Could not acquire lock for `{tableName}` to create table."); } }
//runs program in count mode public void CountMode(object id) { int i = intervals[(int)id]; int j = intervals[(int)id + 1]; while (i < j) { if (MTest(i)) { locker.Lock(); counter++; locker.Unlock(); } i++; } }
public LockingEnumerator(IEnumerator <T> enumerator, ILock @lock) { _enumerator = enumerator; _lock = @lock; _lock.Lock(); }
public void Lock([NotNull] ILock locker) => Locker.RunLocking(() => { counter += 1; if (counter == 1) { locker.Lock(); } });
public void DropTable(string location) { if (@lock.Lock(location, lockTtl)) { try { var statement = CreatePreparedStatements.GetOrAdd(location, x => BuildDropPreparedStatemnt(x)); statement.SetConsistencyLevel(ConsistencyLevel.All); sessionForSchemaChanges.Execute(statement.Bind()); } finally { @lock.Unlock(location); } } else { log.Debug($"[Projections] Could not acquire lock for `{location}` to drop projections table"); } }
private void beginTransaction(SQLiteDatabase mDatabase) { if (allowTransaction) { mDatabase.BeginTransaction(); } else { writeLock.Lock(); writeLocked = true; } }
/// <summary> /// Executes provided action as critical section, acquiring the specified lock, executing a statement, and then /// releasing the lock. /// </summary> /// <param name="lock">Synchronization object to use.</param> /// <param name="action">Action to execute.</param> public static void Synchronized(this ILock @lock, Action action) { @lock.Lock(); try { action(); } finally { @lock.Release(); } }
public void Run() { myLock.Lock(); lockStarted = true; while (!canAwake) { c.AwaitUninterruptibly(); } interrupted = InternalThread.IsAlive; myLock.Unlock(); }
/// <summary> /// Executes provided function as critical section, acquiring the specified lock, executing a statement, and then /// releasing the lock. /// </summary> /// <param name="lock">Synchronization object to use.</param> /// <param name="func">Function to execute.</param> public static T Synchronized <T>(this ILock @lock, Func <T> func) { @lock.Lock(); try { return(func()); } finally { @lock.Release(); } }
public virtual WeakRunnable remove() { @lock.Lock(); try { if (prev != null) { prev.next = next; } if (next != null) { next.prev = prev; } prev = null; next = null; } finally { @lock.Unlock(); } return(wrapper); }
/// <summary> /// This method adds an item to the queue. /// </summary> /// <param name="item"> /// The item to push into the queue. /// </param> public void Enqueue(T item) { _lock.Lock(); try { _queue.Enqueue(item); _notEmpty.Signal(); } finally { _lock.Unlock(); } }
public virtual void TestForceUnlock() { l.Lock(); var latch = new CountdownEvent(1); var t2 = new Thread(delegate(object o) { try { l.ForceUnlock(); latch.Signal(); } catch { } }); t2.Start(); Assert.IsTrue(latch.Wait(TimeSpan.FromSeconds(100))); Assert.IsFalse(l.IsLocked()); }
/// <summary> /// Returns the GrammaticalRelation having the given string /// representation (e.g. /// </summary> /// <remarks> /// Returns the GrammaticalRelation having the given string /// representation (e.g. "nsubj"), or null if no such is found. /// </remarks> /// <param name="s">The short name of the GrammaticalRelation</param> /// <param name="values">The set of GrammaticalRelations to look for it among.</param> /// <returns>The GrammaticalRelation with that name</returns> public static Edu.Stanford.Nlp.Trees.GrammaticalRelation ValueOf(string s, ICollection <Edu.Stanford.Nlp.Trees.GrammaticalRelation> values, ILock readValuesLock) { readValuesLock.Lock(); try { foreach (Edu.Stanford.Nlp.Trees.GrammaticalRelation reln in values) { if (reln.ToString().Equals(s)) { return(reln); } } } finally { readValuesLock.Unlock(); } return(null); }
protected override bool InitValue(TArg arg, out TValue value) { _lock.Lock(); try { if (null != _value) { value = _value.Value; return(false); } var v = Initializer(arg); _value = ValueBox.Create(v); value = v; return(true); } finally { _lock.Release(); } }
public void OnClose() { _clientLock.Lock(); try { if (!_isClosed) { _isClosed = true; if (_isTerminating) { _aeron.InternalClose(); } ForceCloseResources(); for (int i = _closeHandlers.Count - 1; i >= 0; i--) { try { _closeHandlers[i].Invoke(); } catch (Exception ex) { HandleError(ex); } } try { if (_isTerminating) { Thread.Sleep(Aeron.Configuration.IdleSleepMs); } Thread.Sleep(_closeLingerDurationMs); } catch (ThreadInterruptedException) { Thread.CurrentThread.Interrupt(); } for (int i = 0, size = _lingeringResources.Count; i < size; i++) { _lingeringResources[i].Delete(); } _driverProxy.ClientClose(); _ctx.Dispose(); } } finally { _clientLock.Unlock(); } }
public void OnClose() { bool isInterrupted = false; _clientLock.Lock(); try { if (!_isClosed) { if (!_aeron.IsClosed) { _aeron.InternalClose(); } ForceCloseResources(); NotifyCloseHandlers(); try { if (_isTerminating) { Thread.Sleep(Aeron.Configuration.IdleSleepMs); } Thread.Sleep((int)TimeUnit.NANOSECONDS.toMillis(_ctx.CloseLingerDurationNs())); } catch (ThreadInterruptedException) { isInterrupted = true; } for (int i = 0, size = _lingeringLogBuffers.Count; i < size; i++) { CloseHelper.Dispose(_ctx.ErrorHandler(), _lingeringLogBuffers[i]); } _driverProxy.ClientClose(); _ctx.Dispose(); } } finally { _isClosed = true; if (isInterrupted) { Thread.CurrentThread.Interrupt(); } _clientLock.Unlock(); } }
internal void Lock() { ReentrantLock.Lock(); }
public void ExtLock() { m_lock.Lock(); }
public void OnClose() { _clientLock.Lock(); try { if (!_isClosed) { _isClosed = true; int lingeringResourcesSize = _lingeringResources.Count; ForceCloseResources(); _driverProxy.ClientClose(); if (_lingeringResources.Count > lingeringResourcesSize) { Aeron.Sleep(1); } for (int i = 0, size = _lingeringResources.Count; i < size; i++) { _lingeringResources[i].Delete(); } } } finally { _clientLock.Unlock(); } }
public void OnClose() { _clientLock.Lock(); try { if (!_isClosed) { _isClosed = true; ForceCloseResources(); Thread.Yield(); for (int i = 0, size = _lingeringResources.Count; i < size; i++) { _lingeringResources[i].Delete(); } _driverProxy.ClientClose(); _ctx.Dispose(); } } finally { _clientLock.Unlock(); } }