Mechanism to fire callbacks on new object construction
Summary: Create a new class, ConstructorCallback, that when included as a member in another class (e.g., Foo) allows other functions to register and receive callbacks every time any of Foo's constructors are called. Main implementation concern is to be extremely lightweight (e.g., avoid locks) assuming that most code calling this will be performance optimized (both for CPU and mem). Implement as a static array of functions: 1) Static array instead of dynamic (e.g., vector): vector occasionally resizes so avoid locking during resize 2) Don't allow removing callback functions: simplify the calling of funcitons, again to avoid locks and races 3) Use function callbacks instead of objects with an observer pattern (e.g., like AsyncSocket::LifecycleObserver) to ensure that there won't be races on shutdown. Functions are static where classes can de-allocate at shutdown and since we don't allow un-registering the call back, it's not easy to remove the race for a class. Reviewed By: simpkins Differential Revision: D27056139 fbshipit-source-id: 0846e0d55124cfde2e15acbe18e01ca5e327e7df
Showing
folly/ConstructorCallback.h
0 → 100644
Please register or sign in to comment