MB-28940: Remove lock usage from StatisticalCounter
MB-28940: Remove lock usage from StatisticalCounter

The StatisticalCounter::generateValue benchmark has shown that the
function suffers a peformance degradation when used in a multi-threaded
environment.

See below:

./ep_engine_benchmarks --benchmark_filter=BM_SaturateCounter
Run on (8 X 2500 MHz CPU s)
2018-03-28 17:04:15
--------------------------------------------------------------------
Benchmark                             Time           CPU Iterations
--------------------------------------------------------------------
BM_SaturateCounter/threads:1         28 ns         28 ns   22953679
BM_SaturateCounter/threads:8       3723 ns       3853 ns     180248

The issue is believed to be due to the use of a mutex in the
generateValue function.  Therefore this patch changes to use a
thread_local random number generator.  This is based on:
https://stackoverflow.com/a/21238187

The effect on the StatisticalCounter::generateValue benchmark is shown
below:

./ep_engine_benchmarks --benchmark_filter=BM_SaturateCounter
Run on (8 X 2500 MHz CPU s)
2018-03-29 17:30:08
--------------------------------------------------------------------
Benchmark                             Time           CPU Iterations
--------------------------------------------------------------------
BM_SaturateCounter/threads:1         19 ns         19 ns   39370079
BM_SaturateCounter/threads:8          3 ns         26 ns   27001096

Re-applying Because the original patch assumed that all targets
supported the thread_local keyword.  However on MacOS it is only
supported in XCode 8 (MacOS 10.11.5 / 10.12 or later).  Therefore
we implement using the __thread keyword on MacOSX and change the
implementation accordingly.

Change-Id: I036dc37ef955d77393cf5a2b0c9a1b9f85d46795
Reviewed-on: http://review.couchbase.org/91832
Reviewed-by: Dave Rigby <a09264da4832c7ff1d3bf1608a19f4b870f93750@couchbase.com>
Tested-by: Build Bot <80754af91bfb6d1073585b046fe0a474ce868509@couchbase.com>

daverigby/kv_engine,daverigby/kv_engine,daverigby/kv_engine,daverigby/kv_engine