react-native-windows 0.81.35 → 0.81.37
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/Microsoft.ReactNative/TurboModulesProvider.cpp +30 -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
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
/CMake/
|
|
13
13
|
/build/
|
|
14
14
|
/shim/
|
|
15
|
-
/static
|
|
15
|
+
/static/*
|
|
16
|
+
!/static/logo.svg
|
|
16
17
|
/BUCK
|
|
17
18
|
/PACKAGE
|
|
18
19
|
/buck2
|
|
@@ -20,7 +21,6 @@
|
|
|
20
21
|
/build.sh
|
|
21
22
|
/CODE_OF_CONDUCT.md
|
|
22
23
|
/CONTRIBUTING.md
|
|
23
|
-
/README.md
|
|
24
24
|
|
|
25
25
|
# folly/ subdirectories not used by RNW
|
|
26
26
|
/folly/algorithm/*
|
|
@@ -35,7 +35,6 @@
|
|
|
35
35
|
/folly/coro/
|
|
36
36
|
/folly/crypto/
|
|
37
37
|
/folly/debugging/
|
|
38
|
-
/folly/docs/
|
|
39
38
|
/folly/executors/
|
|
40
39
|
/folly/experimental/
|
|
41
40
|
/folly/ext/
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
Folly: Facebook Open-source Library
|
|
2
|
+
===================================
|
|
3
|
+
|
|
4
|
+
<a href="https://opensource.facebook.com/support-ukraine">
|
|
5
|
+
<img src="https://img.shields.io/badge/Support-Ukraine-FFD500?style=flat&labelColor=005BBB" alt="Support Ukraine - Help Provide Humanitarian Aid to Ukraine." />
|
|
6
|
+
</a>
|
|
7
|
+
|
|
8
|
+
# What is `folly`?
|
|
9
|
+
|
|
10
|
+
<img src="static/logo.svg" alt="Logo Folly" width="15%" align="right" />
|
|
11
|
+
|
|
12
|
+
Folly (acronymed loosely after Facebook Open Source Library) is a
|
|
13
|
+
library of C++17 components designed with practicality and efficiency
|
|
14
|
+
in mind. **Folly contains a variety of core library components used extensively
|
|
15
|
+
at Facebook**. In particular, it's often a dependency of Facebook's other
|
|
16
|
+
open source C++ efforts and place where those projects can share code.
|
|
17
|
+
|
|
18
|
+
It complements (as opposed to competing against) offerings
|
|
19
|
+
such as Boost and of course `std`. In fact, we embark on defining our
|
|
20
|
+
own component only when something we need is either not available, or
|
|
21
|
+
does not meet the needed performance profile. We endeavor to remove
|
|
22
|
+
things from folly if or when `std` or Boost obsoletes them.
|
|
23
|
+
|
|
24
|
+
Performance concerns permeate much of Folly, sometimes leading to
|
|
25
|
+
designs that are more idiosyncratic than they would otherwise be (see
|
|
26
|
+
e.g. `PackedSyncPtr.h`, `SmallLocks.h`). Good performance at large
|
|
27
|
+
scale is a unifying theme in all of Folly.
|
|
28
|
+
|
|
29
|
+
## Check it out in the intro video
|
|
30
|
+
[](https://www.youtube.com/watch?v=Wr_IfOICYSs)
|
|
31
|
+
|
|
32
|
+
# Logical Design
|
|
33
|
+
|
|
34
|
+
Folly is a collection of relatively independent components, some as
|
|
35
|
+
simple as a few symbols. There is no restriction on internal
|
|
36
|
+
dependencies, meaning that a given folly module may use any other
|
|
37
|
+
folly components.
|
|
38
|
+
|
|
39
|
+
All symbols are defined in the top-level namespace `folly`, except of
|
|
40
|
+
course macros. Macro names are ALL_UPPERCASE and should be prefixed
|
|
41
|
+
with `FOLLY_`. Namespace `folly` defines other internal namespaces
|
|
42
|
+
such as `internal` or `detail`. User code should not depend on symbols
|
|
43
|
+
in those namespaces.
|
|
44
|
+
|
|
45
|
+
Folly has an `experimental` directory as well. This designation connotes
|
|
46
|
+
primarily that we feel the API may change heavily over time. This code,
|
|
47
|
+
typically, is still in heavy use and is well tested.
|
|
48
|
+
|
|
49
|
+
# Physical Design
|
|
50
|
+
|
|
51
|
+
At the top level Folly uses the classic "stuttering" scheme
|
|
52
|
+
`folly/folly` used by Boost and others. The first directory serves as
|
|
53
|
+
an installation root of the library (with possible versioning a la
|
|
54
|
+
`folly-1.0/`), and the second is to distinguish the library when
|
|
55
|
+
including files, e.g. `#include <folly/FBString.h>`.
|
|
56
|
+
|
|
57
|
+
The directory structure is flat (mimicking the namespace structure),
|
|
58
|
+
i.e. we don't have an elaborate directory hierarchy (it is possible
|
|
59
|
+
this will change in future versions). The subdirectory `experimental`
|
|
60
|
+
contains files that are used inside folly and possibly at Facebook but
|
|
61
|
+
not considered stable enough for client use. Your code should not use
|
|
62
|
+
files in `folly/experimental` lest it may break when you update Folly.
|
|
63
|
+
|
|
64
|
+
The `folly/folly/test` subdirectory includes the unittests for all
|
|
65
|
+
components, usually named `ComponentXyzTest.cpp` for each
|
|
66
|
+
`ComponentXyz.*`. The `folly/folly/docs` directory contains
|
|
67
|
+
documentation.
|
|
68
|
+
|
|
69
|
+
# What's in it?
|
|
70
|
+
|
|
71
|
+
Because of folly's fairly flat structure, the best way to see what's in it
|
|
72
|
+
is to look at the headers in [top level `folly/` directory](https://github.com/facebook/folly/tree/main/folly). You can also
|
|
73
|
+
check the [`docs` folder](folly/docs) for documentation, starting with the
|
|
74
|
+
[overview](folly/docs/Overview.md).
|
|
75
|
+
|
|
76
|
+
Folly is published on GitHub at https://github.com/facebook/folly.
|
|
77
|
+
|
|
78
|
+
# Build Notes
|
|
79
|
+
|
|
80
|
+
Because folly does not provide any ABI compatibility guarantees from commit to
|
|
81
|
+
commit, we generally recommend building folly as a static library.
|
|
82
|
+
|
|
83
|
+
folly supports gcc (5.1+), clang, or MSVC. It should run on Linux (x86-32,
|
|
84
|
+
x86-64, and ARM), iOS, macOS, and Windows (x86-64). The CMake build is only
|
|
85
|
+
tested on some of these platforms; at a minimum, we aim to support macOS and
|
|
86
|
+
Linux (on the latest Ubuntu LTS release or newer.)
|
|
87
|
+
|
|
88
|
+
## `getdeps.py`
|
|
89
|
+
|
|
90
|
+
This script is used by many of Meta's OSS tools. It will download and build all of the necessary dependencies first, and will then invoke cmake etc to build folly. This will help ensure that you build with relevant versions of all of the dependent libraries, taking into account what versions are installed locally on your system.
|
|
91
|
+
|
|
92
|
+
It's written in python so you'll need python3.6 or later on your PATH. It works on Linux, macOS and Windows.
|
|
93
|
+
|
|
94
|
+
The settings for folly's cmake build are held in its getdeps manifest `build/fbcode_builder/manifests/folly`, which you can edit locally if desired.
|
|
95
|
+
|
|
96
|
+
### Dependencies
|
|
97
|
+
|
|
98
|
+
If on Linux or MacOS (with homebrew installed) you can install system dependencies to save building them:
|
|
99
|
+
|
|
100
|
+
# Clone the repo
|
|
101
|
+
git clone https://github.com/facebook/folly
|
|
102
|
+
# Install dependencies
|
|
103
|
+
cd folly
|
|
104
|
+
sudo ./build/fbcode_builder/getdeps.py install-system-deps --recursive
|
|
105
|
+
|
|
106
|
+
If you'd like to see the packages before installing them:
|
|
107
|
+
|
|
108
|
+
./build/fbcode_builder/getdeps.py install-system-deps --dry-run --recursive
|
|
109
|
+
|
|
110
|
+
On other platforms or if on Linux and without system dependencies `getdeps.py` will mostly download and build them for you during the build step.
|
|
111
|
+
|
|
112
|
+
Some of the dependencies `getdeps.py` uses and installs are:
|
|
113
|
+
|
|
114
|
+
* a version of boost compiled with C++14 support.
|
|
115
|
+
* googletest is required to build and run folly's tests.
|
|
116
|
+
|
|
117
|
+
### Build
|
|
118
|
+
|
|
119
|
+
This script will download and build all of the necessary dependencies first,
|
|
120
|
+
and will then invoke cmake etc to build folly. This will help ensure that you build with relevant versions of all of the dependent libraries, taking into account what versions are installed locally on your system.
|
|
121
|
+
|
|
122
|
+
`getdeps.py` currently requires python 3.6+ to be on your path.
|
|
123
|
+
|
|
124
|
+
`getdeps.py` will invoke cmake etc.
|
|
125
|
+
|
|
126
|
+
# Clone the repo
|
|
127
|
+
git clone https://github.com/facebook/folly
|
|
128
|
+
cd folly
|
|
129
|
+
# Build, using system dependencies if available
|
|
130
|
+
python3 ./build/fbcode_builder/getdeps.py --allow-system-packages build
|
|
131
|
+
|
|
132
|
+
It puts output in its scratch area:
|
|
133
|
+
|
|
134
|
+
* `installed/folly/lib/libfolly.a`: Library
|
|
135
|
+
|
|
136
|
+
You can also specify a `--scratch-path` argument to control
|
|
137
|
+
the location of the scratch directory used for the build. You can find the default scratch install location from logs or with `python3 ./build/fbcode_builder/getdeps.py show-inst-dir`.
|
|
138
|
+
|
|
139
|
+
There are also
|
|
140
|
+
`--install-dir` and `--install-prefix` arguments to provide some more
|
|
141
|
+
fine-grained control of the installation directories. However, given that
|
|
142
|
+
folly provides no compatibility guarantees between commits we generally
|
|
143
|
+
recommend building and installing the libraries to a temporary location, and
|
|
144
|
+
then pointing your project's build at this temporary location, rather than
|
|
145
|
+
installing folly in the traditional system installation directories. e.g., if you are building with CMake you can use the `CMAKE_PREFIX_PATH` variable to allow CMake to find folly in this temporary installation directory when
|
|
146
|
+
building your project.
|
|
147
|
+
|
|
148
|
+
If you want to invoke `cmake` again to iterate, there is a helpful `run_cmake.py` script output in the scratch build directory. You can find the scratch build directory from logs or with `python3 ./build/fbcode_builder/getdeps.py show-build-dir`.
|
|
149
|
+
|
|
150
|
+
### Run tests
|
|
151
|
+
|
|
152
|
+
By default `getdeps.py` will build the tests for folly. To run them:
|
|
153
|
+
|
|
154
|
+
cd folly
|
|
155
|
+
python3 ./build/fbcode_builder/getdeps.py --allow-system-packages test
|
|
156
|
+
|
|
157
|
+
### `build.sh`/`build.bat` wrapper
|
|
158
|
+
|
|
159
|
+
`build.sh` can be used on Linux and MacOS, on Windows use
|
|
160
|
+
the `build.bat` script instead. Its a wrapper around `getdeps.py`.
|
|
161
|
+
|
|
162
|
+
## Build with cmake directly
|
|
163
|
+
|
|
164
|
+
If you don't want to let getdeps invoke cmake for you then by default, building the tests is disabled as part of the CMake `all` target.
|
|
165
|
+
To build the tests, specify `-DBUILD_TESTS=ON` to CMake at configure time.
|
|
166
|
+
|
|
167
|
+
NB if you want to invoke `cmake` again to iterate on a `getdeps.py` build, there is a helpful `run_cmake.py` script output in the scratch-path build directory. You can find the scratch build directory from logs or with `python3 ./build/fbcode_builder/getdeps.py show-build-dir`.
|
|
168
|
+
|
|
169
|
+
Running tests with ctests also works if you cd to the build dir, e.g.
|
|
170
|
+
`(cd $(python3 ./build/fbcode_builder/getdeps.py show-build-dir) && ctest)`
|
|
171
|
+
|
|
172
|
+
### Finding dependencies in non-default locations
|
|
173
|
+
|
|
174
|
+
If you have boost, gtest, or other dependencies installed in a non-default
|
|
175
|
+
location, you can use the `CMAKE_INCLUDE_PATH` and `CMAKE_LIBRARY_PATH`
|
|
176
|
+
variables to make CMAKE look also look for header files and libraries in
|
|
177
|
+
non-standard locations. For example, to also search the directories
|
|
178
|
+
`/alt/include/path1` and `/alt/include/path2` for header files and the
|
|
179
|
+
directories `/alt/lib/path1` and `/alt/lib/path2` for libraries, you can invoke
|
|
180
|
+
`cmake` as follows:
|
|
181
|
+
|
|
182
|
+
```
|
|
183
|
+
cmake \
|
|
184
|
+
-DCMAKE_INCLUDE_PATH=/alt/include/path1:/alt/include/path2 \
|
|
185
|
+
-DCMAKE_LIBRARY_PATH=/alt/lib/path1:/alt/lib/path2 ...
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Ubuntu LTS, CentOS Stream, Fedora
|
|
189
|
+
|
|
190
|
+
Use the `getdeps.py` approach above. We test in CI on Ubuntu LTS, and occasionally on other distros.
|
|
191
|
+
|
|
192
|
+
If you find the set of system packages is not quite right for your chosen distro, you can specify distro version specific overrides in the dependency manifests (e.g. https://github.com/facebook/folly/blob/main/build/fbcode_builder/manifests/boost ). You could probably make it work on most recent Ubuntu/Debian or Fedora/Redhat derived distributions.
|
|
193
|
+
|
|
194
|
+
At time of writing (Dec 2021) there is a build break on GCC 11.x based systems in lang_badge_test. If you don't need badge functionality you can work around by commenting it out from CMakeLists.txt (unfortunately fbthrift does need it)
|
|
195
|
+
|
|
196
|
+
## Windows (Vcpkg)
|
|
197
|
+
|
|
198
|
+
Note that many tests are disabled for folly Windows builds, you can see them in the log from the cmake configure step, or by looking for WINDOWS_DISABLED in `CMakeLists.txt`
|
|
199
|
+
|
|
200
|
+
That said, `getdeps.py` builds work on Windows and are tested in CI.
|
|
201
|
+
|
|
202
|
+
If you prefer, you can try Vcpkg. folly is available in [Vcpkg](https://github.com/Microsoft/vcpkg#vcpkg) and releases may be built via `vcpkg install folly:x64-windows`.
|
|
203
|
+
|
|
204
|
+
You may also use `vcpkg install folly:x64-windows --head` to build against `main`.
|
|
205
|
+
|
|
206
|
+
## macOS
|
|
207
|
+
|
|
208
|
+
`getdeps.py` builds work on macOS and are tested in CI, however if you prefer, you can try one of the macOS package managers
|
|
209
|
+
|
|
210
|
+
### Homebrew
|
|
211
|
+
|
|
212
|
+
folly is available as a Formula and releases may be built via `brew install folly`.
|
|
213
|
+
|
|
214
|
+
You may also use `folly/build/bootstrap-osx-homebrew.sh` to build against `main`:
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
./folly/build/bootstrap-osx-homebrew.sh
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
This will create a build directory `_build` in the top-level.
|
|
221
|
+
|
|
222
|
+
### MacPorts
|
|
223
|
+
|
|
224
|
+
Install the required packages from MacPorts:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
sudo port install \
|
|
228
|
+
boost \
|
|
229
|
+
cmake \
|
|
230
|
+
gflags \
|
|
231
|
+
git \
|
|
232
|
+
google-glog \
|
|
233
|
+
libevent \
|
|
234
|
+
libtool \
|
|
235
|
+
lz4 \
|
|
236
|
+
lzma \
|
|
237
|
+
openssl \
|
|
238
|
+
snappy \
|
|
239
|
+
xz \
|
|
240
|
+
zlib
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Download and install double-conversion:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
git clone https://github.com/google/double-conversion.git
|
|
247
|
+
cd double-conversion
|
|
248
|
+
cmake -DBUILD_SHARED_LIBS=ON .
|
|
249
|
+
make
|
|
250
|
+
sudo make install
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Download and install folly with the parameters listed below:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
git clone https://github.com/facebook/folly.git
|
|
257
|
+
cd folly
|
|
258
|
+
mkdir _build
|
|
259
|
+
cd _build
|
|
260
|
+
cmake ..
|
|
261
|
+
make
|
|
262
|
+
sudo make install
|
|
263
|
+
```
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
`folly/AtomicHashmap.h`
|
|
2
|
+
----------------------
|
|
3
|
+
|
|
4
|
+
`folly/AtomicHashmap.h` introduces a synchronized UnorderedAssociativeContainer
|
|
5
|
+
implementation designed for extreme performance in heavily multithreaded
|
|
6
|
+
environments (about 2-5x faster than tbb::concurrent_hash_map) and good memory
|
|
7
|
+
usage properties. Find and iteration are wait-free, insert has key-level lock
|
|
8
|
+
granularity, there is minimal memory overhead, and permanent 32-bit ids can be
|
|
9
|
+
used to reference each element.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Limitations
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
Although it can provide extreme performance, AtomicHashmap has some unique
|
|
16
|
+
limitations as well.
|
|
17
|
+
|
|
18
|
+
* The space for erased elements cannot be reclaimed (they are tombstoned
|
|
19
|
+
forever) so it's generally not a good idea to use this if you're erasing things
|
|
20
|
+
a lot.
|
|
21
|
+
|
|
22
|
+
* Only supports 32 or 64 bit keys - this is because they must be atomically
|
|
23
|
+
compare-and-swap'ed.
|
|
24
|
+
|
|
25
|
+
* Growth beyond initialization reduces performance - if you don't know
|
|
26
|
+
the approximate number of elements you'll be inserting into the map, you
|
|
27
|
+
probably shouldn't use this class.
|
|
28
|
+
|
|
29
|
+
* Must manage synchronization externally in order to modify values in the map
|
|
30
|
+
after insertion. Lock pools are a common way to do this, or you may
|
|
31
|
+
consider using `folly::PackedSyncPtr<T>` as your `ValueT`.
|
|
32
|
+
|
|
33
|
+
* Must define special reserved key values for empty, erased, and locked
|
|
34
|
+
elements.
|
|
35
|
+
|
|
36
|
+
For a complete list of limitations and departures from the
|
|
37
|
+
UnorderedAssociativeContainer concept, see `folly/AtomicHashMap.h`
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
### Unique Features
|
|
41
|
+
***
|
|
42
|
+
|
|
43
|
+
* `value_type` references remain valid as long as the map itself. Note this is
|
|
44
|
+
not true for most other probing hash maps which will move elements when
|
|
45
|
+
rehashing, which is necessary for them to grow. AtomicHashMap grows by chaining
|
|
46
|
+
additional slabs, so elements never need to be moved.
|
|
47
|
+
|
|
48
|
+
* Unique 32-bit ids can be used to reference elements in the map via
|
|
49
|
+
`iterator::getIndex()`. This can be helpful to save memory in the rest of the
|
|
50
|
+
application by replacing 64-bit pointers or keys.
|
|
51
|
+
|
|
52
|
+
* Iterators are never invalidated. This means you can iterate through the map
|
|
53
|
+
while simultaneously inserting and erasing. This is particularly useful for
|
|
54
|
+
non-blocking map serialization.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
### Usage
|
|
58
|
+
***
|
|
59
|
+
|
|
60
|
+
Usage is similar to most maps, although note the conspicuous lack of operator[]
|
|
61
|
+
which encourages non thread-safe access patterns.
|
|
62
|
+
|
|
63
|
+
Below is a synchronized key counter implementation that allows the counter
|
|
64
|
+
values to be incremented in parallel with serializing all the values to a
|
|
65
|
+
string.
|
|
66
|
+
|
|
67
|
+
```Cpp
|
|
68
|
+
class Counters {
|
|
69
|
+
private:
|
|
70
|
+
AtomicHashMap<int64_t,int64_t> ahm;
|
|
71
|
+
|
|
72
|
+
public:
|
|
73
|
+
explicit Counters(size_t numCounters) : ahm(numCounters) {}
|
|
74
|
+
|
|
75
|
+
void increment(int64_t obj_id) {
|
|
76
|
+
auto ret = ahm.insert(make_pair(obj_id, 1));
|
|
77
|
+
if (!ret.second) {
|
|
78
|
+
// obj_id already exists, increment
|
|
79
|
+
NoBarrier_AtomicIncrement(&ret.first->second, 1);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
int64_t getValue(int64_t obj_id) {
|
|
84
|
+
auto ret = ahm.find(obj_id);
|
|
85
|
+
return ret != ahm.end() ? ret->second : 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Serialize the counters without blocking increments
|
|
89
|
+
string toString() {
|
|
90
|
+
string ret = "{\n";
|
|
91
|
+
ret.reserve(ahm.size() * 32);
|
|
92
|
+
for (const auto& e : ahm) {
|
|
93
|
+
ret += folly::to<string>(
|
|
94
|
+
" [", e.first, ":", NoBarrier_Load(&e.second), "]\n");
|
|
95
|
+
}
|
|
96
|
+
ret += "}\n";
|
|
97
|
+
return ret;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Implementation
|
|
103
|
+
***
|
|
104
|
+
|
|
105
|
+
AtomicHashMap is a composition of AtomicHashArray submaps, which implement the
|
|
106
|
+
meat of the functionality. Only one AHA is created on initialization, and
|
|
107
|
+
additional submaps are appended if the first one gets full. If the AHM grows,
|
|
108
|
+
there will be multiple submaps that must be probed in series to find a given
|
|
109
|
+
key. The more growth, the more submaps will be chained, and the slower it will
|
|
110
|
+
get. If the initial size estimate is good, only one submap will ever be created
|
|
111
|
+
and performance will be optimal.
|
|
112
|
+
|
|
113
|
+
AtomicHashArray is a fixed-size probing hash map (also referred to as an open
|
|
114
|
+
addressed hash map) where hash collisions are resolved by checking subsequent
|
|
115
|
+
elements. This means that they can be allocated in slabs as arrays of
|
|
116
|
+
value_type elements, have excellent cache performance, and have no memory
|
|
117
|
+
overhead from storing pointers.
|
|
118
|
+
|
|
119
|
+
The algorithm is simple - when inserting, the key is hash-mod'ed to an offset,
|
|
120
|
+
and that element-key is atomically compare-and-swap'ed with the locked key
|
|
121
|
+
value. If successful, the value is written and the element-key is unlocked by
|
|
122
|
+
setting it to the input key value. If the compare fails, the next element is
|
|
123
|
+
tried until success or the map is full.
|
|
124
|
+
|
|
125
|
+
Finds are even simpler. The key is hash-mod'ed to an offset, and the
|
|
126
|
+
element-key is examined. If it is the same as the input key, the reference is
|
|
127
|
+
returned, if it's the empty key, failure is returned, otherwise the next key is
|
|
128
|
+
tried. This can be done wait-free without any atomic instructions because the
|
|
129
|
+
elements are always in a valid state.
|
|
130
|
+
|
|
131
|
+
Erase is done by finding the key, then compare-and-swap'ing the element-key with
|
|
132
|
+
the reserved erased key value. If the swap succeeds, return success, otherwise
|
|
133
|
+
return failure (the element was erased by a competing thread). If the key does
|
|
134
|
+
not exist, return failure.
|