Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15766] Update shared_mutex thirdparty to don't prioritize writers #2976

Merged
merged 19 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,6 @@ endif()

option(SQLITE3_SUPPORT "Activate SQLITE3 support" ON)

option(USE_THIRDPARTY_SHARED_MUTEX [=[
Forces the use of a Boost-based shared_mutex implementation
instead of the framework one. Useful to cope with issues on
framework implementations like misguided sanitizer reports.
This implementation will be used by default on frameworks
lacking the shared_mutex feature like those not fulfilling
C++17.
]=] OFF)

###############################################################################
# SHM as Default transport
###############################################################################
Expand Down
5 changes: 5 additions & 0 deletions cmake/common/gtest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ macro(add_gtest)
# Normal tests
file(STRINGS ${GTEST_SOURCE_FILE} GTEST_TEST_NAMES REGEX "^([T][Y][P][E][D][_])?TEST")
foreach(GTEST_TEST_NAME ${GTEST_TEST_NAMES})

if(GTEST_TEST_NAME MATCHES "TYPED_TEST_SUITE")
continue()
endif()

string(REGEX REPLACE ["\) \(,"] ";" GTEST_TEST_NAME ${GTEST_TEST_NAME})
list(GET GTEST_TEST_NAME 1 GTEST_GROUP_NAME)
list(GET GTEST_TEST_NAME 3 GTEST_TEST_NAME)
Expand Down
69 changes: 69 additions & 0 deletions cmake/modules/check_shared_mutex_priority.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2022 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// 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.

/**
* @file check_shared_mutex_priority.cpp
*
*/

#include <atomic>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <shared_mutex>
#include <thread>

using namespace std;

int main()
{
shared_mutex sm;
atomic_bool mark = false;

// take first shared lock
sm.lock_shared();

// signal is taken
thread exclusive([&]()
{
mark = true;
lock_guard<shared_mutex> guard(sm);
});

// Wait till the thread takes the lock
do
{
this_thread::sleep_for(chrono::milliseconds(100));
}
while (!mark);

// try take the second shared lock
bool success = sm.try_lock_shared();
if (success)
{
sm.unlock_shared();
cout << "PTHREAD_RWLOCK_PREFER_READER_NP" << endl;
}
else
{
cout << "PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP" << endl;
}

// release first lock
sm.unlock_shared();
// wait for the main thread
exclusive.join();

return 0;
}
Loading