react-native-windows 0.81.35 → 0.81.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Microsoft.ReactNative/Fabric/Composition/TooltipService.cpp +48 -2
- package/Microsoft.ReactNative/Fabric/WindowsImageManager.cpp +40 -13
- package/PropertySheets/Generated/PackageVersion.g.props +3 -3
- package/Scripts/creaternwlib.cmd +2 -2
- package/external/fast-float/.syncignore +0 -1
- package/external/fast-float/README.md +545 -0
- package/external/fmt/.syncignore +0 -2
- package/external/fmt/README.md +484 -0
- package/external/fmt/doc/ChangeLog-old.md +3290 -0
- package/external/fmt/doc/api.md +650 -0
- package/external/fmt/doc/fmt.css +61 -0
- package/external/fmt/doc/fmt.js +4 -0
- package/external/fmt/doc/get-started.md +222 -0
- package/external/fmt/doc/index.md +151 -0
- package/external/fmt/doc/perf.svg +1 -0
- package/external/fmt/doc/python-license.txt +290 -0
- package/external/fmt/doc/syntax.md +887 -0
- package/external/folly/.syncignore +2 -3
- package/external/folly/README.md +263 -0
- package/external/folly/folly/docs/AtomicHashMap.md +134 -0
- package/external/folly/folly/docs/Benchmark.md +310 -0
- package/external/folly/folly/docs/Conv.md +291 -0
- package/external/folly/folly/docs/Dynamic.md +220 -0
- package/external/folly/folly/docs/DynamicConverter.md +71 -0
- package/external/folly/folly/docs/Executors.md +63 -0
- package/external/folly/folly/docs/FBString.md +46 -0
- package/external/folly/folly/docs/FBVector.md +200 -0
- package/external/folly/folly/docs/Fbvector--graphical_solutions.png +0 -0
- package/external/folly/folly/docs/Format.md +177 -0
- package/external/folly/folly/docs/Function.md +92 -0
- package/external/folly/folly/docs/Futures.md +263 -0
- package/external/folly/folly/docs/GroupVarint.md +46 -0
- package/external/folly/folly/docs/Histogram.md +104 -0
- package/external/folly/folly/docs/MapUtils.md +80 -0
- package/external/folly/folly/docs/Overview.md +263 -0
- package/external/folly/folly/docs/PackedSyncPtr.md +77 -0
- package/external/folly/folly/docs/Poly.md +500 -0
- package/external/folly/folly/docs/ProducerConsumerQueue.md +82 -0
- package/external/folly/folly/docs/Rcu.md +218 -0
- package/external/folly/folly/docs/SmallLocks.md +24 -0
- package/external/folly/folly/docs/Synchronized.md +793 -0
- package/external/folly/folly/docs/ThreadCachedInt.md +98 -0
- package/external/folly/folly/docs/ThreadLocal.md +105 -0
- package/external/folly/folly/docs/Traits.md +161 -0
- package/external/folly/folly/docs/small_vector.md +64 -0
- package/external/folly/folly/docs/style.css +23 -0
- package/external/folly/static/logo.svg +1 -0
- package/package.json +2 -2
- package/templates/cpp-lib/example/metro.config.js +31 -6
- package/Scripts/Warm-RnwFeedCache.ps1 +0 -413
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
`folly/stats/Histogram.h`
|
|
2
|
+
-------------------
|
|
3
|
+
|
|
4
|
+
### Classes
|
|
5
|
+
***
|
|
6
|
+
|
|
7
|
+
#### `Histogram`
|
|
8
|
+
|
|
9
|
+
`Histogram.h` defines a simple histogram class, templated on the type of data
|
|
10
|
+
you want to store. This class is useful for tracking a large stream of data
|
|
11
|
+
points, where you want to remember the overall distribution of the data, but do
|
|
12
|
+
not need to remember each data point individually.
|
|
13
|
+
|
|
14
|
+
Each histogram bucket stores the number of data points that fell in the bucket,
|
|
15
|
+
as well as the overall sum of the data points in the bucket. Note that no
|
|
16
|
+
overflow checking is performed, so if you have a bucket with a large number of
|
|
17
|
+
very large values, it may overflow and cause inaccurate data for this bucket.
|
|
18
|
+
As such, the histogram class is not well suited to storing data points with
|
|
19
|
+
very large values. However, it works very well for smaller data points such as
|
|
20
|
+
request latencies, request or response sizes, etc.
|
|
21
|
+
|
|
22
|
+
In addition to providing access to the raw bucket data, the `Histogram` class
|
|
23
|
+
also provides methods for estimating percentile values. This allows you to
|
|
24
|
+
estimate the median value (the 50th percentile) and other values such as the
|
|
25
|
+
95th or 99th percentiles.
|
|
26
|
+
|
|
27
|
+
All of the buckets have the same width. The number of buckets and bucket width
|
|
28
|
+
is fixed for the lifetime of the histogram. As such, you do need to know your
|
|
29
|
+
expected data range ahead of time in order to have accurate statistics. The
|
|
30
|
+
histogram does keep one bucket to store all data points that fall below the
|
|
31
|
+
histogram minimum, and one bucket for the data points above the maximum.
|
|
32
|
+
However, because these buckets don't have a good lower/upper bound, percentile
|
|
33
|
+
estimates in these buckets may be inaccurate.
|
|
34
|
+
|
|
35
|
+
#### `HistogramBuckets`
|
|
36
|
+
|
|
37
|
+
The `Histogram` class is built on top of `HistogramBuckets`.
|
|
38
|
+
`HistogramBuckets` provides an API very similar to `Histogram`, but allows a
|
|
39
|
+
user-defined bucket class. This allows users to implement more complex
|
|
40
|
+
histogram types that store more than just the count and sum in each bucket.
|
|
41
|
+
|
|
42
|
+
When computing percentile estimates `HistogramBuckets` allows user-defined
|
|
43
|
+
functions for computing the average value and data count in each bucket. This
|
|
44
|
+
allows you to define more complex buckets which may have multiple different
|
|
45
|
+
ways of computing the average value and the count.
|
|
46
|
+
|
|
47
|
+
For example, one use case could be tracking timeseries data in each bucket.
|
|
48
|
+
Each set of timeseries data can have independent data in the bucket, which can
|
|
49
|
+
show how the data distribution is changing over time.
|
|
50
|
+
|
|
51
|
+
### Example Usage
|
|
52
|
+
***
|
|
53
|
+
|
|
54
|
+
Say we have code that sends many requests to remote services, and want to
|
|
55
|
+
generate a histogram showing how long the requests take. The following code
|
|
56
|
+
will initialize histogram with 50 buckets, tracking values between 0 and 5000.
|
|
57
|
+
(There are 50 buckets since the bucket width is specified as 100. If the
|
|
58
|
+
bucket width is not an even multiple of the histogram range, the last bucket
|
|
59
|
+
will simply be shorter than the others.)
|
|
60
|
+
|
|
61
|
+
``` Cpp
|
|
62
|
+
folly::Histogram<int64_t> latencies(100, 0, 5000);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The addValue() method is used to add values to the histogram. Each time a
|
|
66
|
+
request finishes we can add its latency to the histogram:
|
|
67
|
+
|
|
68
|
+
``` Cpp
|
|
69
|
+
latencies.addValue(now - startTime);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
You can access each of the histogram buckets to display the overall
|
|
73
|
+
distribution. Note that bucket 0 tracks all data points that were below the
|
|
74
|
+
specified histogram minimum, and the last bucket tracks the data points that
|
|
75
|
+
were above the maximum.
|
|
76
|
+
|
|
77
|
+
``` Cpp
|
|
78
|
+
auto numBuckets = latencies.getNumBuckets();
|
|
79
|
+
cout << "Below min: " << latencies.getBucketByIndex(0).count << "\n";
|
|
80
|
+
for (unsigned int n = 1; n < numBuckets - 1; ++n) {
|
|
81
|
+
cout << latencies.getBucketMin(n) << "-" << latencies.getBucketMax(n)
|
|
82
|
+
<< ": " << latencies.getBucketByIndex(n).count << "\n";
|
|
83
|
+
}
|
|
84
|
+
cout << "Above max: "
|
|
85
|
+
<< latencies.getBucketByIndex(numBuckets - 1).count << "\n";
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
You can also use the `getPercentileEstimate()` method to estimate the value at
|
|
89
|
+
the Nth percentile in the distribution. For example, to estimate the median,
|
|
90
|
+
as well as the 95th and 99th percentile values:
|
|
91
|
+
|
|
92
|
+
``` Cpp
|
|
93
|
+
int64_t median = latencies.getPercentileEstimate(0.5);
|
|
94
|
+
int64_t p95 = latencies.getPercentileEstimate(0.95);
|
|
95
|
+
int64_t p99 = latencies.getPercentileEstimate(0.99);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Thread Safety
|
|
99
|
+
***
|
|
100
|
+
|
|
101
|
+
Note that `Histogram` and `HistogramBuckets` objects are not thread-safe. If
|
|
102
|
+
you wish to access a single `Histogram` from multiple threads, you must perform
|
|
103
|
+
your own locking to ensure that multiple threads do not access it at the same
|
|
104
|
+
time.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
`folly/container/MapUtil.h`
|
|
2
|
+
---------------------------
|
|
3
|
+
|
|
4
|
+
MapUtil provides convenience functions to get a value from a map.
|
|
5
|
+
|
|
6
|
+
### Motivation & Comparisons
|
|
7
|
+
|
|
8
|
+
Fetching a value in a map can be tedious. For example, `map.at()` will throw an exception if the key is not present:
|
|
9
|
+
```cpp
|
|
10
|
+
try {
|
|
11
|
+
auto& v = m.at(1);
|
|
12
|
+
} catch (...) {
|
|
13
|
+
// do something!
|
|
14
|
+
}
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
We can avoid the exception handling by using `find`:
|
|
18
|
+
```cpp
|
|
19
|
+
auto it = m.find(1);
|
|
20
|
+
if (it != m.end()) {
|
|
21
|
+
auto& v = it->second;
|
|
22
|
+
}
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Both of these cases can be written more succinctly and without exception handling using folly/MapUtil.h
|
|
26
|
+
```cpp
|
|
27
|
+
if (const auto* v = folly::get_ptr(m, 1)) {
|
|
28
|
+
// do stuff with `v` which is guaranteed to be present in this block
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
We can also easily lookup values in nested maps:
|
|
33
|
+
```cpp
|
|
34
|
+
std::map<int, std::map<int, int>> m {{1, {{2, 3}}}};
|
|
35
|
+
// using find
|
|
36
|
+
auto it1 = m.find(1);
|
|
37
|
+
if (it1 != m.end()) {
|
|
38
|
+
auto it2 = it1->second.find(2);
|
|
39
|
+
if (it2 != it1->second.end()) {
|
|
40
|
+
auto& v = it2->second;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// using folly/MapUtil.h
|
|
44
|
+
if (const auto* v = folly::get_ptr(m, 1, 2)) {
|
|
45
|
+
// do stuff with `v`!
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Sample
|
|
50
|
+
The corresponding unit test suite has a very thorough collection of examples: `folly/container/test/MapUtilTest.cpp`,
|
|
51
|
+
for brevity, here is a small glimpse:
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
```cpp
|
|
55
|
+
std::map<int, int> m {{1, 2}};
|
|
56
|
+
|
|
57
|
+
// Return a pointer (nullptr if the key is not in the map)
|
|
58
|
+
EXPECT_EQ(2, *get_ptr(m, 1));
|
|
59
|
+
EXPECT_TRUE(get_ptr(m, 2) == nullptr);
|
|
60
|
+
|
|
61
|
+
// Return a value (or default)
|
|
62
|
+
EXPECT_EQ(2, get_default(m, 1, 42));
|
|
63
|
+
EXPECT_EQ(42, get_default(m, 2, 42));
|
|
64
|
+
|
|
65
|
+
// Return an optional (empty if the key is not in the map)
|
|
66
|
+
EXPECT_TRUE(get_optional(m, 1).has_value());
|
|
67
|
+
EXPECT_EQ(2, get_optional(m, 1).value());
|
|
68
|
+
|
|
69
|
+
// Return a reference
|
|
70
|
+
const int i = 42;
|
|
71
|
+
EXPECT_EQ(2, get_ref_default(m, 1, i));
|
|
72
|
+
EXPECT_EQ(42, get_ref_default(m, 2, i));
|
|
73
|
+
|
|
74
|
+
// Even works for nested maps!
|
|
75
|
+
std::map<int, map<int, map<int, map<int, int>>>> nested{{1, {{2, {{3, {{4, 5}}}}}}}};
|
|
76
|
+
EXPECT_EQ(5, *get_ptr(nested, 1, 2, 3, 4));
|
|
77
|
+
EXPECT_TRUE(get_ptr(nested, 1, 2, 3, 4));
|
|
78
|
+
EXPECT_FALSE(get_ptr(nested, 1, 2, 3, 0));
|
|
79
|
+
```
|
|
80
|
+
***
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
### `folly/`
|
|
2
|
+
|
|
3
|
+
### Components
|
|
4
|
+
|
|
5
|
+
Below is a list of (some) Folly components in alphabetical order, along with
|
|
6
|
+
a brief description of each.
|
|
7
|
+
|
|
8
|
+
#### `Arena.h`, `ThreadCachedArena.h`
|
|
9
|
+
|
|
10
|
+
Simple arena for memory allocation: multiple allocations get freed all
|
|
11
|
+
at once. With threaded version.
|
|
12
|
+
|
|
13
|
+
#### [`AtomicHashMap.h`](AtomicHashMap.md), `AtomicHashArray.h`, `AtomicLinkedList.h`, ...
|
|
14
|
+
|
|
15
|
+
High-performance atomic data-structures. Many of these are built with very specific
|
|
16
|
+
tradeoffs and constraints in mind that make them faster than their more general
|
|
17
|
+
counterparts. Each header should contain information about what these tradeoffs are.
|
|
18
|
+
|
|
19
|
+
#### `Baton.h`
|
|
20
|
+
|
|
21
|
+
A Baton allows a thread to block once and be awoken: it captures a single handoff. It is
|
|
22
|
+
essentially a (very small, very fast) semaphore that supports only a single call to `sem_call`
|
|
23
|
+
and `sem_wait`.
|
|
24
|
+
|
|
25
|
+
#### [`Benchmark.h`](Benchmark.md)
|
|
26
|
+
|
|
27
|
+
A small framework for benchmarking code. Client code registers
|
|
28
|
+
benchmarks, optionally with an argument that dictates the scale of the
|
|
29
|
+
benchmark (iterations, working set size etc). The framework runs
|
|
30
|
+
benchmarks (subject to a command-line flag) and produces formatted
|
|
31
|
+
output with timing information.
|
|
32
|
+
|
|
33
|
+
#### `Bits.h`
|
|
34
|
+
|
|
35
|
+
Various bit manipulation utilities optimized for speed; includes functions
|
|
36
|
+
that wrap the
|
|
37
|
+
[ffsl(l)](http://linux.die.net/man/3/ffsll) primitives in a uniform
|
|
38
|
+
interface.
|
|
39
|
+
|
|
40
|
+
#### `ConcurrentSkipList.h`
|
|
41
|
+
|
|
42
|
+
An implementation of the structure described in [A Provably Correct
|
|
43
|
+
Scalable Concurrent Skip
|
|
44
|
+
List](http://people.csail.mit.edu/shanir/publications/OPODIS2006-BA.pdf)
|
|
45
|
+
by Herlihy et al.
|
|
46
|
+
|
|
47
|
+
#### [`Conv.h`](Conv.md)
|
|
48
|
+
|
|
49
|
+
A variety of data conversion routines (notably to and from string),
|
|
50
|
+
optimized for speed and safety.
|
|
51
|
+
|
|
52
|
+
#### `Demangle.h`
|
|
53
|
+
|
|
54
|
+
Pretty-printing C++ types.
|
|
55
|
+
|
|
56
|
+
#### `DiscriminatedPtr.h`
|
|
57
|
+
|
|
58
|
+
Similar to `std::variant`, but restricted to pointers only. Uses the
|
|
59
|
+
highest-order unused 16 bits in a pointer as discriminator. So
|
|
60
|
+
`sizeof(DiscriminatedPtr<int, string, Widget>) == sizeof(void*)`.
|
|
61
|
+
|
|
62
|
+
#### [`dynamic.h`](Dynamic.md)
|
|
63
|
+
|
|
64
|
+
Dynamically-typed object, created with JSON objects in mind. `DynamicConverter.h` is
|
|
65
|
+
a utility for efficiently converting from a `dynamic` to a more concrete structure when
|
|
66
|
+
the scheme is known (e.g. json -> `map<int,int>`).
|
|
67
|
+
|
|
68
|
+
#### `EvictingCacheMap.h`
|
|
69
|
+
|
|
70
|
+
A simple LRU hash map.
|
|
71
|
+
|
|
72
|
+
#### [`FBString.h`](FBString.md)
|
|
73
|
+
|
|
74
|
+
A drop-in implementation of `std::string` with a variety of optimizations.
|
|
75
|
+
|
|
76
|
+
#### [`FBVector.h`](FBVector.md)
|
|
77
|
+
|
|
78
|
+
A mostly drop-in implementation of `std::vector` with a variety of
|
|
79
|
+
optimizations.
|
|
80
|
+
|
|
81
|
+
#### `File.h`
|
|
82
|
+
|
|
83
|
+
A C++ abstraction around files.
|
|
84
|
+
|
|
85
|
+
#### `Fingerprint.h`
|
|
86
|
+
|
|
87
|
+
Rabin fingerprinting.
|
|
88
|
+
|
|
89
|
+
#### [`Function.h`](Function.md)
|
|
90
|
+
|
|
91
|
+
A polymorphic wrapper for callables similar to `std::function` but not copyable and therefore able to wrap non-copyable callables, such as lambdas that capture move-only types like `std::unique_ptr` or `folly::Promise`.
|
|
92
|
+
|
|
93
|
+
#### [`futures/`](Futures.md)
|
|
94
|
+
|
|
95
|
+
Futures is a framework for expressing asynchronous code in C++ using the Promise/Future pattern.
|
|
96
|
+
|
|
97
|
+
#### [`Format.h`](Format.md)
|
|
98
|
+
|
|
99
|
+
Python-style formatting utilities.
|
|
100
|
+
|
|
101
|
+
#### `gen/`
|
|
102
|
+
|
|
103
|
+
This library makes it possible to write declarative comprehensions for
|
|
104
|
+
processing sequences of values efficiently in C++ akin to C#'s LINQ.
|
|
105
|
+
|
|
106
|
+
#### [`GroupVarint.h`](GroupVarint.md)
|
|
107
|
+
|
|
108
|
+
[Group Varint
|
|
109
|
+
encoding](http://www.ir.uwaterloo.ca/book/addenda-06-index-compression.html)
|
|
110
|
+
for 32-bit values.
|
|
111
|
+
|
|
112
|
+
#### `IPAddress.h`
|
|
113
|
+
|
|
114
|
+
A collection of utilities to deal with IPAddresses, including ipv4 and ipv6.
|
|
115
|
+
|
|
116
|
+
#### `io/`
|
|
117
|
+
|
|
118
|
+
A collection of useful of abstractions for high-performance io. This is heavily relied upon
|
|
119
|
+
in Facebook's internally networking code.
|
|
120
|
+
|
|
121
|
+
#### `Hash.h`
|
|
122
|
+
|
|
123
|
+
Various popular hash function implementations.
|
|
124
|
+
|
|
125
|
+
#### [`Histogram.h`](Histogram.md)
|
|
126
|
+
|
|
127
|
+
A simple class for collecting histogram data.
|
|
128
|
+
|
|
129
|
+
#### `IntrusiveList.h`
|
|
130
|
+
|
|
131
|
+
Convenience type definitions for using `boost::intrusive_list`.
|
|
132
|
+
|
|
133
|
+
#### `json.h`
|
|
134
|
+
|
|
135
|
+
JSON serializer and deserializer. Uses `dynamic.h`.
|
|
136
|
+
|
|
137
|
+
#### `Likely.h`
|
|
138
|
+
|
|
139
|
+
Wrappers around [`__builtin_expect`](http://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html).
|
|
140
|
+
|
|
141
|
+
#### `Malloc.h`, `Memory.h`
|
|
142
|
+
|
|
143
|
+
Memory allocation helpers, particularly when using jemalloc.
|
|
144
|
+
|
|
145
|
+
#### `MicroSpinLock.h`
|
|
146
|
+
|
|
147
|
+
A really, *really* small spinlock for fine-grained locking of lots of teeny-tiny data.
|
|
148
|
+
|
|
149
|
+
#### `MPMCQueue.h`
|
|
150
|
+
|
|
151
|
+
MPMCQueue<typename> is a high-performance bounded concurrent queue that
|
|
152
|
+
supports multiple producers, multiple consumers, and optional blocking.
|
|
153
|
+
The queue has a fixed capacity, for which all memory will be allocated
|
|
154
|
+
up front.
|
|
155
|
+
|
|
156
|
+
The additional utility `MPMCPipeline.h` is an extension that lets you
|
|
157
|
+
chain several queues together with processing steps in between.
|
|
158
|
+
|
|
159
|
+
#### [`PackedSyncPtr.h`](PackedSyncPtr.md)
|
|
160
|
+
|
|
161
|
+
A highly specialized data structure consisting of a pointer, a 1-bit
|
|
162
|
+
spin lock, and a 15-bit integer, all inside one 64-bit word.
|
|
163
|
+
|
|
164
|
+
#### [`Poly.h`](Poly.md)
|
|
165
|
+
|
|
166
|
+
A class template that makes it relatively easy to define a type-erasing
|
|
167
|
+
polymorphic object wrapper.
|
|
168
|
+
|
|
169
|
+
#### `Preprocessor.h`
|
|
170
|
+
|
|
171
|
+
Necessarily evil stuff.
|
|
172
|
+
|
|
173
|
+
#### [`ProducerConsumerQueue.h`](ProducerConsumerQueue.md)
|
|
174
|
+
|
|
175
|
+
Lock free single-reader, single-writer queue.
|
|
176
|
+
|
|
177
|
+
#### `Random.h`
|
|
178
|
+
|
|
179
|
+
Defines only one function---`randomNumberSeed()`.
|
|
180
|
+
|
|
181
|
+
#### `Range.h`
|
|
182
|
+
|
|
183
|
+
Boost-style range facility and the `StringPiece` specialization.
|
|
184
|
+
|
|
185
|
+
#### `RWSpinLock.h`
|
|
186
|
+
|
|
187
|
+
Fast and compact reader-writer spin lock.
|
|
188
|
+
|
|
189
|
+
#### `ScopeGuard.h`
|
|
190
|
+
|
|
191
|
+
C++11 incarnation of the old [ScopeGuard](http://drdobbs.com/184403758) idiom.
|
|
192
|
+
|
|
193
|
+
#### `Singleton.h`
|
|
194
|
+
|
|
195
|
+
A singleton to rule the singletons. This is an attempt to insert a layer between
|
|
196
|
+
C++ statics and the fiasco that ensues, so that things can be created, and destroyed,
|
|
197
|
+
correctly upon program creation, program end and sometimes `dlopen` and `fork`.
|
|
198
|
+
|
|
199
|
+
Singletons are bad for you, but this may help.
|
|
200
|
+
|
|
201
|
+
#### [`SmallLocks.h`](SmallLocks.md)
|
|
202
|
+
|
|
203
|
+
Very small spin locks (1 byte and 1 bit).
|
|
204
|
+
|
|
205
|
+
#### `small_vector.h`
|
|
206
|
+
|
|
207
|
+
Vector with the small buffer optimization and an optional embedded
|
|
208
|
+
`PicoSpinLock`.
|
|
209
|
+
|
|
210
|
+
#### `sorted_vector_types.h`
|
|
211
|
+
|
|
212
|
+
Collections similar to `std::map` but implemented as sorted vectors.
|
|
213
|
+
|
|
214
|
+
#### `stats/`
|
|
215
|
+
|
|
216
|
+
A collection of efficient utilities for collecting statistics:
|
|
217
|
+
* time series counters, gauges, histograms, and quantiles;
|
|
218
|
+
* single-pass mean and variance.
|
|
219
|
+
|
|
220
|
+
#### `StlAllocator.h`
|
|
221
|
+
|
|
222
|
+
STL allocator wrapping a simple allocate/deallocate interface.
|
|
223
|
+
|
|
224
|
+
#### `String.h`
|
|
225
|
+
|
|
226
|
+
String utilities that connect `folly::fbstring` with `std::string`.
|
|
227
|
+
|
|
228
|
+
#### `Subprocess.h`
|
|
229
|
+
|
|
230
|
+
Subprocess library, modeled after Python's subprocess module.
|
|
231
|
+
|
|
232
|
+
#### [`Synchronized.h`](Synchronized.md)
|
|
233
|
+
|
|
234
|
+
High-level synchronization library.
|
|
235
|
+
|
|
236
|
+
#### `System.h`
|
|
237
|
+
|
|
238
|
+
Demangling and errno utilities.
|
|
239
|
+
|
|
240
|
+
#### [`ThreadCachedInt.h`](ThreadCachedInt.md)
|
|
241
|
+
|
|
242
|
+
High-performance atomic increment using thread caching.
|
|
243
|
+
|
|
244
|
+
#### [`ThreadLocal.h`](ThreadLocal.md)
|
|
245
|
+
|
|
246
|
+
Improved thread local storage for non-trivial types.
|
|
247
|
+
|
|
248
|
+
#### `TimeoutQueue.h`
|
|
249
|
+
|
|
250
|
+
Queue with per-item timeout.
|
|
251
|
+
|
|
252
|
+
#### `Traits.h`
|
|
253
|
+
|
|
254
|
+
Type traits that complement those defined in the standard C++11 header
|
|
255
|
+
`<traits>`.
|
|
256
|
+
|
|
257
|
+
#### `Unicode.h`
|
|
258
|
+
|
|
259
|
+
Defines the `codePointToUtf8` function.
|
|
260
|
+
|
|
261
|
+
#### `Uri.h`
|
|
262
|
+
|
|
263
|
+
A collection of utilities to deal with URIs.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
`folly/PackedSyncPtr.h`
|
|
2
|
+
----------------------
|
|
3
|
+
|
|
4
|
+
A highly specialized data structure consisting of a pointer, a 1-bit
|
|
5
|
+
spin lock, and a 15-bit integral packed into `sizeof(void*)`.
|
|
6
|
+
|
|
7
|
+
Typical application is for microsharding of many elements within containers.
|
|
8
|
+
Because there is no memory overhead, an arbitrarily large number of locks can be
|
|
9
|
+
used to minimize lock contention with no memory penalty. Additionally,
|
|
10
|
+
excellent cache performance is obtained by storing the lock inline with the
|
|
11
|
+
pointer (no additional cache miss or false sharing). Finally, because it uses a
|
|
12
|
+
simple spinlock mechanism, the cost of acquiring an uncontended lock is minimal.
|
|
13
|
+
|
|
14
|
+
### Usage
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
This is not a "smart" pointer: nothing automagical is going on
|
|
18
|
+
here. Locking is up to the user. Resource deallocation is up to
|
|
19
|
+
the user. Locks are never acquired or released outside explicit
|
|
20
|
+
calls to lock() and unlock().
|
|
21
|
+
|
|
22
|
+
Change the value of the raw pointer with set(), but you must hold
|
|
23
|
+
the lock when calling this function if multiple threads could be
|
|
24
|
+
using it.
|
|
25
|
+
|
|
26
|
+
Here is an example of using a PackedSyncPtr to build a synchronized vector with
|
|
27
|
+
no memory overhead - the spinlock and size are stored in the 16 unused bits of
|
|
28
|
+
pointer, the rest of which points to the actual data. See
|
|
29
|
+
`folly/small_vector.h` for a complete implementation of this concept.
|
|
30
|
+
|
|
31
|
+
``` Cpp
|
|
32
|
+
template<typename T>
|
|
33
|
+
class SyncVec {
|
|
34
|
+
PackedSyncPtr<T> base;
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
SyncVec() { base.init(); }
|
|
38
|
+
|
|
39
|
+
void push_back(const T& t) {
|
|
40
|
+
base.set(
|
|
41
|
+
static_cast<T*>(realloc(base.get(), (base.extra() + 1) * sizeof(T))));
|
|
42
|
+
base[base.extra()] = t;
|
|
43
|
+
base.setExtra(base.extra() + 1);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
size_t size() const {
|
|
47
|
+
return base.extra();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
void lock() {
|
|
51
|
+
base.lock();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void unlock() {
|
|
55
|
+
base.unlock();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
T* begin() const {
|
|
59
|
+
return base.get();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
T* end() const {
|
|
63
|
+
return base.get() + base.extra();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Implementation
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
This is using an x64-specific detail about the effective virtual
|
|
72
|
+
address space. Long story short: the upper two bytes of all our
|
|
73
|
+
pointers will be zero in reality---and if you have a couple billion
|
|
74
|
+
such pointers in core, it makes pretty good sense to try to make
|
|
75
|
+
use of that memory. The exact details can be perused here:
|
|
76
|
+
|
|
77
|
+
[http://en.wikipedia.org/wiki/X86-64#Canonical_form_addresses](http://en.wikipedia.org/wiki/X86-64#Canonical_form_addresses)
|