Adds writer test case for RCU
[folly.git] / folly / test / function_benchmark / test_functions.cpp
1 /*
2  * Copyright 2011-present 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 <folly/test/function_benchmark/test_functions.h>
18
19 /*
20  * These functions are defined in a separate file so that
21  * gcc won't be able to inline them.
22  */
23
24
25 class Exception : public std::exception {
26  public:
27   explicit Exception(const std::string& value) : value_(value) {}
28   ~Exception() noexcept override {}
29
30   const char* what() const noexcept override {
31     return value_.c_str();
32   }
33
34  private:
35   std::string value_;
36 };
37
38 void doNothing() {
39 }
40
41 [[noreturn]]
42 void throwException() {
43   throw Exception("this is a test");
44 }
45
46 std::exception_ptr returnExceptionPtr() {
47   Exception ex("this is a test");
48   return std::make_exception_ptr(ex);
49 }
50
51 void exceptionPtrReturnParam(std::exception_ptr* excReturn) {
52   if (excReturn) {
53     Exception ex("this is a test");
54     *excReturn = std::make_exception_ptr(ex);
55   }
56 }
57
58 std::string returnString() {
59   return "this is a test";
60 }
61
62 std::string returnStringNoExcept() noexcept {
63   return "this is a test";
64 }
65
66 int returnCode(int value) {
67   return value;
68 }
69
70 int returnCodeNoExcept(int value) noexcept {
71   return value;
72 }
73
74 void TestClass::doNothing() {
75 }
76
77 VirtualClass::~VirtualClass() {
78 }
79
80 void VirtualClass::doNothing() {
81 };
82
83 LargeClass::LargeClass() {
84   // Suppress unused field warning
85   data[0] = 42;
86 }
87
88 void LargeClass::operator()() const {}
89
90 void invoke(std::function<void()> f) {
91   f();
92 }
93
94 void invoke(folly::Function<void()> f) {
95   f();
96 }