• Adam Simpkins's avatar
    add Synchronized::withLock() methods · b179601d
    Adam Simpkins authored
    Summary:
    Add withLock() and related methods for invoking a lambda function while the
    lock is held.  This is sometimes more convenient than opening a new scope and
    using lock().
    
    withLock() also retains some of the benefits of the SYNCHRONIZED macro in that
    it forces users to put their critical section code in a new scope, making the
    critical section more visibly distinct in the code.  This also encourages users
    to only put necessary work inside the critical section, and do to other work
    once the lock is released.
    
    This also adds a LockedGuardPtr class, which is a slightly cheaper version of
    LockedPtr.  The relationship between LockedGuardPtr and LockedPtr is very much
    like that between std::lock_guard and std::unique_lock.  It saves a branch in
    the destructor, and in the case of std::mutex it also saves a small amount of
    storage space (since LockedPtr is specialized for std::mutex to also store a
    std::unique_lock).
    
    Reviewed By: yfeldblum, djwatson
    
    Differential Revision: D3530368
    
    fbshipit-source-id: 72a4f457b3f18e8e8f4cc6713218f6882bb89818
    b179601d
SynchronizedTestLib-inl.h 22.9 KB