io/async: Add support for RequestData::onClear() callback function
Summary: Add support for onClear() callback function to RequestData. The callback is to be executed on the last clearing of RequestData. This typically happens upon the destruction of the last RequestContext that contains the RequestData or due to explicit calls to RequestContext::clearContextData that remove the RequestData from the RequestContext. The onClear() callback is executed exactly once. If there are no calls to clearContextData, then onClear is executed upon the destruction of the last RequestContext that refers to the RequestData. If there are calls to clearContextData, then onClear is executed upon the removal of the last reference to the RequestData from a RequestContext. RequestData::hasCallback() applies only to onSet() and onUnset() which may be called multiple times, whereas onClear() is called exactly once. If a class derived from RequestData overrides onClear and either or both of onSet and onUnset, then care must be taken that the callbacks are mutually safe, as it is possible for the execution of onClear to be concurrent with executions of onSet and onUnset. Motivation: Some uses of RequestContext::clearContextData expect the immediate destruction of associated RequestData. The hazard pointer-based implementation of RequestContext guarantees only that all associated RequestData is destroyed before the completion of the destructor of the RequestContext. This callback provides users of RequestContext more control of the timing of executing actions related to clearing the data. The addition of this capability is intended to provide a tool to eliminate differences in timing of executing actions between the two implementations of RequestContext (hazard pointer-based vs. read lock-based). Also, fixes a minor bug in request_context_test, where the key "test2" was used in two tests (setIfAbsentTest and deadlockTest) without being cleared, which generated a warning when the tests were run in the same process. Reviewed By: davidtgoldblatt Differential Revision: D20332008 fbshipit-source-id: c9cefffb28c8da098e97f851f31d29a1bf704061
Showing
Please register or sign in to comment