├── folly
├── VERSION
├── docs
│ ├── .gitignore
│ ├── Fbvector--graphical_solutions.png
│ ├── style.css
│ ├── Makefile
│ ├── SmallLocks.md
│ └── FBString.md
├── test
│ ├── .gitignore
│ ├── json_test_data
│ │ ├── commented.json.exp
│ │ └── commented.json
│ ├── function_benchmark
│ │ ├── Makefile.am
│ │ ├── test_functions.h
│ │ ├── benchmark_impl.cpp
│ │ ├── benchmark_impl.h
│ │ └── test_functions.cpp
│ ├── CpuIdTest.cpp
│ ├── SafeAssertTest.cpp
│ ├── AsciiCaseInsensitiveTest.cpp
│ ├── FileTestLockHelper.cpp
│ ├── PortabilityTest.cpp
│ ├── HistogramBenchmark.cpp
│ ├── MoveWrapperTest.cpp
│ ├── SynchronizedTestLib.h
│ ├── AtomicBitSetTest.cpp
│ ├── DemangleTest.cpp
│ ├── DeterministicScheduleTest.cpp
│ ├── SingletonVaultCTest.cpp
│ ├── EndianTest.cpp
│ ├── MapUtilTest.cpp
│ └── MergeTest.cpp
├── wangle
│ ├── codec
│ │ ├── README.md
│ │ ├── ByteToMessageCodec.cpp
│ │ ├── StringCodec.h
│ │ ├── FixedLengthFrameDecoder.h
│ │ ├── LineBasedFrameDecoder.h
│ │ ├── ByteToMessageCodec.h
│ │ └── LengthFieldPrepender.h
│ ├── ssl
│ │ ├── TLSTicketKeySeeds.h
│ │ ├── SSLCacheOptions.h
│ │ ├── ClientHelloExtStats.h
│ │ ├── PasswordInFile.cpp
│ │ ├── PasswordInFile.h
│ │ └── SSLStats.h
│ ├── acceptor
│ │ ├── SocketOptions.h
│ │ ├── SocketOptions.cpp
│ │ ├── LoadShedConfiguration.cpp
│ │ ├── ConnectionCounter.h
│ │ ├── NetworkAddress.h
│ │ ├── DomainNameMisc.h
│ │ ├── TransportInfo.cpp
│ │ └── ManagedConnection.cpp
│ ├── rx
│ │ ├── Dummy.cpp
│ │ ├── types.h
│ │ ├── Subject.h
│ │ ├── Subscription.h
│ │ └── README.md
│ ├── concurrent
│ │ ├── ThreadFactory.h
│ │ ├── BlockingQueue.h
│ │ ├── test
│ │ │ └── CodelTest.cpp
│ │ ├── LifoSemMPMCQueue.h
│ │ ├── NamedThreadFactory.h
│ │ ├── FiberIOExecutor.h
│ │ ├── IOExecutor.h
│ │ └── GlobalExecutor.h
│ ├── service
│ │ └── ServerDispatcher.h
│ └── channel
│ │ └── EventBaseHandler.h
├── experimental
│ ├── io
│ │ ├── test
│ │ │ └── Makefile.am
│ │ ├── FsUtil.cpp
│ │ └── FsUtil.h
│ ├── symbolizer
│ │ ├── test
│ │ │ ├── Crash.cpp
│ │ │ └── SignalHandlerTest.h
│ │ ├── ElfUtil.cpp
│ │ ├── StackTrace.h
│ │ └── SignalHandler.h
│ ├── fibers
│ │ ├── GenericBaton.h
│ │ ├── FiberManagerMap.h
│ │ ├── GuardPageAllocator.h
│ │ ├── test
│ │ │ └── main.cpp
│ │ ├── ExecutionObserver.h
│ │ ├── ForEach.h
│ │ ├── LoopController.h
│ │ └── EventBaseLoopController.h
│ ├── SharedMutex.cpp
│ ├── exception_tracer
│ │ ├── README.md
│ │ ├── ExceptionTracerBenchmark.cpp
│ │ ├── ExceptionTracer.h
│ │ └── ExceptionAbi.h
│ ├── StringKeyedCommon.h
│ └── JSONSchemaTester.cpp
├── futures
│ ├── exercises
│ │ ├── README.md
│ │ ├── Koan.h
│ │ └── main.cpp
│ ├── InlineExecutor.cpp
│ ├── Deprecated.h
│ ├── detail
│ │ ├── Types.h
│ │ └── ThreadWheelTimekeeper.h
│ ├── test
│ │ ├── ClientCompile.cpp
│ │ ├── main.cpp
│ │ ├── UnitTest.cpp
│ │ ├── SugarTest.cpp
│ │ ├── thens.rb
│ │ └── Try.cpp
│ ├── InlineExecutor.h
│ ├── QueuedImmediateExecutor.h
│ ├── QueuedImmediateExecutor.cpp
│ ├── Unit.h
│ ├── DrivableExecutor.h
│ ├── Future.cpp
│ ├── OpaqueCallbackShunt.h
│ └── ScheduledExecutor.h
├── Version.cpp
├── detail
│ ├── ExceptionWrapper.h
│ ├── MallocImpl.cpp
│ ├── FunctionalExcept.h
│ ├── FunctionalExcept.cpp
│ ├── Clock.h
│ ├── AtomicHashUtils.h
│ ├── BitsDetail.h
│ ├── Malloc.h
│ └── Clock.cpp
├── io
│ └── async
│ │ ├── AsyncSocketBase.h
│ │ ├── Request.cpp
│ │ ├── test
│ │ ├── certs
│ │ │ ├── tests-cert.pem
│ │ │ ├── ca-cert.pem
│ │ │ └── tests-key.pem
│ │ ├── SocketPair.h
│ │ ├── MockAsyncSocket.h
│ │ └── MockAsyncServerSocket.h
│ │ └── EventUtil.h
├── GroupVarint.cpp
├── Chrono.h
├── gen
│ ├── Core.h
│ ├── Combine.h
│ ├── test
│ │ └── Bench.h
│ └── ParallelMap.h
├── Unicode.h
├── Likely.h
├── StringBase.cpp
├── bootstrap-osx-homebrew.sh
├── SingletonVault_c.h
├── SingletonVault_c.cpp
├── Checksum.h
├── ThreadName.h
├── SpinLock.h
├── Uri-inl.h
├── LifoSem.cpp
├── ThreadCachedArena.cpp
├── SafeAssert.cpp
├── SingletonStackTrace.cpp
├── Unicode.cpp
├── SafeAssert.h
├── Executor.h
└── CPortability.h
└── .gitignore
/folly/VERSION:
--------------------------------------------------------------------------------
1 | 40:0
2 |
--------------------------------------------------------------------------------
/folly/docs/.gitignore:
--------------------------------------------------------------------------------
1 | *.html
2 |
--------------------------------------------------------------------------------
/folly/test/.gitignore:
--------------------------------------------------------------------------------
1 | *.log
2 | *.trs
3 | gtest*/*
4 |
--------------------------------------------------------------------------------
/folly/docs/Fbvector--graphical_solutions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/clearlinux/folly/master/folly/docs/Fbvector--graphical_solutions.png
--------------------------------------------------------------------------------
/folly/test/json_test_data/commented.json.exp:
--------------------------------------------------------------------------------
1 | {
2 | "test": "foo", "test2": "foo // bar",
3 | "test4": "foo /* bar",
4 | "te//": "foo",
5 | "te/*": "bar",
6 | "\\\"": "\\"
7 | }
8 |
--------------------------------------------------------------------------------
/folly/docs/style.css:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/folly/wangle/codec/README.md:
--------------------------------------------------------------------------------
1 | Codecs are modeled after netty's codecs:
2 |
3 | https://github.com/netty/netty/tree/master/codec/src/main/java/io/netty/handler/codec
4 |
5 | Most of the changes are due to differing memory allocation strategies.
--------------------------------------------------------------------------------
/folly/test/json_test_data/commented.json:
--------------------------------------------------------------------------------
1 | {
2 | // comment
3 | "test": "foo", // comment
4 | "test2": "foo // bar", // more comments
5 | /*
6 | "test3": "baz"
7 | */
8 | "test4": "foo /* bar", /* comment */
9 | "te//": "foo",
10 | "te/*": "bar",
11 | "\\\"": "\\" /* comment */
12 | }
13 |
--------------------------------------------------------------------------------
/folly/test/function_benchmark/Makefile.am:
--------------------------------------------------------------------------------
1 | ACLOCAL_AMFLAGS = -I m4
2 |
3 | # depends on libfollybenchmark
4 |
5 | # TESTS = function_benchmark
6 |
7 | # check_PROGRAMS = $(TESTS)
8 |
9 | # noinst_HEADERS = test_functions.h benchmark_impl.h
10 |
11 | # function_benchmark_SOURCES = benchmark_impl.cpp main.cpp test_functions.cpp
12 |
--------------------------------------------------------------------------------
/folly/experimental/io/test/Makefile.am:
--------------------------------------------------------------------------------
1 | ACLOCAL_AMFLAGS = -I m4
2 |
3 | TESTS = iobuf_test \
4 | iobuf_cursor_test
5 |
6 | check_PROGRAMS = $(TESTS)
7 |
8 | iobuf_test_SOURCES = IOBufTest.cpp
9 | iobuf_test_LDADD = $(top_builddir)/libfollyio.la
10 |
11 | iobuf_cursor_test_SOURCES = IOBufCursorTest.cpp
12 | iobuf_cursor_test_LDADD = $(top_builddir)/libfollyio.la $(top_builddir)/libfollybenchmark.la
13 |
--------------------------------------------------------------------------------
/folly/futures/exercises/README.md:
--------------------------------------------------------------------------------
1 | Working through [Programming Koans][1] can be a fun, lightweight, and fast way to
2 | learn a new language or pattern with small, focused exercises. Therefore, we
3 | present Koans for Futures. Perhaps you will call them "Koans to Be".
4 |
5 | Edit the topical files one at a time, moving the "compilation cursor" down one
6 | exercise at a time, and getting them to pass by filling in the blanks.
7 |
8 | [1] http://www.lauradhamilton.com/learn-a-new-programming-language-today-with-koans
9 | [2] http://catb.org/esr/writings/unix-koans/ten-thousand.html
10 |
--------------------------------------------------------------------------------
/folly/wangle/ssl/TLSTicketKeySeeds.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | namespace folly {
13 |
14 | struct TLSTicketKeySeeds {
15 | std::vector oldSeeds;
16 | std::vector currentSeeds;
17 | std::vector newSeeds;
18 | };
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/folly/wangle/ssl/SSLCacheOptions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | #include
13 | #include
14 |
15 | namespace folly {
16 |
17 | struct SSLCacheOptions {
18 | std::chrono::seconds sslCacheTimeout;
19 | uint64_t maxSSLCacheSize;
20 | uint64_t sslCacheFlushSize;
21 | };
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.o
2 | *.lo
3 | *.la
4 | .dirstamp
5 | Makefile
6 | Makefile.in
7 | .libs
8 | .deps
9 | stamp-h1
10 | folly-config.h
11 | _configs.sed
12 | aclocal.m4
13 | autom4te.cache
14 | build-aux
15 | libtool
16 | folly/test/gtest-1.6.0
17 | folly/folly-config.h
18 | folly/test/*_benchmark
19 | folly/test/*_test
20 | folly/test/*_test_using_jemalloc
21 | folly/config.*
22 | folly/configure
23 | folly/m4/libtool.m4
24 | folly/m4/ltoptions.m4
25 | folly/m4/ltsugar.m4
26 | folly/m4/ltversion.m4
27 | folly/m4/lt~obsolete.m4
28 | folly/generate_fingerprint_tables
29 | folly/FormatTables.cpp
30 | folly/EscapeTables.cpp
31 | folly/GroupVarintTables.cpp
32 | folly/FingerprintTables.cpp
33 |
--------------------------------------------------------------------------------
/folly/futures/InlineExecutor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
--------------------------------------------------------------------------------
/folly/wangle/ssl/ClientHelloExtStats.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | namespace folly {
13 |
14 | class ClientHelloExtStats {
15 | public:
16 | virtual ~ClientHelloExtStats() noexcept {}
17 |
18 | // client hello
19 | virtual void recordAbsentHostname() noexcept = 0;
20 | virtual void recordMatch() noexcept = 0;
21 | virtual void recordNotMatch() noexcept = 0;
22 | };
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/folly/wangle/acceptor/SocketOptions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | #include
13 |
14 | namespace folly {
15 |
16 | /**
17 | * Returns a copy of the socket options excluding options with the given
18 | * level.
19 | */
20 | AsyncSocket::OptionMap filterIPSocketOptions(
21 | const AsyncSocket::OptionMap& allOptions,
22 | const int addrFamily);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/folly/futures/Deprecated.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 | #define DEPRECATED __attribute__((__deprecated__))
19 |
--------------------------------------------------------------------------------
/folly/futures/exercises/Koan.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 | #include
18 | #include
19 | #include
20 |
--------------------------------------------------------------------------------
/folly/futures/detail/Types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly {
22 |
23 | using Duration = std::chrono::milliseconds;
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/folly/Version.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | namespace folly { namespace detail {
20 |
21 | FOLLY_VERSION_CHECK(folly, FOLLY_VERSION)
22 |
23 | }} // namespaces
24 |
--------------------------------------------------------------------------------
/folly/wangle/rx/Dummy.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // fbbuild is too dumb to know that .h files in the directory affect
18 | // our project, unless we have a .cpp file in the target, in the same
19 | // directory.
20 |
--------------------------------------------------------------------------------
/folly/docs/Makefile:
--------------------------------------------------------------------------------
1 | SOURCES=$(wildcard *.md)
2 | PDF=$(SOURCES:%.md=%.pdf)
3 | HTML=$(SOURCES:%.md=%.html)
4 | INSTALL=install -c -m 644
5 | PYTHON=python
6 | PANDOCARGS=-s
7 | PANDOC=/usr/bin/pandoc
8 |
9 | export LANGUAGE=C
10 | export LC_ALL=C
11 |
12 | all: html index.html
13 |
14 | pdf: $(PDF)
15 |
16 | html: $(HTML)
17 |
18 | # This needs pandoc 1.9 or later to work
19 | %.pdf: %.md
20 | $(PANDOC) -f markdown -o $*.pdf $*.md
21 |
22 | %.html: %.md style.css
23 | $(PANDOC) $(PANDOCARGS) -H style.css -f markdown -t html --toc -o $*.html $*.md
24 |
25 | docs.md: $(SOURCES) style.css
26 | $(PANDOC) $(PANDOCARGS) -H style.css -f markdown -t markdown --toc -o $@ *.md
27 |
28 | index.html: $(SOURCES) style.css
29 | $(PANDOC) $(PANDOCARGS) -H style.css -f markdown -t html --toc -o $@ *.md
30 |
31 |
32 | clean:
33 | $(RM) $(PDF) $(HTML) index.html
34 |
--------------------------------------------------------------------------------
/folly/experimental/symbolizer/test/Crash.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | int main() {
20 | folly::symbolizer::installFatalSignalHandler();
21 | __builtin_trap();
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/folly/futures/exercises/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include "Koan.h"
17 |
18 | int main(int argc, char** argv) {
19 | ::testing::InitGoogleTest(&argc, argv);
20 | ::gflags::ParseCommandLineFlags(&argc, &argv, true);
21 | return RUN_ALL_TESTS();
22 | }
23 |
--------------------------------------------------------------------------------
/folly/experimental/fibers/GenericBaton.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 |
20 | #include
21 |
22 | namespace folly { namespace fibers {
23 |
24 | typedef Baton GenericBaton;
25 |
26 | }}
27 |
--------------------------------------------------------------------------------
/folly/wangle/ssl/PasswordInFile.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #include
11 |
12 | #include
13 |
14 | using namespace std;
15 |
16 | namespace folly {
17 |
18 | PasswordInFile::PasswordInFile(const string& file)
19 | : fileName_(file) {
20 | folly::readFile(file.c_str(), password_);
21 | auto p = password_.find('\0');
22 | if (p != std::string::npos) {
23 | password_.erase(p);
24 | }
25 | }
26 |
27 | PasswordInFile::~PasswordInFile() {
28 | OPENSSL_cleanse((char *)password_.data(), password_.length());
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/folly/experimental/SharedMutex.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include "SharedMutex.h"
18 |
19 | COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(
20 | folly::SharedMutexReadPriority);
21 | COMMON_CONCURRENCY_SHARED_MUTEX_DECLARE_STATIC_STORAGE(
22 | folly::SharedMutexWritePriority);
23 |
--------------------------------------------------------------------------------
/folly/futures/test/ClientCompile.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // amazing what things can go wrong if you include things in an unexpected
18 | // order.
19 | #include
20 | #include
21 | #include
22 | int main() { return 0; }
23 |
--------------------------------------------------------------------------------
/folly/test/CpuIdTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 | #include
21 |
22 | using namespace folly;
23 |
24 | TEST(CpuId, Simple) {
25 | // All CPUs should support MMX
26 | CpuId id;
27 | EXPECT_TRUE(id.mmx());
28 | }
29 |
--------------------------------------------------------------------------------
/folly/futures/test/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | int main(int argc, char** argv) {
22 | ::testing::InitGoogleTest(&argc, argv);
23 | ::gflags::ParseCommandLineFlags(&argc, &argv, true);
24 | return RUN_ALL_TESTS();
25 | }
26 |
--------------------------------------------------------------------------------
/folly/wangle/concurrent/ThreadFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 | #include
19 |
20 | #include
21 |
22 | namespace folly { namespace wangle {
23 |
24 | class ThreadFactory {
25 | public:
26 | virtual ~ThreadFactory() {}
27 | virtual std::thread newThread(Func&& func) = 0;
28 | };
29 |
30 | }} // folly::wangle
31 |
--------------------------------------------------------------------------------
/folly/detail/ExceptionWrapper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_DETAIL_EXCEPTIONWRAPPER_H
18 | #define FOLLY_DETAIL_EXCEPTIONWRAPPER_H
19 |
20 | namespace folly { namespace detail {
21 |
22 | template
23 | class Thrower {
24 | public:
25 | static void doThrow(std::exception* obj) {
26 | throw *static_cast(obj);
27 | }
28 | };
29 |
30 | }}
31 |
32 | #endif
33 |
--------------------------------------------------------------------------------
/folly/experimental/fibers/FiberManagerMap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 | #include
20 |
21 | namespace folly { namespace fibers {
22 |
23 | FiberManager& getFiberManager(
24 | folly::EventBase& evb,
25 | const FiberManager::Options& opts = FiberManager::Options());
26 |
27 | }}
28 |
--------------------------------------------------------------------------------
/folly/wangle/ssl/PasswordInFile.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | #include // PasswordCollector
13 |
14 | namespace folly {
15 |
16 | class PasswordInFile: public folly::PasswordCollector {
17 | public:
18 | explicit PasswordInFile(const std::string& file);
19 | ~PasswordInFile();
20 |
21 | void getPassword(std::string& password, int size) override {
22 | password = password_;
23 | }
24 |
25 | const char* getPasswordStr() const {
26 | return password_.c_str();
27 | }
28 |
29 | std::string describe() const override {
30 | return fileName_;
31 | }
32 |
33 | protected:
34 | std::string fileName_;
35 | std::string password_;
36 | };
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/folly/io/async/AsyncSocketBase.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 | #include
20 |
21 | namespace folly {
22 |
23 | class AsyncSocketBase {
24 | public:
25 | virtual EventBase* getEventBase() const = 0;
26 | virtual ~AsyncSocketBase() = default;
27 | virtual void getAddress(SocketAddress*) const = 0;
28 | };
29 |
30 | } // namespace
31 |
--------------------------------------------------------------------------------
/folly/io/async/Request.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 | #include
22 |
23 | namespace folly {
24 |
25 | RequestContext* defaultContext;
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/folly/experimental/symbolizer/test/SignalHandlerTest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_SYMBOLIZER_TEST_SIGNALHANDLERTEST_H_
18 | #define FOLLY_SYMBOLIZER_TEST_SIGNALHANDLERTEST_H_
19 |
20 | namespace folly { namespace symbolizer { namespace test {
21 |
22 | inline void failHard() {
23 | *(/* nolint */ volatile char*)42; // SIGSEGV
24 | }
25 |
26 | }}} // namespaces
27 |
28 | #endif /* FOLLY_SYMBOLIZER_TEST_SIGNALHANDLERTEST_H_ */
29 |
--------------------------------------------------------------------------------
/folly/futures/InlineExecutor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 | #include
19 |
20 | namespace folly {
21 |
22 | /// When work is "queued", execute it immediately inline.
23 | /// Usually when you think you want this, you actually want a
24 | /// QueuedImmediateExecutor.
25 | class InlineExecutor : public Executor {
26 | public:
27 | void add(Func f) override {
28 | f();
29 | }
30 | };
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/folly/GroupVarint.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #if HAVE_GROUP_VARINT
20 | namespace folly {
21 |
22 | const uint32_t GroupVarint32::kMask[] = {
23 | 0xff, 0xffff, 0xffffff, 0xffffffff
24 | };
25 |
26 | const uint64_t GroupVarint64::kMask[] = {
27 | 0xff, 0xffff, 0xffffff, 0xffffffff,
28 | 0xffffffffffULL, 0xffffffffffffULL, 0xffffffffffffffULL,
29 | 0xffffffffffffffffULL
30 | };
31 |
32 | } // namespace folly
33 | #endif
34 |
--------------------------------------------------------------------------------
/folly/docs/SmallLocks.md:
--------------------------------------------------------------------------------
1 | `folly/SmallLocks.h`
2 | --------------------
3 |
4 | This module is currently x64 only.
5 |
6 | This header defines two very small mutex types. These are useful in
7 | highly memory-constrained environments where contention is unlikely.
8 | The purpose of these is to allow fine-grained locking in massive data
9 | structures where memory is at a premium. Often, each record may have
10 | a spare bit or byte lying around, so sometimes these can be tacked on
11 | with no additional memory cost.
12 |
13 | There are two types exported from this header. `MicroSpinLock` is a
14 | single byte lock, and `PicoSpinLock` can be wrapped around an
15 | integer to use a single bit as a lock. Why do we have both?
16 | Because you can't use x64 `bts` on a single byte, so
17 | `sizeof(MicroSpinLock)` is smaller than `sizeof(PicoSpinLock)` can
18 | be, giving it some use cases.
19 |
20 | Both the locks in this header model the C++11 Lockable concept. So
21 | you can use `std::lock_guard` or `std::unique_lock` to lock them in an
22 | RAII way if you want.
23 |
24 | Additional information is in the header.
25 |
--------------------------------------------------------------------------------
/folly/experimental/fibers/GuardPageAllocator.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | namespace folly { namespace fibers {
19 |
20 | /**
21 | * Stack allocator that protects an extra memory page after
22 | * the end of the stack.
23 | */
24 | class GuardPageAllocator {
25 | public:
26 | inline unsigned char* allocate(size_t size);
27 | inline void deallocate(unsigned char* up, size_t size);
28 | };
29 |
30 | }} // folly::fibers
31 |
32 | #include "GuardPageAllocator-inl.h"
33 |
--------------------------------------------------------------------------------
/folly/experimental/fibers/test/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 |
18 | #include
19 |
20 | // for backward compatibility with gflags
21 | namespace gflags { }
22 | namespace google { using namespace gflags; }
23 |
24 | int main(int argc, char** argv) {
25 | testing::InitGoogleTest(&argc, argv);
26 | gflags::ParseCommandLineFlags(&argc, &argv, true);
27 |
28 | auto rc = RUN_ALL_TESTS();
29 | folly::runBenchmarksOnFlag();
30 | return rc;
31 | }
32 |
--------------------------------------------------------------------------------
/folly/test/SafeAssertTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 | #include
21 |
22 | #include
23 |
24 | using namespace folly;
25 |
26 | void fail() {
27 | FOLLY_SAFE_CHECK(0, "hello");
28 | }
29 |
30 | void succeed() {
31 | FOLLY_SAFE_CHECK(1, "world");
32 | }
33 |
34 | TEST(SafeAssert, AssertionFailure) {
35 | succeed();
36 | EXPECT_DEATH(fail(), ".*Assertion failure:.*hello.*");
37 | }
38 |
--------------------------------------------------------------------------------
/folly/wangle/codec/ByteToMessageCodec.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 |
18 | namespace folly { namespace wangle {
19 |
20 | void ByteToMessageCodec::read(Context* ctx, IOBufQueue& q) {
21 | size_t needed = 0;
22 | std::unique_ptr result;
23 | while (true) {
24 | result = decode(ctx, q, needed);
25 | if (result) {
26 | ctx->fireRead(std::move(result));
27 | } else {
28 | break;
29 | }
30 | }
31 | }
32 |
33 | }} // namespace
34 |
--------------------------------------------------------------------------------
/folly/futures/QueuedImmediateExecutor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly {
22 |
23 | /**
24 | * Runs inline like InlineExecutor, but with a queue so that any tasks added
25 | * to this executor by one of its own callbacks will be queued instead of
26 | * executed inline (nested). This is usually better behavior than Inline.
27 | */
28 | class QueuedImmediateExecutor : public Executor {
29 | public:
30 | void add(Func) override;
31 | };
32 |
33 | } // folly
34 |
--------------------------------------------------------------------------------
/folly/wangle/acceptor/SocketOptions.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | namespace folly {
16 |
17 | AsyncSocket::OptionMap filterIPSocketOptions(
18 | const AsyncSocket::OptionMap& allOptions,
19 | const int addrFamily) {
20 | AsyncSocket::OptionMap opts;
21 | int exclude;
22 | if (addrFamily == AF_INET) {
23 | exclude = IPPROTO_IPV6;
24 | } else if (addrFamily == AF_INET6) {
25 | exclude = IPPROTO_IP;
26 | } else {
27 | LOG(FATAL) << "Address family " << addrFamily << " was not IPv4 or IPv6";
28 | return opts;
29 | }
30 | for (const auto& opt: allOptions) {
31 | if (opt.first.level != exclude) {
32 | opts[opt.first] = opt.second;
33 | }
34 | }
35 | return opts;
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/folly/futures/QueuedImmediateExecutor.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 |
21 | namespace folly {
22 |
23 | void QueuedImmediateExecutor::add(Func callback) {
24 | thread_local std::queue q;
25 |
26 | if (q.empty()) {
27 | q.push(std::move(callback));
28 | while (!q.empty()) {
29 | q.front()();
30 | q.pop();
31 | }
32 | } else {
33 | q.push(callback);
34 | }
35 | }
36 |
37 | } // namespace
38 |
--------------------------------------------------------------------------------
/folly/futures/Unit.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 | namespace folly {
18 |
19 | struct Unit {
20 | template struct Lift : public std::false_type {
21 | using type = T;
22 | };
23 | };
24 |
25 | template <>
26 | struct Unit::Lift : public std::true_type {
27 | using type = Unit;
28 | };
29 |
30 | template
31 | struct is_void_or_unit : public std::conditional<
32 | std::is_void::value || std::is_same::value,
33 | std::true_type,
34 | std::false_type>::type
35 | {};
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/folly/Chrono.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Wrapper around that hides away some gcc 4.6 issues
18 | #ifndef FOLLY_CHRONO_H_
19 | #define FOLLY_CHRONO_H_
20 |
21 | #include
22 | #include
23 |
24 | // gcc 4.6 uses an obsolete name for steady_clock, although the implementation
25 | // is the same
26 | #if __GNUC_PREREQ(4, 6) && !__GNUC_PREREQ(4, 7)
27 | namespace std { namespace chrono {
28 | typedef monotonic_clock steady_clock;
29 | }} // namespaces
30 | #endif
31 |
32 | #endif /* FOLLY_CHRONO_H_ */
33 |
--------------------------------------------------------------------------------
/folly/detail/MallocImpl.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | extern "C" {
20 |
21 | #if !FOLLY_HAVE_WEAK_SYMBOLS
22 | void* (*mallocx)(size_t, int) = nullptr;
23 | void* (*rallocx)(void*, size_t, int) = nullptr;
24 | size_t (*xallocx)(void*, size_t, size_t, int) = nullptr;
25 | size_t (*sallocx)(const void*, int) = nullptr;
26 | void (*dallocx)(void*, int) = nullptr;
27 | size_t (*nallocx)(size_t, int) = nullptr;
28 | int (*mallctl)(const char*, void*, size_t*, void*, size_t) = nullptr;
29 | #endif
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/folly/detail/FunctionalExcept.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_DETAIL_FUNCTIONAL_EXCEPT_H
18 | #define FOLLY_DETAIL_FUNCTIONAL_EXCEPT_H
19 |
20 | #include
21 |
22 | FOLLY_NAMESPACE_STD_BEGIN
23 |
24 | FOLLY_NORETURN void __throw_length_error(const char* msg);
25 | FOLLY_NORETURN void __throw_logic_error(const char* msg);
26 | FOLLY_NORETURN void __throw_out_of_range(const char* msg);
27 |
28 | #ifdef _MSC_VER
29 | FOLLY_NORETURN void __throw_bad_alloc();
30 | #endif
31 |
32 | FOLLY_NAMESPACE_STD_END
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/folly/wangle/concurrent/BlockingQueue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly { namespace wangle {
22 |
23 | template
24 | class BlockingQueue {
25 | public:
26 | virtual ~BlockingQueue() {}
27 | virtual void add(T item) = 0;
28 | virtual void addWithPriority(T item, int8_t priority) {
29 | add(std::move(item));
30 | }
31 | virtual uint8_t getNumPriorities() {
32 | return 1;
33 | }
34 | virtual T take() = 0;
35 | virtual size_t size() = 0;
36 | };
37 |
38 | }} // folly::wangle
39 |
--------------------------------------------------------------------------------
/folly/experimental/exception_tracer/README.md:
--------------------------------------------------------------------------------
1 | Exception tracer library
2 |
3 | This library allows you to inspect the exception stack at runtime.
4 | The library can be used in three ways:
5 |
6 | 1. Link in the exception_tracer_base library. You get access to the functions
7 | in ExceptionTracer.h, but no stack traces. This has no runtime overhead,
8 | and is compliant with the C++ ABI.
9 |
10 | 2. Link in the (full) exception_tracer library. You get access to the
11 | functions in ExceptionTracer.h, the std::terminate and std::unexpected
12 | handlers are installed by default, and you get full stack traces with
13 | all exceptions. This has some runtime overhead (the stack trace must be
14 | captured and stored whenever an exception is thrown) added to throw
15 | and catch, but no runtime overhead otherwise. This is less portable
16 | (depends on internal details of GNU's libstdc++).
17 |
18 | 3. LD_PRELOAD libexceptiontracer.so. This is equivalent to #2 above, but
19 | requires no link-time changes. On the other hand, you need to ensure that
20 | libexceptiontracer.so is compiled with the same compiler and flags as
21 | your binary, and the usual caveats about LD_PRELOAD apply (it propagates
22 | to child processes, etc).
23 |
--------------------------------------------------------------------------------
/folly/detail/FunctionalExcept.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 |
21 | FOLLY_NAMESPACE_STD_BEGIN
22 |
23 | void __throw_length_error(const char* msg) {
24 | throw std::length_error(msg);
25 | }
26 |
27 | void __throw_logic_error(const char* msg) {
28 | throw std::logic_error(msg);
29 | }
30 |
31 | void __throw_out_of_range(const char* msg) {
32 | throw std::out_of_range(msg);
33 | }
34 |
35 | #if defined(_MSC_VER)
36 | void __throw_bad_alloc() {
37 | throw std::bad_alloc();
38 | }
39 | #endif
40 |
41 | FOLLY_NAMESPACE_STD_END
42 |
--------------------------------------------------------------------------------
/folly/gen/Core.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_GEN_CORE_H
18 | #define FOLLY_GEN_CORE_H
19 |
20 | namespace folly { namespace gen {
21 |
22 | template
23 | class GenImpl;
24 |
25 | template
26 | class Operator;
27 |
28 | namespace detail {
29 |
30 | template
31 | struct FBounded;
32 |
33 | template
34 | class Composed;
35 |
36 | template
37 | class Chain;
38 |
39 | } // detail
40 |
41 | }} // folly::gen
42 |
43 | #include
44 |
45 | #endif // FOLLY_GEN_CORE_H
46 |
--------------------------------------------------------------------------------
/folly/Unicode.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Some utility routines relating to unicode.
18 |
19 | #ifndef FOLLY_UNICODE_H_
20 | #define FOLLY_UNICODE_H_
21 |
22 | #include
23 |
24 | namespace folly {
25 |
26 | //////////////////////////////////////////////////////////////////////
27 |
28 | /*
29 | * Encode a single unicode code point into a UTF-8 byte sequence.
30 | *
31 | * Return value is undefined if `cp' is an invalid code point.
32 | */
33 | fbstring codePointToUtf8(char32_t cp);
34 |
35 | //////////////////////////////////////////////////////////////////////
36 |
37 | }
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/folly/Likely.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /**
18 | * Compiler hints to indicate the fast path of an "if" branch: whether
19 | * the if condition is likely to be true or false.
20 | *
21 | * @author Tudor Bosman (tudorb@fb.com)
22 | */
23 |
24 | #ifndef FOLLY_BASE_LIKELY_H_
25 | #define FOLLY_BASE_LIKELY_H_
26 |
27 | #undef LIKELY
28 | #undef UNLIKELY
29 |
30 | #if defined(__GNUC__) && __GNUC__ >= 4
31 | #define LIKELY(x) (__builtin_expect((x), 1))
32 | #define UNLIKELY(x) (__builtin_expect((x), 0))
33 | #else
34 | #define LIKELY(x) (x)
35 | #define UNLIKELY(x) (x)
36 | #endif
37 |
38 | #endif /* FOLLY_BASE_LIKELY_H_ */
39 |
--------------------------------------------------------------------------------
/folly/io/async/test/certs/tests-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDKzCCAhOgAwIBAgIBCjANBgkqhkiG9w0BAQUFADBFMQswCQYDVQQGEwJVUzEP
3 | MA0GA1UECgwGVGhyaWZ0MSUwIwYDVQQDDBxUaHJpZnQgQ2VydGlmaWNhdGUgQXV0
4 | aG9yaXR5MB4XDTE0MDUxNjIwMjg1MloXDTQxMTAwMTIwMjg1MlowRjELMAkGA1UE
5 | BhMCVVMxDTALBgNVBAgTBE9oaW8xETAPBgNVBAcTCEhpbGxpYXJkMRUwEwYDVQQD
6 | EwxBc294IENvbXBhbnkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCz
7 | ZGrJ5XQHAuMYHlBgn32OOc9l0n3RjXccio2ceeWctXkSxDP3vFyZ4kBILF1lsY1g
8 | o8UTjMkqSDYcytCLK0qavrv9BZRLB9FcpqJ9o4V9feaI/HsHa8DYHyEs8qyNTTNG
9 | YQ3i4j+AA9iDSpezIYy/tyAOAjrSquUW1jI4tzKTBh8hk8MAMvR2/NPHPkrp4gI+
10 | EMH6u4vWdr4F9bbriLFWoU04T9mWOMk7G+h8BS9sgINg2+v5cWvl3BC4kLk5L1yJ
11 | FEyuofSSCEEe6dDf7uVh+RPKa4hEkIYo31AEOPFrN56d+pCj/5l67HTWXoQx3rjy
12 | dNXMvgU75urm6TQe8dB5AgMBAAGjJTAjMCEGA1UdEQQaMBiHBH8AAAGHEAAAAAAA
13 | AAAAAAAAAAAAAAEwDQYJKoZIhvcNAQEFBQADggEBAD26XYInaEvlWZJYgtl3yQyC
14 | 3NRQc3LG7XxWg4aFdXCxYLPRAL2HLoarKYH8GPFso57t5xnhA8WfP7iJxmgsKdCS
15 | 0pNIicOWsMmXvYLib0j9tMCFR+a8rn3f4n+clwnqas4w/vWBJUoMgyxtkP8NNNZO
16 | kIl02JKRhuyiFyPLilVp5tu0e+lmyUER+ak53WjLq2yoytYAlHkzkOpc4MZ/TNt5
17 | UTEtx/WVlZvlrPi3dsi7QikkjQgo1wCnm7owtuAHlPDMAB8wKk4+vvIOjsGM33T/
18 | 8ffq/4X1HeYM0w0fM+SVlX1rwkXA1RW/jn48VWFHpWbE10+m196OdiToGfm2OJI=
19 | -----END CERTIFICATE-----
20 |
--------------------------------------------------------------------------------
/folly/test/AsciiCaseInsensitiveTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 | #include
21 | #include
22 |
23 | using namespace std;
24 | using namespace folly;
25 |
26 | TEST(CaseInsensitiveMatch, CompareWithLegacy) {
27 | AsciiCaseInsensitive cmp;
28 | for (int i=0; i<(1<<8); i++) {
29 | EXPECT_TRUE(cmp(tolower(i), toupper(i)));
30 | EXPECT_TRUE(cmp(toupper(i), tolower(i)));
31 | }
32 | }
33 |
34 | int main(int argc, char** argv) {
35 | testing::InitGoogleTest(&argc, argv);
36 | gflags::ParseCommandLineFlags(&argc, &argv, true);
37 | return RUN_ALL_TESTS();
38 | }
39 |
--------------------------------------------------------------------------------
/folly/StringBase.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | namespace folly {
20 |
21 | StringPiece skipWhitespace(StringPiece sp) {
22 | // Spaces other than ' ' characters are less common but should be
23 | // checked. This configuration where we loop on the ' '
24 | // separately from oddspaces was empirically fastest.
25 | auto oddspace = [] (char c) {
26 | return c == '\n' || c == '\t' || c == '\r';
27 | };
28 |
29 | loop:
30 | for (; !sp.empty() && sp.front() == ' '; sp.pop_front()) {
31 | }
32 | if (!sp.empty() && oddspace(sp.front())) {
33 | sp.pop_front();
34 | goto loop;
35 | }
36 |
37 | return sp;
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/folly/io/async/test/certs/ca-cert.pem:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDXTCCAkWgAwIBAgIJAKMZICGWUzawMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV
3 | BAYTAlVTMQ8wDQYDVQQKDAZUaHJpZnQxJTAjBgNVBAMMHFRocmlmdCBDZXJ0aWZp
4 | Y2F0ZSBBdXRob3JpdHkwHhcNMTQwNTE2MjAyODUyWhcNNDExMDAxMjAyODUyWjBF
5 | MQswCQYDVQQGEwJVUzEPMA0GA1UECgwGVGhyaWZ0MSUwIwYDVQQDDBxUaHJpZnQg
6 | Q2VydGlmaWNhdGUgQXV0aG9yaXR5MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB
7 | CgKCAQEA1Bx2vUvXZ8PrvEBxwdH5qM1F2Xo7UkeC1jzQ+OLUBEcCiEduyStitSvB
8 | NOAzAGdjt7NmHTP/7OJngp2vzQGjSQzm20XacyTieFUuPBuikUc0Ge3Tf+uQXtiU
9 | zZPh+xn6arHH+zBWtmUCt3cBrpgRqdnWUsbl8eqo5HsczY781FxQbDoT9VP6A+9R
10 | KGTsEhxxKbWJ1C7OngwLKc7Zv4DtTC1JFlFyKd8ryDtxP4s/GgsXJkoK0Hkpputr
11 | cMxMm6OGt77mFvzR2qRY1CpEK/9rjBB6Gqd8GakXsvoOsqL/37k2wVhN/JoS/Pde
12 | 12Mp6TZ2rA8NW8vRujfWU0u55gnQnwIDAQABo1AwTjAdBgNVHQ4EFgQUQ00NGVmY
13 | NZ6LJg8UQUOVLZX1Gh8wHwYDVR0jBBgwFoAUQ00NGVmYNZ6LJg8UQUOVLZX1Gh8w
14 | DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAdlxt5+z9uXCBr1Wt6r49
15 | 4MmOYw9lOnEOG1JPMRo108TLpmwXEWReCAtjQuR7BitRJW0kJtlO1M6t3qoIh6GA
16 | sBkgsjQM1xNY3YEpx71MLt1V+JD+2WtSBKMyysj1TiOmIH66kkvXO3ptXzhjhZyX
17 | G6B+kxLtxrqkn9SJULyN55X8T+dkW28UIBZVLavoREDU+UPrYU9JgZeIVObtGSWi
18 | DvS4RIJZNjgG3vTrT00rfUGEfTlI54Vbcmv0cYvswP/nMsLtDStCdgI7c/ipyJve
19 | dfuI4CedjE240AxK5OFxFg/k/IfnB4a5oojbdIR9hKrTU57TPaUVD50Na9WA1aqX
20 | 5Q==
21 | -----END CERTIFICATE-----
22 |
--------------------------------------------------------------------------------
/folly/test/FileTestLockHelper.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 |
20 | #include
21 |
22 | DEFINE_bool(s, false, "get shared lock");
23 | DEFINE_bool(x, false, "get exclusive lock");
24 |
25 | int main(int argc, char *argv[]) {
26 | gflags::ParseCommandLineFlags(&argc, &argv, true);
27 | google::InitGoogleLogging(argv[0]);
28 | CHECK_EQ(FLAGS_s + FLAGS_x, 1)
29 | << "exactly one of -s and -x must be specified";
30 | CHECK_EQ(argc, 2);
31 | folly::File f(argv[1], O_RDWR);
32 | bool r;
33 | if (FLAGS_s) {
34 | r = f.try_lock_shared();
35 | } else {
36 | r = f.try_lock();
37 | }
38 | return r ? 0 : 42;
39 | }
40 |
--------------------------------------------------------------------------------
/folly/test/function_benchmark/test_functions.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef TEST_FUNCTIONS_H_
18 | #define TEST_FUNCTIONS_H_
19 |
20 | #include
21 | #include
22 |
23 | void doNothing();
24 |
25 | void throwException();
26 | std::exception_ptr returnExceptionPtr();
27 | void exceptionPtrReturnParam(std::exception_ptr* excReturn);
28 | std::string returnString();
29 | std::string returnStringNoExcept() noexcept;
30 | int returnCode(int value);
31 | int returnCodeNoExcept(int value) noexcept;
32 |
33 | class TestClass {
34 | public:
35 | void doNothing();
36 | };
37 |
38 | class VirtualClass {
39 | public:
40 | virtual ~VirtualClass();
41 | virtual void doNothing();
42 | };
43 |
44 | #endif // TEST_FUNCTIONS_H_
45 |
--------------------------------------------------------------------------------
/folly/bootstrap-osx-homebrew.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash -x
2 | # The only prerequisite should be homebrew. If something doesn't work out of
3 | # the box with just homebrew, let's fix it.
4 |
5 | # fail fast
6 | set -e
7 |
8 | brewget() {
9 | brew install $@ || brew upgrade $@
10 | }
11 |
12 | # tool dependencies: autotools and scons (for double-conversion)
13 | brewget autoconf automake libtool scons
14 |
15 | # dependencies
16 | brewget glog gflags boost libevent
17 |
18 | # Install the double-conversion library.
19 | # NB their install target installs the libs but not the headers, hence the
20 | # CPPFLAGS and link shenanigans.
21 | test -d double-conversion || {
22 | git clone https://github.com/floitsch/double-conversion.git
23 | pushd double-conversion/src
24 | ln -s . double-conversion
25 | popd
26 | }
27 | pushd double-conversion
28 | scons
29 | # fool libtool into using static linkage
30 | # (this won't work if you've already installed libdouble-conversion into a
31 | # default search path)
32 | rm -f libdouble-conversion*dylib
33 | DOUBLE_CONVERSION_HOME=$(pwd)
34 | popd
35 |
36 | autoreconf -i
37 | ./configure CPPFLAGS=-I"$DOUBLE_CONVERSION_HOME/src" LDFLAGS=-L"$DOUBLE_CONVERSION_HOME"
38 |
39 | pushd test
40 | test -e gtest-1.7.0.zip || {
41 | curl -O https://googletest.googlecode.com/files/gtest-1.7.0.zip
42 | unzip gtest-1.7.0.zip
43 | }
44 | popd
45 |
--------------------------------------------------------------------------------
/folly/SingletonVault_c.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Plain C interface to SingletonVault. This facilitates combining programs
18 | // that cannot use C++ (e.g. programs written in C) with libraries that use
19 | // Singleton, by allowing the program to perform the required SingletonVault
20 | // lifecycle calls.
21 |
22 | #pragma once
23 |
24 | #ifdef __cplusplus
25 | extern "C" {
26 | #endif
27 |
28 | typedef void SingletonVault_t;
29 |
30 | SingletonVault_t *SingletonVault_singleton();
31 | void SingletonVault_registrationComplete(SingletonVault_t *vault);
32 | void SingletonVault_destroyInstances(SingletonVault_t *vault);
33 | void SingletonVault_reenableInstances(SingletonVault_t *vault);
34 |
35 | #ifdef __cplusplus
36 | } // extern "C"
37 | #endif
38 |
--------------------------------------------------------------------------------
/folly/detail/Clock.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_DETAIL_CLOCK_H_
18 | #define FOLLY_DETAIL_CLOCK_H_
19 |
20 | #include
21 | #include
22 |
23 | #include
24 |
25 | #if FOLLY_HAVE_CLOCK_GETTIME
26 | #error This should only be used as a workaround for platforms \
27 | that do not support clock_gettime(2).
28 | #endif
29 |
30 | /* For windows, we'll use pthread's time implementations */
31 | #ifdef _MSC_VER
32 | #include
33 | #include
34 | #else
35 | typedef uint8_t clockid_t;
36 | #define CLOCK_REALTIME 0
37 |
38 | int clock_gettime(clockid_t clk_id, struct timespec* ts);
39 | int clock_getres(clockid_t clk_id, struct timespec* ts);
40 | #endif
41 |
42 | #endif /* FOLLY_DETAIL_CLOCK_H_ */
43 |
--------------------------------------------------------------------------------
/folly/wangle/acceptor/LoadShedConfiguration.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #include
11 |
12 | #include
13 | #include
14 |
15 | using std::string;
16 |
17 | namespace folly {
18 |
19 | void LoadShedConfiguration::addWhitelistAddr(folly::StringPiece input) {
20 | auto addr = input.str();
21 | size_t separator = addr.find_first_of('/');
22 | if (separator == string::npos) {
23 | whitelistAddrs_.insert(SocketAddress(addr, 0));
24 | } else {
25 | unsigned prefixLen = folly::to(addr.substr(separator + 1));
26 | addr.erase(separator);
27 | whitelistNetworks_.insert(NetworkAddress(SocketAddress(addr, 0), prefixLen));
28 | }
29 | }
30 |
31 | bool LoadShedConfiguration::isWhitelisted(const SocketAddress& address) const {
32 | if (whitelistAddrs_.find(address) != whitelistAddrs_.end()) {
33 | return true;
34 | }
35 | for (auto& network : whitelistNetworks_) {
36 | if (network.contains(address)) {
37 | return true;
38 | }
39 | }
40 | return false;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/folly/SingletonVault_c.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 |
20 | #ifdef __cplusplus
21 | extern "C" {
22 | #endif
23 |
24 | SingletonVault_t *SingletonVault_singleton() {
25 | return folly::SingletonVault::singleton();
26 | }
27 |
28 | void SingletonVault_registrationComplete(SingletonVault_t *vault) {
29 | ((folly::SingletonVault*) vault)->registrationComplete();
30 | }
31 |
32 | void SingletonVault_destroyInstances(SingletonVault_t *vault) {
33 | ((folly::SingletonVault*) vault)->destroyInstances();
34 | }
35 |
36 | void SingletonVault_reenableInstances(SingletonVault_t *vault) {
37 | ((folly::SingletonVault*) vault)->reenableInstances();
38 | }
39 |
40 | #ifdef __cplusplus
41 | } // extern "C"
42 | #endif
43 |
--------------------------------------------------------------------------------
/folly/gen/Combine.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_GEN_COMBINE_H
18 | #define FOLLY_GEN_COMBINE_H
19 |
20 | #include
21 |
22 | namespace folly {
23 | namespace gen {
24 | namespace detail {
25 |
26 | template
27 | class Interleave;
28 |
29 | template
30 | class Zip;
31 |
32 | } // namespace detail
33 |
34 | template::type,
36 | class Interleave = detail::Interleave>
37 | Interleave interleave(Source2&& source2) {
38 | return Interleave(std::forward(source2));
39 | }
40 |
41 | } // namespace gen
42 | } // namespace folly
43 |
44 | #include
45 |
46 | #endif // FOLLY_GEN_COMBINE_H
47 |
--------------------------------------------------------------------------------
/folly/wangle/rx/types.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace folly { namespace wangle {
23 | typedef folly::exception_wrapper Error;
24 | // The Executor is basically an rx Scheduler (by design). So just
25 | // alias it.
26 | typedef std::shared_ptr SchedulerPtr;
27 |
28 | template class Observable;
29 | template struct Observer;
30 | template struct Subject;
31 |
32 | template using ObservablePtr = std::shared_ptr>;
33 | template using ObserverPtr = std::shared_ptr>;
34 | template using SubjectPtr = std::shared_ptr>;
35 | }}
36 |
--------------------------------------------------------------------------------
/folly/Checksum.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_CHECKSUM_H_
18 | #define FOLLY_CHECKSUM_H_
19 |
20 | #include
21 | #include
22 |
23 | /*
24 | * Checksum functions
25 | */
26 |
27 | namespace folly {
28 |
29 | /**
30 | * Compute the CRC-32C checksum of a buffer, using a hardware-accelerated
31 | * implementation if available or a portable software implementation as
32 | * a default.
33 | *
34 | * @note CRC-32C is different from CRC-32; CRC-32C starts with a different
35 | * polynomial and thus yields different results for the same input
36 | * than a traditional CRC-32.
37 | */
38 | uint32_t crc32c(const uint8_t* data, size_t nbytes,
39 | uint32_t startingChecksum = ~0U);
40 |
41 | } // folly
42 |
43 | #endif /* FOLLY_CHECKSUM_H_ */
44 |
--------------------------------------------------------------------------------
/folly/ThreadName.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 |
22 | namespace folly {
23 |
24 | // This looks a bit weird, but it's necessary to avoid
25 | // having an undefined compiler function called.
26 | #if defined(__GLIBC__) && !defined(__APPLE__) && !defined(__ANDROID__)
27 | #if __GLIBC_PREREQ(2, 12)
28 | # define FOLLY_HAS_PTHREAD_SETNAME_NP
29 | #endif
30 | #endif
31 |
32 | inline bool setThreadName(pthread_t id, StringPiece name) {
33 | #ifdef FOLLY_HAS_PTHREAD_SETNAME_NP
34 | return 0 == pthread_setname_np(id, name.fbstr().substr(0, 15).c_str());
35 | #else
36 | return false;
37 | #endif
38 | }
39 |
40 | inline bool setThreadName(StringPiece name) {
41 | return setThreadName(pthread_self(), name);
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/folly/SpinLock.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly {
22 |
23 | #if __x86_64__
24 | typedef SpinLockMslImpl SpinLock;
25 | #elif __APPLE__
26 | typedef SpinLockAppleImpl SpinLock;
27 | #elif FOLLY_HAVE_PTHREAD_SPINLOCK_T
28 | typedef SpinLockPthreadImpl SpinLock;
29 | #else
30 | typedef SpinLockPthreadMutexImpl SpinLock;
31 | #endif
32 |
33 | template
34 | class SpinLockGuardImpl : private boost::noncopyable {
35 | public:
36 | FOLLY_ALWAYS_INLINE explicit SpinLockGuardImpl(LOCK& lock) :
37 | lock_(lock) {
38 | lock_.lock();
39 | }
40 | FOLLY_ALWAYS_INLINE ~SpinLockGuardImpl() {
41 | lock_.unlock();
42 | }
43 | private:
44 | LOCK& lock_;
45 | };
46 |
47 | typedef SpinLockGuardImpl SpinLockGuard;
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/folly/Uri-inl.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_URI_H_
18 | #error This file may only be included from folly/Uri.h
19 | #endif
20 |
21 | #include
22 |
23 | namespace folly {
24 |
25 | template
26 | String Uri::toString() const {
27 | String str;
28 | toAppend(scheme_, "://", &str);
29 | if (!password_.empty()) {
30 | toAppend(username_, ":", password_, "@", &str);
31 | } else if (!username_.empty()) {
32 | toAppend(username_, "@", &str);
33 | }
34 | toAppend(host_, &str);
35 | if (port_ != 0) {
36 | toAppend(":", port_, &str);
37 | }
38 | toAppend(path_, &str);
39 | if (!query_.empty()) {
40 | toAppend("?", query_, &str);
41 | }
42 | if (!fragment_.empty()) {
43 | toAppend("#", fragment_, &str);
44 | }
45 | return str;
46 | }
47 |
48 | } // namespace folly
49 |
--------------------------------------------------------------------------------
/folly/test/PortabilityTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 |
21 | #include
22 |
23 | class Base {
24 | public:
25 | virtual ~Base() { }
26 | virtual int foo() const { return 1; }
27 | };
28 |
29 | class Derived : public Base {
30 | public:
31 | virtual int foo() const FOLLY_FINAL { return 2; }
32 | };
33 |
34 | // A compiler that supports final will likely inline the call to p->foo()
35 | // in fooDerived (but not in fooBase) as it knows that Derived::foo() can
36 | // no longer be overridden.
37 | int fooBase(const Base* p) { return p->foo() + 1; }
38 | int fooDerived(const Derived* p) { return p->foo() + 1; }
39 |
40 | TEST(Portability, Final) {
41 | std::unique_ptr p(new Derived);
42 | EXPECT_EQ(3, fooBase(p.get()));
43 | EXPECT_EQ(3, fooDerived(p.get()));
44 | }
45 |
--------------------------------------------------------------------------------
/folly/io/async/EventUtil.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed to the Apache Software Foundation (ASF) under one
5 | * or more contributor license agreements. See the NOTICE file
6 | * distributed with this work for additional information
7 | * regarding copyright ownership. The ASF licenses this file
8 | * to you under the Apache License, Version 2.0 (the
9 | * "License"); you may not use this file except in compliance
10 | * with the License. You may obtain a copy of the License at
11 | *
12 | * http://www.apache.org/licenses/LICENSE-2.0
13 | *
14 | * Unless required by applicable law or agreed to in writing,
15 | * software distributed under the License is distributed on an
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 | * KIND, either express or implied. See the License for the
18 | * specific language governing permissions and limitations
19 | * under the License.
20 | */
21 | #pragma once
22 |
23 | #include // libevent
24 |
25 | namespace folly {
26 |
27 | /**
28 | * low-level libevent utility functions
29 | */
30 | class EventUtil {
31 | public:
32 | static bool isEventRegistered(const struct event* ev) {
33 | // If any of these flags are set, the event is registered.
34 | enum {
35 | EVLIST_REGISTERED = (EVLIST_INSERTED | EVLIST_ACTIVE |
36 | EVLIST_TIMEOUT | EVLIST_SIGNAL)
37 | };
38 | return (ev->ev_flags & EVLIST_REGISTERED);
39 | }
40 | };
41 |
42 | } // folly
43 |
--------------------------------------------------------------------------------
/folly/test/HistogramBenchmark.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 |
18 | #include
19 |
20 | #include
21 | #include
22 |
23 | using folly::Histogram;
24 |
25 | void addValue(unsigned int n, int64_t bucketSize, int64_t min, int64_t max) {
26 | Histogram hist(bucketSize, min, max);
27 | int64_t num = min;
28 | FOR_EACH_RANGE (i, 0, n) {
29 | hist.addValue(num);
30 | ++num;
31 | if (num > max) { num = min; }
32 | }
33 | }
34 |
35 | BENCHMARK_NAMED_PARAM(addValue, 0_to_100, 1, 0, 100);
36 | BENCHMARK_NAMED_PARAM(addValue, 0_to_1000, 10, 0, 1000);
37 | BENCHMARK_NAMED_PARAM(addValue, 5k_to_20k, 250, 5000, 20000);
38 |
39 | int main(int argc, char *argv[]) {
40 | gflags::ParseCommandLineFlags(&argc, &argv, true);
41 | folly::runBenchmarks();
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/folly/futures/test/UnitTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 |
20 | using namespace folly;
21 |
22 | TEST(Unit, FutureDefaultCtor) {
23 | Future();
24 | }
25 |
26 | TEST(Unit, voidOrUnit) {
27 | EXPECT_TRUE(is_void_or_unit::value);
28 | EXPECT_TRUE(is_void_or_unit::value);
29 | EXPECT_FALSE(is_void_or_unit::value);
30 | }
31 |
32 | TEST(Unit, PromiseSetValue) {
33 | Promise p;
34 | p.setValue();
35 | }
36 |
37 | TEST(Unit, LiftInt) {
38 | using Lifted = Unit::Lift;
39 | EXPECT_FALSE(Lifted::value);
40 | auto v = std::is_same::value;
41 | EXPECT_TRUE(v);
42 | }
43 |
44 | TEST(Unit, LiftVoid) {
45 | using Lifted = Unit::Lift;
46 | EXPECT_TRUE(Lifted::value);
47 | auto v = std::is_same::value;
48 | EXPECT_TRUE(v);
49 | }
50 |
--------------------------------------------------------------------------------
/folly/gen/test/Bench.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_GEN_BENCH_H_
18 | #define FOLLY_GEN_BENCH_H_
19 |
20 | #include
21 |
22 | #define BENCH_GEN_IMPL(gen, prefix) \
23 | static bool FB_ANONYMOUS_VARIABLE(benchGen) = ( \
24 | ::folly::addBenchmark(__FILE__, prefix FB_STRINGIZE(gen), \
25 | [](unsigned iters){ \
26 | const unsigned num = iters; \
27 | while (iters--) { \
28 | folly::doNotOptimizeAway(gen); \
29 | } \
30 | return num; \
31 | }), true)
32 | #define BENCH_GEN(gen) BENCH_GEN_IMPL(gen, "")
33 | #define BENCH_GEN_REL(gen) BENCH_GEN_IMPL(gen, "%")
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/folly/test/MoveWrapperTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 | #include
21 |
22 | namespace folly {
23 |
24 | TEST(makeMoveWrapper, Empty) {
25 | // checks for crashes
26 | auto p = makeMoveWrapper(std::unique_ptr());
27 | }
28 |
29 | TEST(makeMoveWrapper, NonEmpty) {
30 | auto u = std::unique_ptr(new int(5));
31 | EXPECT_EQ(*u, 5);
32 | auto p = makeMoveWrapper(std::move(u));
33 | EXPECT_TRUE(!u);
34 | EXPECT_EQ(**p, 5);
35 | }
36 |
37 | TEST(makeMoveWrapper, rvalue) {
38 | std::unique_ptr p;
39 | makeMoveWrapper(std::move(p));
40 | }
41 |
42 | TEST(makeMoveWrapper, lvalue) {
43 | std::unique_ptr p;
44 | makeMoveWrapper(p);
45 | }
46 |
47 | TEST(makeMoveWrapper, lvalue_copyable) {
48 | std::shared_ptr p;
49 | makeMoveWrapper(p);
50 | }
51 |
52 | } // namespace
53 |
--------------------------------------------------------------------------------
/folly/experimental/symbolizer/ElfUtil.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 |
18 | #include
19 |
20 | #include
21 |
22 | #include
23 | #include
24 |
25 | using namespace folly;
26 | using namespace folly::symbolizer;
27 |
28 | int main(int argc, char *argv[]) {
29 | gflags::ParseCommandLineFlags(&argc, &argv, true);
30 | CHECK_GE(argc, 2);
31 |
32 | ElfFile elf(argv[1]);
33 |
34 | if (argc > 2) {
35 | auto section = elf.getSectionByName(argv[2]);
36 | printf("Section %s: %s\n",
37 | argv[2],
38 | (section ? "found" : "not found"));
39 | }
40 |
41 | auto sym = elf.getDefinitionByAddress(reinterpret_cast(main));
42 | if (sym.first) {
43 | printf("found %s\n", elf.getSymbolName(sym));
44 | } else {
45 | printf("main not found\n");
46 | }
47 |
48 | return 0;
49 | }
50 |
--------------------------------------------------------------------------------
/folly/LifoSem.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | /// Raw node storage is preallocated in a contiguous memory segment,
20 | /// but we use an anonymous mmap so the physical memory used (RSS) will
21 | /// only reflect the maximum number of waiters that actually existed
22 | /// concurrently. For blocked threads the max node count is limited by the
23 | /// number of threads, so we can conservatively estimate that this will be
24 | /// < 10k. For LifoEventSem, however, we could potentially have many more.
25 | ///
26 | /// On a 64-bit architecture each LifoSemRawNode takes 16 bytes. We make
27 | /// the pool 1 million entries.
28 |
29 | LIFOSEM_DECLARE_POOL(std::atomic, 1000000)
30 |
31 | namespace folly {
32 |
33 | ShutdownSemError::ShutdownSemError(const std::string& msg)
34 | : std::runtime_error(msg)
35 | {}
36 |
37 | ShutdownSemError::~ShutdownSemError() noexcept {
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/folly/wangle/service/ServerDispatcher.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 | #include
20 |
21 | namespace folly { namespace wangle {
22 |
23 | /**
24 | * Dispatch requests from pipeline one at a time synchronously.
25 | * Concurrent requests are queued in the pipeline.
26 | */
27 | template
28 | class SerialServerDispatcher : public HandlerAdapter {
29 | public:
30 |
31 | typedef typename HandlerAdapter::Context Context;
32 |
33 | explicit SerialServerDispatcher(Service* service)
34 | : service_(service) {}
35 |
36 | void read(Context* ctx, Req in) override {
37 | auto resp = (*service_)(std::move(in)).get();
38 | ctx->fireWrite(std::move(resp));
39 | }
40 |
41 | private:
42 |
43 | Service* service_;
44 | };
45 |
46 | }} // namespace
47 |
--------------------------------------------------------------------------------
/folly/ThreadCachedArena.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | namespace folly {
20 |
21 | ThreadCachedArena::ThreadCachedArena(size_t minBlockSize, size_t maxAlign)
22 | : minBlockSize_(minBlockSize), maxAlign_(maxAlign) {
23 | }
24 |
25 | SysArena* ThreadCachedArena::allocateThreadLocalArena() {
26 | SysArena* arena =
27 | new SysArena(minBlockSize_, SysArena::kNoSizeLimit, maxAlign_);
28 | auto disposer = [this] (SysArena* t, TLPDestructionMode mode) {
29 | std::unique_ptr tp(t); // ensure it gets deleted
30 | if (mode == TLPDestructionMode::THIS_THREAD) {
31 | zombify(std::move(*t));
32 | }
33 | };
34 | arena_.reset(arena, disposer);
35 | return arena;
36 | }
37 |
38 | void ThreadCachedArena::zombify(SysArena&& arena) {
39 | std::lock_guard lock(zombiesMutex_);
40 | zombies_.merge(std::move(arena));
41 | }
42 |
43 | } // namespace folly
44 |
--------------------------------------------------------------------------------
/folly/io/async/test/SocketPair.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one
3 | * or more contributor license agreements. See the NOTICE file
4 | * distributed with this work for additional information
5 | * regarding copyright ownership. The ASF licenses this file
6 | * to you under the Apache License, Version 2.0 (the
7 | * "License"); you may not use this file except in compliance
8 | * with the License. You may obtain a copy of the License at
9 | *
10 | * http://www.apache.org/licenses/LICENSE-2.0
11 | *
12 | * Unless required by applicable law or agreed to in writing,
13 | * software distributed under the License is distributed on an
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | * KIND, either express or implied. See the License for the
16 | * specific language governing permissions and limitations
17 | * under the License.
18 | */
19 | #pragma once
20 |
21 | namespace folly {
22 |
23 | class SocketPair {
24 | public:
25 | enum Mode {
26 | BLOCKING,
27 | NONBLOCKING
28 | };
29 |
30 | explicit SocketPair(Mode mode = NONBLOCKING);
31 | ~SocketPair();
32 |
33 | int operator[](int index) const {
34 | return fds_[index];
35 | }
36 |
37 | void closeFD0();
38 | void closeFD1();
39 |
40 | int extractFD0() {
41 | return extractFD(0);
42 | }
43 | int extractFD1() {
44 | return extractFD(1);
45 | }
46 | int extractFD(int index) {
47 | int fd = fds_[index];
48 | fds_[index] = -1;
49 | return fd;
50 | }
51 |
52 | private:
53 | int fds_[2];
54 | };
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/folly/experimental/fibers/ExecutionObserver.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 |
20 | namespace folly { namespace fibers {
21 |
22 | /**
23 | * Observes the execution of a task.
24 | */
25 | class ExecutionObserver {
26 | public:
27 | virtual ~ExecutionObserver() { }
28 |
29 | /**
30 | * Called when a task is about to start executing.
31 | *
32 | * @param id Unique id for the fiber which is starting.
33 | */
34 | virtual void starting(uintptr_t id) noexcept = 0;
35 |
36 | /**
37 | * Called when a task is ready to run.
38 | *
39 | * @param id Unique id for the fiber which is ready to run.
40 | */
41 | virtual void runnable(uintptr_t id) noexcept = 0;
42 |
43 | /**
44 | * Called just after a task stops executing.
45 | *
46 | * @param id Unique id for the fiber which is stopping.
47 | */
48 | virtual void stopped(uintptr_t id) noexcept = 0;
49 | };
50 |
51 | }} // namespace folly::fibers
52 |
--------------------------------------------------------------------------------
/folly/SafeAssert.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 | #include
21 |
22 | namespace folly { namespace detail {
23 |
24 | namespace {
25 | void writeStderr(const char* s) {
26 | writeFull(STDERR_FILENO, s, strlen(s));
27 | }
28 | } // namespace
29 |
30 | void assertionFailure(const char* expr, const char* msg, const char* file,
31 | unsigned int line, const char* function) {
32 | writeStderr("\n\nAssertion failure: ");
33 | writeStderr(expr);
34 | writeStderr("\nMessage: ");
35 | writeStderr(msg);
36 | writeStderr("\nFile: ");
37 | writeStderr(file);
38 | writeStderr("\nLine: ");
39 | char buf[20];
40 | uint32_t n = uint64ToBufferUnsafe(line, buf);
41 | writeFull(STDERR_FILENO, buf, n);
42 | writeStderr("\nFunction: ");
43 | writeStderr(function);
44 | writeStderr("\n");
45 | fsyncNoInt(STDERR_FILENO);
46 | abort();
47 | }
48 |
49 | }} // namespaces
50 |
--------------------------------------------------------------------------------
/folly/detail/AtomicHashUtils.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | // Some utilities used by AtomicHashArray and AtomicHashMap
18 | //
19 | // Note: no include guard; different -inl.h files include this and
20 | // undef it more than once in a translation unit.
21 | // override-include-guard
22 |
23 | #if !(defined(__x86__) || defined(__i386__) || FOLLY_X64)
24 | #define FOLLY_SPIN_WAIT(condition) \
25 | for (int counter = 0; condition; ++counter) { \
26 | if (counter < 10000) continue; \
27 | pthread_yield(); \
28 | }
29 | #else
30 | #define FOLLY_SPIN_WAIT(condition) \
31 | for (int counter = 0; condition; ++counter) { \
32 | if (counter < 10000) { \
33 | asm volatile("pause"); \
34 | continue; \
35 | } \
36 | pthread_yield(); \
37 | }
38 | #endif
39 |
--------------------------------------------------------------------------------
/folly/wangle/concurrent/test/CodelTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 | #include
19 | #include
20 | #include
21 |
22 | TEST(CodelTest, Basic) {
23 | using std::chrono::milliseconds;
24 | folly::wangle::Codel c;
25 | std::this_thread::sleep_for(milliseconds(110));
26 | // This interval is overloaded
27 | EXPECT_FALSE(c.overloaded(milliseconds(100)));
28 | std::this_thread::sleep_for(milliseconds(90));
29 | // At least two requests must happen in an interval before they will fail
30 | EXPECT_FALSE(c.overloaded(milliseconds(50)));
31 | EXPECT_TRUE(c.overloaded(milliseconds(50)));
32 | std::this_thread::sleep_for(milliseconds(110));
33 | // Previous interval is overloaded, but 2ms isn't enough to fail
34 | EXPECT_FALSE(c.overloaded(milliseconds(2)));
35 | std::this_thread::sleep_for(milliseconds(90));
36 | // 20 ms > target interval * 2
37 | EXPECT_TRUE(c.overloaded(milliseconds(20)));
38 | }
39 |
--------------------------------------------------------------------------------
/folly/wangle/codec/StringCodec.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly { namespace wangle {
22 |
23 | /*
24 | * StringCodec converts a pipeline from IOBufs to std::strings.
25 | */
26 | class StringCodec : public Handler, std::string,
27 | std::string, std::unique_ptr> {
28 | public:
29 | typedef typename Handler<
30 | std::unique_ptr, std::string,
31 | std::string, std::unique_ptr>::Context Context;
32 |
33 | void read(Context* ctx, std::unique_ptr buf) override {
34 | buf->coalesce();
35 | std::string data((const char*)buf->data(), buf->length());
36 |
37 | ctx->fireRead(data);
38 | }
39 |
40 | Future write(Context* ctx, std::string msg) override {
41 | auto buf = IOBuf::copyBuffer(msg.data(), msg.length());
42 | return ctx->fireWrite(std::move(buf));
43 | }
44 | };
45 |
46 | }} // namespace
47 |
--------------------------------------------------------------------------------
/folly/gen/ParallelMap.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_GEN_PARALLELMAP_H
18 | #define FOLLY_GEN_PARALLELMAP_H
19 |
20 | #include
21 |
22 | namespace folly { namespace gen {
23 |
24 | namespace detail {
25 |
26 | template
27 | class PMap;
28 |
29 | } // namespace detail
30 |
31 | /**
32 | * Run `pred` in parallel in nThreads. Results are returned in the
33 | * same order in which they were retrieved from the source generator
34 | * (similar to map).
35 | *
36 | * NOTE: Only `pred` is run from separate threads; the source
37 | * generator and the rest of the pipeline is executed in the
38 | * caller thread.
39 | */
40 | template>
42 | PMap pmap(Predicate pred = Predicate(), size_t nThreads = 0) {
43 | return PMap(std::move(pred), nThreads);
44 | }
45 |
46 | }} // namespaces
47 |
48 | #include
49 |
50 | #endif // FOLLY_GEN_PARALLELMAP_H
51 |
--------------------------------------------------------------------------------
/folly/wangle/rx/Subject.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include // must come first
20 | #include
21 | #include
22 |
23 | namespace folly { namespace wangle {
24 |
25 | /// Subject interface. A Subject is both an Observable and an Observer. There
26 | /// is a default implementation of the Observer methods that just forwards the
27 | /// observed events to the Subject's observers.
28 | template
29 | struct Subject : public Observable, public Observer {
30 | void onNext(const T& val) override {
31 | this->forEachObserver([&](Observer* o){
32 | o->onNext(val);
33 | });
34 | }
35 | void onError(Error e) override {
36 | this->forEachObserver([&](Observer* o){
37 | o->onError(e);
38 | });
39 | }
40 | void onCompleted() override {
41 | this->forEachObserver([](Observer* o){
42 | o->onCompleted();
43 | });
44 | }
45 | };
46 |
47 | }}
48 |
--------------------------------------------------------------------------------
/folly/wangle/channel/EventBaseHandler.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | namespace folly { namespace wangle {
19 |
20 | class EventBaseHandler : public OutboundBytesToBytesHandler {
21 | public:
22 | folly::Future write(
23 | Context* ctx,
24 | std::unique_ptr buf) override {
25 | folly::Future retval;
26 | DCHECK(ctx->getTransport());
27 | DCHECK(ctx->getTransport()->getEventBase());
28 | ctx->getTransport()->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait([&](){
29 | retval = ctx->fireWrite(std::move(buf));
30 | });
31 | return retval;
32 | }
33 |
34 | Future close(Context* ctx) override {
35 | DCHECK(ctx->getTransport());
36 | DCHECK(ctx->getTransport()->getEventBase());
37 | Future retval;
38 | ctx->getTransport()->getEventBase()->runImmediatelyOrRunInEventBaseThreadAndWait([&](){
39 | retval = ctx->fireClose();
40 | });
41 | return retval;
42 | }
43 | };
44 |
45 | }} // namespace
46 |
--------------------------------------------------------------------------------
/folly/experimental/StringKeyedCommon.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Copyright 2013-present Facebook. All Rights Reserved.
17 | // @author: Pavlo Kushnir (pavlo)
18 |
19 | #ifndef FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_
20 | #define FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_
21 |
22 | #include
23 | #include
24 |
25 | namespace folly {
26 |
27 | template
28 | StringPiece stringPieceDup(StringPiece piece, const Alloc& alloc) {
29 | auto size = piece.size();
30 | auto keyDup = typename Alloc::template rebind::other(alloc)
31 | .allocate(size);
32 | memcpy(keyDup, piece.data(), size * sizeof(typename StringPiece::value_type));
33 | return StringPiece(keyDup, size);
34 | }
35 |
36 | template
37 | void stringPieceDel(StringPiece piece, const Alloc& alloc) {
38 | typename Alloc::template rebind::other(alloc)
39 | .deallocate(const_cast(piece.data()), piece.size());
40 | }
41 |
42 | } // folly
43 |
44 | #endif /* FOLLY_EXPERIMENTAL_STRINGKEYEDCOMMON_H_ */
45 |
--------------------------------------------------------------------------------
/folly/experimental/symbolizer/StackTrace.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_SYMBOLIZER_STACKTRACE_H_
18 | #define FOLLY_SYMBOLIZER_STACKTRACE_H_
19 |
20 | #include
21 | #include
22 |
23 | namespace folly { namespace symbolizer {
24 |
25 | /**
26 | * Get the current stack trace into addresses, which has room for at least
27 | * maxAddresses frames.
28 | *
29 | * Returns the number of frames written in the array.
30 | * Returns -1 on failure.
31 | *
32 | * NOT async-signal-safe, but fast.
33 | */
34 | ssize_t getStackTrace(uintptr_t* addresses, size_t maxAddresses);
35 |
36 | /**
37 | * Get the current stack trace into addresses, which has room for at least
38 | * maxAddresses frames.
39 | *
40 | * Returns the number of frames written in the array.
41 | * Returns -1 on failure.
42 | *
43 | * Async-signal-safe, but likely slower.
44 | */
45 | ssize_t getStackTraceSafe(uintptr_t* addresses, size_t maxAddresses);
46 |
47 | }} // namespaces
48 |
49 | #endif /* FOLLY_SYMBOLIZER_STACKTRACE_H_ */
50 |
--------------------------------------------------------------------------------
/folly/SingletonStackTrace.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 | #include
18 |
19 | namespace folly {
20 |
21 | namespace {
22 |
23 | std::string stackTraceGetter() {
24 | // Get and symbolize stack trace
25 | constexpr size_t kMaxStackTraceDepth = 100;
26 | symbolizer::FrameArray addresses;
27 |
28 | if (!getStackTraceSafe(addresses)) {
29 | return "";
30 | } else {
31 | constexpr size_t kDefaultCapacity = 500;
32 | symbolizer::ElfCache elfCache(kDefaultCapacity);
33 |
34 | symbolizer::Symbolizer symbolizer(&elfCache);
35 | symbolizer.symbolize(addresses);
36 |
37 | symbolizer::StringSymbolizePrinter printer;
38 | printer.println(addresses);
39 | return printer.str();
40 | }
41 | }
42 |
43 | struct SetStackTraceGetter {
44 | SetStackTraceGetter() {
45 | SingletonVault::stackTraceGetter().store(stackTraceGetter);
46 | }
47 | };
48 |
49 | SetStackTraceGetter setStackTraceGetter;
50 |
51 | }
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/folly/futures/DrivableExecutor.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 |
21 | namespace folly {
22 |
23 | /*
24 | * A DrivableExecutor can be driven via its drive() method
25 | * Examples include EventBase (via loopOnce()) and ManualExecutor
26 | * (via makeProgress()).
27 | *
28 | * This interface is most handy in conjunction with
29 | * Future::getVia(DrivableExecutor*) and
30 | * Future::waitVia(DrivableExecutor*)
31 | *
32 | * These call drive() * repeatedly until the Future is fulfilled.
33 | * getVia() returns the value (or throws the exception) and waitVia() returns
34 | * the same Future for chainability.
35 | *
36 | * These will be most helpful in tests, for instance if you need to pump a mock
37 | * EventBase until Futures complete.
38 | */
39 | class DrivableExecutor : public virtual Executor {
40 | public:
41 | virtual ~DrivableExecutor() = default;
42 |
43 | // Make progress on this Executor's work.
44 | virtual void drive() = 0;
45 | };
46 |
47 | } // folly
48 |
--------------------------------------------------------------------------------
/folly/wangle/concurrent/LifoSemMPMCQueue.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 | #include
19 | #include
20 | #include
21 |
22 | namespace folly { namespace wangle {
23 |
24 | template
25 | class LifoSemMPMCQueue : public BlockingQueue {
26 | public:
27 | explicit LifoSemMPMCQueue(size_t max_capacity) : queue_(max_capacity) {}
28 |
29 | void add(T item) override {
30 | if (!queue_.write(std::move(item))) {
31 | throw std::runtime_error("LifoSemMPMCQueue full, can't add item");
32 | }
33 | sem_.post();
34 | }
35 |
36 | T take() override {
37 | T item;
38 | while (!queue_.read(item)) {
39 | sem_.wait();
40 | }
41 | return item;
42 | }
43 |
44 | size_t capacity() {
45 | return queue_.capacity();
46 | }
47 |
48 | size_t size() override {
49 | return queue_.size();
50 | }
51 |
52 | private:
53 | LifoSem sem_;
54 | MPMCQueue queue_;
55 | };
56 |
57 | }} // folly::wangle
58 |
--------------------------------------------------------------------------------
/folly/detail/BitsDetail.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_DETAIL_BITSDETAIL_H_
18 | #define FOLLY_DETAIL_BITSDETAIL_H_
19 |
20 | namespace folly {
21 | namespace detail {
22 |
23 | // If we're targeting an architecture with popcnt support, use
24 | // __builtin_popcount directly, as it's presumably inlined.
25 | // If not, use runtime detection using __attribute__((__ifunc__))
26 | // (see Bits.cpp)
27 | #ifdef _MSC_VER
28 | inline int popcount(unsigned int x) {
29 | return __popcnt(x);
30 | }
31 | inline int popcountll(unsigned long long x) {
32 | return __popcnt64(x);
33 | }
34 | #elif defined(__POPCNT__)
35 |
36 | inline int popcount(unsigned int x) {
37 | return __builtin_popcount(x);
38 | }
39 | inline int popcountll(unsigned long long x) {
40 | return __builtin_popcountll(x);
41 | }
42 |
43 | #else /* !__POPCNT__ */
44 |
45 | int popcount(unsigned int x);
46 | int popcountll(unsigned long long x);
47 |
48 | #endif /* !__POPCNT__ */
49 |
50 | } // namespace detail
51 | } // namespace folly
52 |
53 | #endif /* FOLLY_DETAIL_BITSDETAIL_H_ */
54 |
--------------------------------------------------------------------------------
/folly/futures/Future.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #include
17 | #include
18 | #include
19 |
20 | namespace folly {
21 |
22 | // Instantiate the most common Future types to save compile time
23 | template class Future;
24 | template class Future;
25 | template class Future;
26 | template class Future;
27 | template class Future;
28 | template class Future;
29 |
30 | }
31 |
32 | namespace folly { namespace futures {
33 |
34 | Future sleep(Duration dur, Timekeeper* tk) {
35 | if (LIKELY(!tk)) {
36 | tk = detail::getTimekeeperSingleton();
37 | }
38 | return tk->after(dur);
39 | }
40 |
41 | }}
42 |
43 | namespace folly { namespace detail {
44 |
45 | template <>
46 | CollectContext::~CollectContext() {
47 | if (!threw.exchange(true)) {
48 | p.setValue();
49 | }
50 | }
51 |
52 | template <>
53 | void CollectContext::setPartialResult(size_t i, Try& t) {
54 | // Nothing to do for void
55 | }
56 |
57 | }}
58 |
--------------------------------------------------------------------------------
/folly/test/function_benchmark/benchmark_impl.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #include
18 |
19 | #include
20 |
21 | /*
22 | * These functions are defined in a separate file so that gcc won't be able to
23 | * inline them and optimize away the indirect calls.
24 | */
25 |
26 | void BM_fn_ptr_invoke_impl(int iters, void (*fn)()) {
27 | for (int n = 0; n < iters; ++n) {
28 | fn();
29 | }
30 | }
31 |
32 | void BM_std_function_invoke_impl(int iters,
33 | const std::function& fn) {
34 | for (int n = 0; n < iters; ++n) {
35 | fn();
36 | }
37 | }
38 |
39 | void BM_mem_fn_invoke_impl(int iters,
40 | TestClass* tc,
41 | void (TestClass::*memfn)()) {
42 | for (int n = 0; n < iters; ++n) {
43 | (tc->*memfn)();
44 | }
45 | }
46 |
47 | void BM_virtual_fn_invoke_impl(int iters, VirtualClass* vc) {
48 | for (int n = 0; n < iters; ++n) {
49 | vc->doNothing();
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/folly/io/async/test/MockAsyncSocket.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | #pragma once
17 |
18 | #include
19 |
20 | #include
21 | #include
22 |
23 | namespace folly {
24 |
25 | namespace test {
26 |
27 | class MockAsyncSocket : public AsyncSocket {
28 | public:
29 | typedef std::unique_ptr UniquePtr;
30 |
31 | explicit MockAsyncSocket(EventBase* base) : AsyncSocket(base) {
32 | }
33 |
34 | GMOCK_METHOD5_(, noexcept, , connect,
35 | void(AsyncSocket::ConnectCallback*,
36 | const folly::SocketAddress&,
37 | int,
38 | const OptionMap&,
39 | const folly::SocketAddress&));
40 |
41 | MOCK_CONST_METHOD1(getPeerAddress,
42 | void(folly::SocketAddress*));
43 | MOCK_METHOD0(detachFd, int());
44 | MOCK_CONST_METHOD0(getFd, int());
45 | MOCK_METHOD0(closeNow, void());
46 | MOCK_CONST_METHOD0(good, bool());
47 | MOCK_CONST_METHOD0(readable, bool());
48 | MOCK_CONST_METHOD0(hangup, bool());
49 | };
50 |
51 | }}
52 |
--------------------------------------------------------------------------------
/folly/test/SynchronizedTestLib.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef FOLLY_TEST_SYNCHRONIZEDTESTLIB_H
18 | #define FOLLY_TEST_SYNCHRONIZEDTESTLIB_H
19 |
20 | // We have mutex types outside of folly that we want to test with Synchronized.
21 | // Make it easy for mutex implementators to test their classes with
22 | // Synchronized by just having a test like:
23 | //
24 | // class MyMutex { ... };
25 | //
26 | // TEST(Synchronized, Basic) {
27 | // testBasic();
28 | // }
29 | //
30 | // ... similar for testConcurrency, testDualLocking, etc.
31 |
32 |
33 | template void testBasic();
34 |
35 | template void testConcurrency();
36 |
37 | template void testDualLocking();
38 |
39 | template void testDualLockingWithConst();
40 |
41 | template void testTimedSynchronized();
42 |
43 | template void testTimedSynchronizedWithConst();
44 |
45 | template void testConstCopy();
46 |
47 | #include
48 |
49 | #endif /* FOLLY_TEST_SYNCHRONIZEDTESTLIB_H */
50 |
--------------------------------------------------------------------------------
/folly/wangle/acceptor/ConnectionCounter.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2015, Facebook, Inc.
3 | * All rights reserved.
4 | *
5 | * This source code is licensed under the BSD-style license found in the
6 | * LICENSE file in the root directory of this source tree. An additional grant
7 | * of patent rights can be found in the PATENTS file in the same directory.
8 | *
9 | */
10 | #pragma once
11 |
12 | namespace folly {
13 |
14 | class IConnectionCounter {
15 | public:
16 | virtual uint64_t getNumConnections() const = 0;
17 |
18 | /**
19 | * Get the maximum number of non-whitelisted client-side connections
20 | * across all Acceptors managed by this. A value
21 | * of zero means "unlimited."
22 | */
23 | virtual uint64_t getMaxConnections() const = 0;
24 |
25 | /**
26 | * Increment the count of client-side connections.
27 | */
28 | virtual void onConnectionAdded() = 0;
29 |
30 | /**
31 | * Decrement the count of client-side connections.
32 | */
33 | virtual void onConnectionRemoved() = 0;
34 | virtual ~IConnectionCounter() {}
35 | };
36 |
37 | class SimpleConnectionCounter: public IConnectionCounter {
38 | public:
39 | uint64_t getNumConnections() const override { return numConnections_; }
40 | uint64_t getMaxConnections() const override { return maxConnections_; }
41 | void setMaxConnections(uint64_t maxConnections) {
42 | maxConnections_ = maxConnections;
43 | }
44 |
45 | void onConnectionAdded() override { numConnections_++; }
46 | void onConnectionRemoved() override { numConnections_--; }
47 | virtual ~SimpleConnectionCounter() {}
48 |
49 | protected:
50 | uint64_t maxConnections_{0};
51 | uint64_t numConnections_{0};
52 | };
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/folly/docs/FBString.md:
--------------------------------------------------------------------------------
1 | `folly/FBString.h`
2 | ------------------
3 |
4 | `fbstring` is a drop-in replacement for `std::string`. The main
5 | benefit of `fbstring` is significantly increased performance on
6 | virtually all important primitives. This is achieved by using a
7 | three-tiered storage strategy and by cooperating with the memory
8 | allocator. In particular, `fbstring` is designed to detect use of
9 | jemalloc and cooperate with it to achieve significant improvements in
10 | speed and memory usage.
11 |
12 | `fbstring` supports x32 and x64 architectures. Porting it to big endian
13 | architectures would require some changes.
14 |
15 | ### Storage strategies
16 | ***
17 |
18 | * Small strings (<= 23 chars) are stored in-situ without memory
19 | allocation.
20 |
21 | * Medium strings (24 - 255 chars) are stored in malloc-allocated
22 | memory and copied eagerly.
23 |
24 | * Large strings (> 255 chars) are stored in malloc-allocated memory and
25 | copied lazily.
26 |
27 | ### Implementation highlights
28 | ***
29 |
30 | * 100% compatible with `std::string`.
31 |
32 | * Thread-safe reference counted copy-on-write for strings "large"
33 | strings (> 255 chars).
34 |
35 | * Uses `malloc` instead of allocators.
36 |
37 | * Jemalloc-friendly. `fbstring` automatically detects if application
38 | uses jemalloc and if so, significantly improves allocation
39 | strategy by using non-standard jemalloc extensions.
40 |
41 | * `find()` is implemented using simplified Boyer-Moore
42 | algorithm. Casual tests indicate a 30x speed improvement over
43 | `string::find()` for successful searches and a 1.5x speed
44 | improvement for failed searches.
45 |
46 | * Offers conversions to and from `std::string`.
--------------------------------------------------------------------------------
/folly/wangle/concurrent/NamedThreadFactory.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015 Facebook, Inc.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #pragma once
18 |
19 | #include
20 | #include
21 | #include