/// <summary> /// Add an alias for a namespace. /// </summary> /// <param name="alias">The alias for the namespace.</param> /// <param name="ns">The namespace being aliased.</param> /// <remarks>Lowercase name for core.clj compatibility</remarks> public void addAlias(Symbol alias, Namespace ns) { if (alias == null || ns == null) { throw new NullReferenceException("Expecting Symbol + Namespace"); } IPersistentMap map = Aliases; // race condition while (!map.containsKey(alias)) { IPersistentMap newMap = map.assoc(alias, ns); _aliases.CompareAndSet(map, newMap); map = Aliases; } // you can rebind an alias, but only to the initially-aliased namespace if (!map.valAt(alias).Equals(ns)) { throw new InvalidOperationException(String.Format("Alias {0} already exists in namespace {1}, aliasing {2}", alias, _name, map.valAt(alias))); } }
/// <summary> /// Enqueue an action in the pending queue. /// </summary> /// <param name="action">The action to enqueue.</param> /// <remarks>Spin-locks to update the queue.</remarks> void Enqueue(Action action) { bool queued = false; IPersistentStack prior = null; while (!queued) { prior = _q.Get(); queued = _q.CompareAndSet(prior, (IPersistentStack)prior.cons(action)); } if (prior.count() == 0) { action.execute(); } }