Rework the Future::Core state machine
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

loversInJapan/folly,wildinto/folly,kernelim/folly,gavioto/folly,ykarlsbrun/folly,wildinto/folly,renyinew/folly,raphaelamorim/folly,tomhughes/folly,loverszhaokai/folly,SammyK/folly,doctaweeks/folly,wildinto/folly,sonnyhu/folly,reddit/folly,project-zerus/folly,brunomorishita/folly,raphaelamorim/folly,loverszhaokai/folly,fw1121/folly,mqeizi/folly,sonnyhu/folly,bowlofstew/folly,guker/folly,Hincoin/folly,doctaweeks/folly,shaobz/folly,shaobz/folly,cole14/folly,upsoft/folly,PPC64/folly,PPC64/folly,Orvid/folly,theiver9827/folly,yangjin-unique/folly,KSreeHarsha/folly,gaoyingie/folly,nickhen/folly,lifei/folly,bobegir/folly,ykarlsbrun/folly,hongliangzhao/folly,PPC64/folly,constantine001/folly,bsampath/folly,KSreeHarsha/folly,cppfool/folly,floxard/folly,theiver9827/folly,fw1121/folly,bowlofstew/folly,CJstar/folly,alexst07/folly,fw1121/folly,SammyK/folly,mqeizi/folly,colemancda/folly,clearlinux/folly,kernelim/folly,reddit/folly,constantine001/folly,xzmagic/folly,clearlylin/folly,chjp2046/folly,gavioto/folly,cole14/folly,ykarlsbrun/folly,bsampath/folly,cole14/folly,yangjin-unique/folly,bikong2/folly,facebook/folly,facebook/folly,SeanRBurton/folly,KSreeHarsha/folly,cppfool/folly,bikong2/folly,zhiweicai/folly,gaoyingie/folly,tempbottle/folly,SeanRBurton/folly,charsyam/folly,hongliangzhao/folly,clearlinux/folly,loversInJapan/folly,lifei/folly,fw1121/folly,clearlylin/folly,brunomorishita/folly,Eagle-X/folly,sonnyhu/folly,PPC64/folly,CJstar/folly,alexst07/folly,raphaelamorim/folly,PPC64/folly,clearlinux/folly,rklabs/folly,shaobz/folly,wildinto/folly,mqeizi/folly,bowlofstew/folly,upsoft/folly,xzmagic/folly,bowlofstew/folly,KSreeHarsha/folly,Orvid/folly,gavioto/folly,doctaweeks/folly,cole14/folly,leolujuyi/folly,chjp2046/folly,loversInJapan/folly,PoisonBOx/folly,bsampath/folly,tomhughes/folly,yangjin-unique/folly,floxard/folly,loversInJapan/folly,shaobz/folly,leolujuyi/folly,hongliangzhao/folly,cppfool/folly,sonnyhu/folly,upsoft/folly,romange/folly,leolujuyi/folly,stonegithubs/folly,guker/folly,clearlylin/folly,clearlylin/folly,stonegithubs/folly,sonnyhu/folly,bikong2/folly,PoisonBOx/folly,bobegir/folly,arg0/folly,zhiweicai/folly,theiver9827/folly,stonegithubs/folly,lifei/folly,SammyK/folly,sakishum/folly,project-zerus/folly,clearlinux/folly,ykarlsbrun/folly,guker/folly,nickhen/folly,Hincoin/folly,upsoft/folly,tomhughes/folly,reddit/folly,CJstar/folly,arg0/folly,romange/folly,renyinew/folly,wildinto/folly,zhiweicai/folly,colemancda/folly,facebook/folly,romange/folly,Eagle-X/folly,PoisonBOx/folly,leolujuyi/folly,lifei/folly,hongliangzhao/folly,Orvid/folly,Hincoin/folly,ykarlsbrun/folly,nickhen/folly,hongliangzhao/folly,facebook/folly,xzmagic/folly,PoisonBOx/folly,sakishum/folly,colemancda/folly,PoisonBOx/folly,gavioto/folly,colemancda/folly,kernelim/folly,SammyK/folly,constantine001/folly,theiver9827/folly,tempbottle/folly,brunomorishita/folly,mqeizi/folly,renyinew/folly,bikong2/folly,cppfool/folly,stonegithubs/folly,project-zerus/folly,kernelim/folly,bobegir/folly,alexst07/folly,mqeizi/folly,floxard/folly,yangjin-unique/folly,rklabs/folly,project-zerus/folly,Eagle-X/folly,theiver9827/folly,cole14/folly,charsyam/folly,juniway/folly,upsoft/folly,nickhen/folly,bikong2/folly,guker/folly,bsampath/folly,brunomorishita/folly,juniway/folly,renyinew/folly,leolujuyi/folly,CJstar/folly,shaobz/folly,Eagle-X/folly,sakishum/folly,bsampath/folly,arg0/folly,SammyK/folly,xzmagic/folly,Hincoin/folly,Eagle-X/folly,rklabs/folly,SeanRBurton/folly,floxard/folly,reddit/folly,SeanRBurton/folly,zhiweicai/folly,raphaelamorim/folly,bobegir/folly,raphaelamorim/folly,CJstar/folly,brunomorishita/folly,facebook/folly,sakishum/folly,loversInJapan/folly,arg0/folly,chjp2046/folly,arg0/folly,clearlinux/folly,lifei/folly,doctaweeks/folly,bowlofstew/folly,stonegithubs/folly,alexst07/folly,constantine001/folly,Orvid/folly,guker/folly,juniway/folly,floxard/folly,constantine001/folly,renyinew/folly,loverszhaokai/folly,Hincoin/folly,tempbottle/folly,yangjin-unique/folly,tomhughes/folly,gavioto/folly,romange/folly,zhiweicai/folly,cppfool/folly,chjp2046/folly,charsyam/folly,SeanRBurton/folly,alexst07/folly,gaoyingie/folly,tempbottle/folly,project-zerus/folly,KSreeHarsha/folly,juniway/folly,reddit/folly,charsyam/folly,romange/folly,Orvid/folly,loverszhaokai/folly,tomhughes/folly,rklabs/folly,loverszhaokai/folly,sakishum/folly,clearlylin/folly,gaoyingie/folly,juniway/folly,nickhen/folly,kernelim/folly,colemancda/folly,gaoyingie/folly,tempbottle/folly,bobegir/folly,xzmagic/folly,doctaweeks/folly,fw1121/folly,chjp2046/folly,rklabs/folly