/** Swap the value held at key, and return the old value * @param key the key to change the value of * @param new_value the new value to set to * @param cb the delegate to call at completion */ override public IAsyncResult BeginSwap(MemBlock key, MemBlock new_value, AsyncCallback cb, object state) { MemBlock old_v = null; lock ( _sync ) { old_v = _ht[key] as MemBlock; _ht[key] = new_value; } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return(r); }
/** Begin a Read of a Key * @param key the key to read * @param result_cb the delegate to call when the read completes */ override public IAsyncResult BeginRead(MemBlock key, AsyncCallback cb, object state) { MemBlock old_v = null; lock ( _sync ) { //We have to hold the lock to be consistent with CompareSwap and Swap old_v = _ht[key] as MemBlock; } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return(r); }
/** Begin a Compare-and-Swap operation * @param key the key to change * @param new_value the value to replace if the old value is given * @param old_value the value we are checking for (may be null) * @param cb the delegate to call on completion * Note the swap succeeds if and only if the return value * of EndCompareSwap == old_value */ override public IAsyncResult BeginCompareSwap(MemBlock key, MemBlock new_value, MemBlock old_value, AsyncCallback cb, object state) { MemBlock old_v = null; lock ( _sync ) { old_v = _ht[key] as MemBlock; if ((old_v == null) && (old_value == null)) { //Looks good: _ht[key] = new_value; } else if (old_v.Equals(old_value)) { //Use Equals method to check for equality _ht[key] = new_value; } } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return(r); }
/** Swap the value held at key, and return the old value * @param key the key to change the value of * @param new_value the new value to set to * @param cb the delegate to call at completion */ override public IAsyncResult BeginSwap(MemBlock key, MemBlock new_value, AsyncCallback cb, object state) { MemBlock old_v = null; lock( _sync ) { old_v = _ht[key] as MemBlock; _ht[key] = new_value; } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return r; }
/** Begin a Read of a Key * @param key the key to read * @param result_cb the delegate to call when the read completes */ override public IAsyncResult BeginRead(MemBlock key, AsyncCallback cb, object state) { MemBlock old_v = null; lock( _sync ) { //We have to hold the lock to be consistent with CompareSwap and Swap old_v = _ht[key] as MemBlock; } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return r; }
/** Begin a Compare-and-Swap operation * @param key the key to change * @param new_value the value to replace if the old value is given * @param old_value the value we are checking for (may be null) * @param cb the delegate to call on completion * Note the swap succeeds if and only if the return value * of EndCompareSwap == old_value */ override public IAsyncResult BeginCompareSwap(MemBlock key, MemBlock new_value, MemBlock old_value, AsyncCallback cb, object state) { MemBlock old_v = null; lock( _sync ) { old_v = _ht[key] as MemBlock; if ( (old_v == null) && (old_value == null)) { //Looks good: _ht[key] = new_value; } else if( old_v.Equals(old_value) ) { //Use Equals method to check for equality _ht[key] = new_value; } } IAsyncResult r = new LhtAsResult(state, old_v); cb(r); return r; }
/** End a Swap * @return the old value held by the key */ override public MemBlock EndSwap(IAsyncResult r) { LhtAsResult res = (LhtAsResult)r; return(res.Result); }