forked from reactivemarkets/toolbox-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend thread config to include affinity
The ThreadConfig structure should be extended to include an isolcpus-style affinity mask, along with helper functions for parsing and setting thread affinity. Closes reactivemarkets#49
- Loading branch information
1 parent
87e9261
commit 81d377a
Showing
11 changed files
with
139 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
cppcheckError:*/toolbox/util/IntTypes.ut.cpp | ||
syntaxError:*/toolbox/sys/Thread.cpp | ||
preprocessorErrorDirective:*/toolbox/net/Error.cpp | ||
preprocessorErrorDirective:*/toolbox/sys/Error.cpp | ||
returnDanglingLifetime:*/toolbox/io/Timer.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// The Reactive C++ Toolbox. | ||
// Copyright (C) 2013-2019 Swirly Cloud Limited | ||
// Copyright (C) 2019 Reactive Markets Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "Thread.hpp" | ||
|
||
#include <boost/test/unit_test.hpp> | ||
|
||
using namespace std; | ||
using namespace toolbox; | ||
|
||
namespace { | ||
uint32_t to_bitset(const cpu_set_t& cpuset) noexcept | ||
{ | ||
uint32_t bs{0}; | ||
for (int i{0}; i < 32; ++i) { | ||
if (CPU_ISSET(i, &cpuset)) { | ||
bs |= (1 << i); | ||
} | ||
} | ||
return bs; | ||
} | ||
} // namespace | ||
|
||
BOOST_AUTO_TEST_SUITE(ThreadSuite) | ||
|
||
BOOST_AUTO_TEST_CASE(ThreadParseCpuSetCase) | ||
{ | ||
BOOST_TEST(to_bitset(parse_cpu_set(""sv)) == 0b0); | ||
BOOST_TEST(to_bitset(parse_cpu_set("0"sv)) == 0b1); | ||
BOOST_TEST(to_bitset(parse_cpu_set("1,2"sv)) == 0b110); | ||
BOOST_TEST(to_bitset(parse_cpu_set("0-3"sv)) == 0b1111); | ||
BOOST_TEST(to_bitset(parse_cpu_set("1,2,4-7"sv)) == 0b11110110); | ||
BOOST_TEST(to_bitset(parse_cpu_set("0-3,5,6,8-11"sv)) == 0b111101101111); | ||
} | ||
|
||
BOOST_AUTO_TEST_SUITE_END() |