Skip to content

Commit

Permalink
A fix for #84.
Browse files Browse the repository at this point in the history
  • Loading branch information
eao197 committed Oct 16, 2024
1 parent a2ab68a commit 7b46938
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
29 changes: 19 additions & 10 deletions dev/so_5/details/sync_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
* \file
* \brief Basic tools for simplify usage of std::mutex or null_mutex
*
* \since
* v.5.5.19
* \since v.5.5.19
*/

#pragma once
Expand All @@ -22,8 +21,11 @@ namespace so_5 {
/*!
* \brief A class which is like std::mutex but does not do any real actions.
*
* \since
* v.5.5.19.2
* \note
* Since v.5.8.3 it can also be used instead of std::shared_mutex because
* empty method lock_shared() and unlock_shared() were added in v.5.8.3.
*
* \since v.5.5.19.2
*/
class null_mutex_t
{
Expand All @@ -34,6 +36,16 @@ class null_mutex_t

void lock() {}
void unlock() {}

/*!
* \since v.5.8.3
*/
void lock_shared() {}

/*!
* \since v.5.8.3
*/
void unlock_shared() {}
};

namespace details {
Expand Down Expand Up @@ -62,8 +74,7 @@ namespace details {
* \tparam Lock_Type type of lock to be used for object protection.
* Will be used with std::lock_guard.
*
* \since
* v.5.5.19
* \since v.5.5.19
*/
template< typename Lock_Type = std::mutex >
class actual_lock_holder_t
Expand Down Expand Up @@ -108,8 +119,7 @@ class actual_lock_holder_t
using non_mtsafe_coop_repo_t = coop_repo_t< so_5::details::no_lock_holder_t >;
* \endcode
*
* \since
* v.5.5.19
* \since v.5.5.19
*/
class no_lock_holder_t
{
Expand Down Expand Up @@ -143,8 +153,7 @@ class no_lock_holder_t
* };
* \endcode
*
* \since
* v.5.5.19.2
* \since v.5.5.19.2
*/
template< typename Lock_Type >
struct lock_holder_detector
Expand Down
1 change: 1 addition & 0 deletions dev/test/so_5/details/build_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
required_prj( "#{path}/invoke_noexcept_code/prj.ut.rb" )
required_prj( "#{path}/remaining_time_counter/prj.ut.rb" )
required_prj( "#{path}/lock_holder_detector/prj.ut.rb" )
required_prj( "#{path}/null_mutex_lock_shared/prj.ut.rb" )
}
27 changes: 27 additions & 0 deletions dev/test/so_5/details/null_mutex_lock_shared/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* A test for so_5::null_mutex_t and std::shared_lock.
*/

#include <so_5/details/sync_helpers.hpp>

#include <shared_mutex>
#include <iostream>
#include <type_traits>

template< typename Mutex >
void
lock_then_unlock_shared( Mutex && mtx )
{
std::shared_lock< std::decay_t<Mutex> > lock{ mtx };
std::cout << "lock_then_unlock_shared" << std::endl;
}

int
main()
{
so_5::null_mutex_t mtx;
lock_then_unlock_shared( mtx );

return 0;
}

11 changes: 11 additions & 0 deletions dev/test/so_5/details/null_mutex_lock_shared/prj.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'mxx_ru/cpp'

MxxRu::Cpp::exe_target {

required_prj 'so_5/prj.rb'

target '_unit.test.details.null_mutex_lock_shared'

cpp_source 'main.cpp'
}

9 changes: 9 additions & 0 deletions dev/test/so_5/details/null_mutex_lock_shared/prj.ut.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require 'mxx_ru/binary_unittest'

path = 'test/so_5/details/null_mutex_lock_shared'

MxxRu::setup_target(
MxxRu::BinaryUnittestTarget.new(
"#{path}/prj.ut.rb",
"#{path}/prj.rb" )
)

0 comments on commit 7b46938

Please sign in to comment.