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 (backport #2976) #3091

Merged
merged 3 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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;
}
2 changes: 2 additions & 0 deletions include/fastrtps/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
#define HAVE_SQLITE3 @HAVE_SQLITE3@
#endif /* ifndef HAVE_SQLITE3 */

// Using thirdparty shared_mutex
#cmakedefine01 USE_THIRDPARTY_SHARED_MUTEX

// TLS support
#ifndef TLS_FOUND
Expand Down
3 changes: 3 additions & 0 deletions include/fastrtps/utils/ProxyPool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class ProxyPool

// return the resource
mask_.set(idx);

// notify the resource is free
cv_.notify_one();
}

public:
Expand Down
2 changes: 1 addition & 1 deletion include/fastrtps/utils/TimedConditionVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

#ifndef _UTILS_TIMEDCONDITIONVARIABLE_HPP_
#define _UTILS_TIMEDCONDITIONVARIABLE_HPP_
#include <fastrtps/config.h>
#include <fastrtps/fastrtps_dll.h>

/*
NOTE: Windows implementation temporary disabled due to aleatory high CPU consumption when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <foonathan/memory/detail/debug_helpers.hpp>

#include "ResourceLimitedContainerConfig.hpp"
#include "fastrtps/config.h"
#include <fastrtps/fastrtps_dll.h>

namespace eprosima {
namespace fastrtps {
Expand Down
Loading