Skip to content

Commit

Permalink
Update shared_mutex thirdparty to not prioritize writers (#2976)
Browse files Browse the repository at this point in the history
* Add test for multithreaded creation of readers on a single subscriber.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Add DataWriter.

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>

* Refs 15766: Refactor of shared_mutex to select writer priority

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: CMake update to force third party shared mutex if the framework prioritizes writing.

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: Add atomic support for some debian distros

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: Allow recursiveness on participant endpoint collection mutexes. Now they always allow them.

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: linter pass

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: Generate the config.h file when the USE_THIRDPARTY_SHARED_MUTEX value is already specified.

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: Mandatory piggyback: avoid polution on free_pools_ collection

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: Add some missing members to shared_lock thirdparty

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766: linter

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. shared_mutex testing

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. fixing gtest backward compatibility issues

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Add a new test to check priority is right

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Fixing gcc build warnings

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Fixing clang build warnings

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Make thirdparty versions always available even if none is used as eprosima::shared_mutex.

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Addressing reviewers comments

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

* Refs 15766. Fixing sync issue on ProxyPool.

Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>

Signed-off-by: Miguel Company <MiguelCompany@eprosima.com>
Signed-off-by: Miguel Barro <miguelbarro@eprosima.com>
Co-authored-by: Miguel Company <MiguelCompany@eprosima.com>
  • Loading branch information
2 people authored and Miguel Barro committed Nov 15, 2022
1 parent 7ee6000 commit 70bac5a
Show file tree
Hide file tree
Showing 11 changed files with 852 additions and 90 deletions.
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;
}
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
Loading

0 comments on commit 70bac5a

Please sign in to comment.