Baton - minimalist inter-thread notification
authorNathan Bronson <ngbronson@fb.com>
Fri, 17 Jan 2014 18:25:41 +0000 (10:25 -0800)
committerJordan DeLong <jdelong@fb.com>
Sun, 19 Jan 2014 01:39:50 +0000 (17:39 -0800)
commit9f040aa0d4023a64e08cda5b76b37a15e48ff732
tree706b96f66050588acb0cbf3a81a8e95597c980dd
parent325517b966a67d52e9db98cd66d6aa0714b2ad7b
Baton - minimalist inter-thread notification

Summary:
A Baton allows a thread to block once and be awoken: it captures
a single handoff.  During its lifecycle (from construction/reset to
destruction/reset) a baton must either be post()ed and wait()ed exactly
once each, or not at all.  Batons may be reused after a call to
recycle().

Baton includes no internal padding, and is only 4 bytes in size.
Any alignment or padding to avoid false sharing is up to the user.

This is basically a stripped-down semaphore that supports only a single
call to sem_post.  The current posix semaphore sem_t isn't too bad, but
this provides more a bit more speed, checking, inlining, smaller size,
a guarantee that the implementation won't change, and compatibility
with DeterministicSchedule.  Baton is directly implemented on top of
futex, and takes care to avoid system calls.

Test Plan:
1. new unit tests
2. this code has already been in production use in TAO for many months

Reviewed By: davejwatson@fb.com

FB internal diff: D1130407
folly/Baton.h [new file with mode: 0644]
folly/Makefile.am
folly/test/BatonTest.cpp [new file with mode: 0644]