(wangle) express current Core functionality with a state machine
(wangle) express current Core functionality with a state machine

Summary:
This is a refactor of the current functionality to use a state machine (inheriting from `FSM`). This will make it easier to extend to do cancellation and Future collapsing. Performance is the same, maybe slightly faster (abt 1%). (I might be a little conservative with the atomics, it might be worth going through and reasoning about whether they all need to be atomic).

The state machine is two states, Waiting (no value), and Done (has a value). Transitioning to Done will execute the callback if it exists and we are active. Otherwise the callback will happen when it is set and active is true.

There is a subjective balancing act in place here, between making a state for every single mutable bit of information (which results in an explosion of states: hasValue X hasCallback X isActive X isCancelled …), and finding a sweet spot of expressivity. This isn't too far from the way Twitter did it, though we don't (yet) have all the states they have (and they don't have the concept of hot/cold futures). But I got there by way of replacing the `mutex_` with the state, after changing all those variables to atomics so they didn't need mutex protection (resulting in only `callback_` and `result_` needing it). I expect the state machine will morph as the rest of the functionality is added, but hopefully it will be easier to understand and keep correct (that's the idea anyway).

Test Plan: Tests still pass (and not by accident, I made several awesome mistakes along the way).

Reviewed By: davejwatson@fb.com

Subscribers: net-systems@, fugalh, exa, njormrod

FB internal diff: D1618240

Tasks: 4618297

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