Branch: Tag:

2017-11-28

2017-11-28 12:11:46 by Stephen R. van den Berg <srb@cuci.nl>

Concurrent: Reduce lock contention and cleanup superfluous catches.

The interpreter lock will protect trivial cases.
The natural destruction at the end of a block takes care of some
unlocks.

72:       s = state;    res = result; -  key = 0; +     }       if (s == STATE_REJECTED) {
98:    //! @[on_failure()]    this_program on_success(function(mixed, mixed ... : void) cb, mixed ... extra)    { -  Thread.MutexKey key = mux->lock(); -  -  if (state == STATE_FULFILLED) { -  key = 0; +  switch (state) { +  case STATE_FULFILLED:    callout(cb, 0, result, @extra); -  } else { +  break; +  case STATE_PENDING: +  // Rely on interpreter lock to add to success_cbs before state changes +  // again    success_cbs += ({ ({ cb, @extra }) }); -  key = 0; +     } -  +     return this_program::this;    }   
128:    //! @[on_success()]    this_program on_failure(function(mixed, mixed ... : void) cb, mixed ... extra)    { -  Thread.MutexKey key = mux->lock(); -  -  if (state == STATE_REJECTED) { -  key = 0; +  switch (state) { +  case STATE_REJECTED:    callout(cb, 0, result, @extra); -  } else { +  break; +  case STATE_PENDING: +  // Rely on interpreter lock to add to failure_cbs before state changes +  // again    failure_cbs += ({ ({ cb, @extra }) }); -  key = 0; +     } -  +     return this_program::this;    }   
479:       final void materialise()    { -  Thread.MutexKey key = mux->lock(); +     if (promise->_astate)    {    promise->_astate = 0; -  key = 0; +     if (results)    {    promises = sizeof(results);
497:    }    }    } -  key = 0; +     }       private void fold_one(mixed val)
542:    break;    }    } -  else -  key = 0; +     return;    } while (0);    promise = 0; // Free backreference
579:    break;    }    } -  else -  key = 0; +     return;    } while (0);    promise = 0; // Free backreference
620:    Future on_success(function(mixed, mixed ... : void) cb, mixed ... extra)    {    if (_astate) -  catch(_astate->materialise()); // catches race for _astate == 0 +  _astate->materialise();    return ::on_success(cb, @extra);    }       Future on_failure(function(mixed, mixed ... : void) cb, mixed ... extra)    {    if (_astate) -  catch(_astate->materialise()); // catches race for _astate == 0 +  _astate->materialise();    return ::on_failure(cb, @extra);    }       mixed get()    {    if (_astate) -  catch(_astate->materialise()); // catches race for _astate == 0 +  _astate->materialise();    return ::get();    }