add LockTraits
authorAdam Simpkins <simpkins@fb.com>
Wed, 6 Jul 2016 01:26:31 +0000 (18:26 -0700)
committerFacebook Github Bot 7 <facebook-github-bot-7-bot@fb.com>
Wed, 6 Jul 2016 01:38:29 +0000 (18:38 -0700)
commit9276f2a5646a94eda765c92b171b98c499313213
tree83139e9e7e830261fbe6058447fc4920a9f1d71c
parent7235d2011dbd7efaf67489d3a827ce006f2399e7
add LockTraits

Summary:
This adds a new LockTraits template class, for specifying how to use arbitrary
custom mutex types.

The goal of this new class is to replace the acquireRead(), acquireReadWrite(),
releaseRead(), and releaseReadWrite() functions currently defined in
Synchronized.h.  I have not replaced these functions yet in this diff, but will
do so in a follow-up diff.

LockTraits has a few advantages over the existing methods:
* It provides mechanisms for telling if a given mutex supports shared access
  and timed access.
* The default LockTraits implementation automatically figures out the correct
  behavior for classes that define lock(), unlock(), methods.  It automatically
  detects sharing and timed support based on the presence of lock_shared() and
  try_lock_for() methods.

LockTraits can be specialized for custom lock types that do not conform with
the lock method names used by the C++ standard.  This does differ slightly from
the argument dependent lookup mechanism used by the acquireRead() functions.

Reviewed By: yfeldblum

Differential Revision: D3504625

fbshipit-source-id: 40320997e9ae2147baecd10b70e8dc06a35e49e1
folly/LockTraits.h [new file with mode: 0644]
folly/LockTraitsBoost.h [new file with mode: 0644]
folly/Makefile.am
folly/Synchronized.h
folly/test/LockTraitsTest.cpp [new file with mode: 0644]
folly/test/Makefile.am