Rework the Future::Core state machine
Summary:
There was a race reading `callback_` in `maybeCallback` and setting `callback_` in `setCallback`. This diff reworks the state machine to make this unpossible. To avoid the explosion of states due to the cross-product of has-interrupt-handler/has-been-interrupted/etc. I introduce a separate lock for setting interrupt handler and interruption, since this is primarily orthogonal. Other attributes (active, for example) are still atomic variables, and while somewhat tied into the state machine logically (e.g. transitioning from Armed to Done only happens when active) they are mostly independent, keeping the state machine simple (and probably faster).
I think it may even be possible to do some things cheaper. In some states, we may not need to protect the writing of `callback_` and `result_`. But we'd need to enforce some ordering so I'm not going to try to tackle that. But that could be some speedup if we can do it cheaply.
Test Plan:
Builds and all existing tests pass.
Reviewed By: rockyliu4@fb.com
Subscribers: yfeldblum, stepan, trunkagent, exa, folly-diffs@, jsedgwick
FB internal diff:
D1807854
Tasks:
6087856
Signature: t1:
1807854:
1422656713:
25b62706cd7952b2dde06dab08074f8030db456b