meganz / sdk

MEGA C++ SDK
BSD 2-Clause "Simplified" License
1.34k stars 508 forks source link

Compile error: `std::recursive_mutex` has no member named `owns_lock` #2679

Closed dbermond closed 5 months ago

dbermond commented 5 months ago

In src/nodemanager.cpp, every occurrence of mMutex.owns_lock() gives the following compile error:

In file included from /usr/include/c++/14.1.1/cassert:44,
                 from /build/megasync/src/MEGAsync/src/MEGASync/mega/include/mega/fuse/common/pending_callbacks.h:3,
                 from /build/megasync/src/MEGAsync/src/MEGASync/mega/include/mega/fuse/common/client_adapter.h:10,
                 from /build/megasync/src/MEGAsync/src/MEGASync/mega/include/mega/megaclient.h:47,
                 from /build/megasync/src/MEGAsync/src/MEGASync/mega/src/nodemanager.cpp:23:
/build/megasync/src/MEGAsync/src/MEGASync/mega/src/nodemanager.cpp: In member function ‘void mega::NodeManager::setTable_internal(mega::DBTableNodes*)’:
/build/megasync/src/MEGAsync/src/MEGASync/mega/src/nodemanager.cpp:46:19: error: ‘using mega::NodeManager::MutexType = class std::recursive_mutex’ {aka ‘class std::recursive_mutex’} has no member named ‘owns_lock’
   46 |     assert(mMutex.owns_lock());
      |                   ^~~~~~~~~

That's because the mMutex variable is of type std::recursive_mutex (in non debug builds), which in turn does not have an own_lock() method. A mutex cannot check if it owns the lock for itself, and lock variables like std::unique_lock must to be used for this purpose.

System Information:

dbermond commented 5 months ago

Looks like this happens only when using the CMake None build type due to absence of NDEBUG definition on it. Closing.