binaryurp: use more std::mutex

Change-Id: I1d16c4cbf60e78323b74e7df049736bd0d0ab591
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132072
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Arnaud Versini 2022-03-24 12:56:28 +01:00 committed by Noel Grandin
parent 38b8ca62dd
commit 34df7e2cb9
4 changed files with 30 additions and 30 deletions

View file

@ -207,7 +207,7 @@ void Bridge::start() {
rtl::Reference r(new Reader(this)); rtl::Reference r(new Reader(this));
rtl::Reference w(new Writer(this)); rtl::Reference w(new Writer(this));
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert( assert(
state_ == STATE_INITIAL && threadPool_ == nullptr && !writer_.is() && state_ == STATE_INITIAL && threadPool_ == nullptr && !writer_.is() &&
!reader_.is()); !reader_.is());
@ -237,7 +237,7 @@ void Bridge::terminate(bool final) {
bool joinW; bool joinW;
Listeners ls; Listeners ls;
{ {
osl::ClearableMutexGuard g(mutex_); std::unique_lock g(mutex_);
switch (state_) { switch (state_) {
case STATE_INITIAL: // via ~Bridge -> dispose -> terminate case STATE_INITIAL: // via ~Bridge -> dispose -> terminate
case STATE_FINAL: case STATE_FINAL:
@ -246,10 +246,10 @@ void Bridge::terminate(bool final) {
break; break;
case STATE_TERMINATED: case STATE_TERMINATED:
if (final) { if (final) {
g.clear(); g.unlock();
terminated_.wait(); terminated_.wait();
{ {
osl::MutexGuard g2(mutex_); std::lock_guard g2(mutex_);
tp = threadPool_; tp = threadPool_;
threadPool_ = nullptr; threadPool_ = nullptr;
if (reader_.is()) { if (reader_.is()) {
@ -309,7 +309,7 @@ void Bridge::terminate(bool final) {
uno_threadpool_dispose(tp); uno_threadpool_dispose(tp);
Stubs s; Stubs s;
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
s.swap(stubs_); s.swap(stubs_);
} }
for (auto & stub : s) for (auto & stub : s)
@ -340,7 +340,7 @@ void Bridge::terminate(bool final) {
uno_threadpool_destroy(tp); uno_threadpool_destroy(tp);
} }
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
if (final) { if (final) {
threadPool_ = nullptr; threadPool_ = nullptr;
} }
@ -361,14 +361,14 @@ BinaryAny Bridge::mapCppToBinaryAny(css::uno::Any const & cppAny) {
} }
uno_ThreadPool Bridge::getThreadPool() { uno_ThreadPool Bridge::getThreadPool() {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
checkDisposed(); checkDisposed();
assert(threadPool_ != nullptr); assert(threadPool_ != nullptr);
return threadPool_; return threadPool_;
} }
rtl::Reference< Writer > Bridge::getWriter() { rtl::Reference< Writer > Bridge::getWriter() {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
checkDisposed(); checkDisposed();
assert(writer_.is()); assert(writer_.is());
return writer_; return writer_;
@ -392,7 +392,7 @@ css::uno::UnoInterfaceReference Bridge::registerIncomingInterface(
} else { } else {
obj.set(new Proxy(this, oid, type), SAL_NO_ACQUIRE); obj.set(new Proxy(this, oid, type), SAL_NO_ACQUIRE);
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(proxies_ < std::numeric_limits< std::size_t >::max()); assert(proxies_ < std::numeric_limits< std::size_t >::max());
++proxies_; ++proxies_;
} }
@ -419,7 +419,7 @@ OUString Bridge::registerOutgoingInterface(
if (!Proxy::isProxy(this, object, &oid)) { if (!Proxy::isProxy(this, object, &oid)) {
binaryUno_.get()->pExtEnv->getObjectIdentifier( binaryUno_.get()->pExtEnv->getObjectIdentifier(
binaryUno_.get()->pExtEnv, &oid.pData, object.get()); binaryUno_.get()->pExtEnv, &oid.pData, object.get());
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
Stubs::iterator i(stubs_.find(oid)); Stubs::iterator i(stubs_.find(oid));
Stub newStub; Stub newStub;
Stub * stub = i == stubs_.end() ? &newStub : &i->second; Stub * stub = i == stubs_.end() ? &newStub : &i->second;
@ -458,7 +458,7 @@ css::uno::UnoInterfaceReference Bridge::findStub(
OUString const & oid, css::uno::TypeDescription const & type) OUString const & oid, css::uno::TypeDescription const & type)
{ {
assert(!oid.isEmpty() && type.is()); assert(!oid.isEmpty() && type.is());
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
Stubs::iterator i(stubs_.find(oid)); Stubs::iterator i(stubs_.find(oid));
if (i != stubs_.end()) { if (i != stubs_.end()) {
Stub::iterator j(i->second.find(type)); Stub::iterator j(i->second.find(type));
@ -484,7 +484,7 @@ void Bridge::releaseStub(
css::uno::UnoInterfaceReference obj; css::uno::UnoInterfaceReference obj;
bool unused; bool unused;
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
Stubs::iterator i(stubs_.find(oid)); Stubs::iterator i(stubs_.find(oid));
if (i == stubs_.end()) { if (i == stubs_.end()) {
throw css::uno::RuntimeException("URP: release unknown stub"); throw css::uno::RuntimeException("URP: release unknown stub");
@ -538,7 +538,7 @@ void Bridge::freeProxy(Proxy & proxy) {
} }
bool unused; bool unused;
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(proxies_ > 0); assert(proxies_ > 0);
--proxies_; --proxies_;
unused = becameUnused(); unused = becameUnused();
@ -547,7 +547,7 @@ void Bridge::freeProxy(Proxy & proxy) {
} }
void Bridge::incrementCalls(bool normalCall) noexcept { void Bridge::incrementCalls(bool normalCall) noexcept {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(calls_ < std::numeric_limits< std::size_t >::max()); assert(calls_ < std::numeric_limits< std::size_t >::max());
++calls_; ++calls_;
normalCall_ |= normalCall; normalCall_ |= normalCall;
@ -556,7 +556,7 @@ void Bridge::incrementCalls(bool normalCall) noexcept {
void Bridge::decrementCalls() { void Bridge::decrementCalls() {
bool unused; bool unused;
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(calls_ > 0); assert(calls_ > 0);
--calls_; --calls_;
unused = becameUnused(); unused = becameUnused();
@ -565,7 +565,7 @@ void Bridge::decrementCalls() {
} }
void Bridge::incrementActiveCalls() noexcept { void Bridge::incrementActiveCalls() noexcept {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert( assert(
activeCalls_ <= calls_ && activeCalls_ <= calls_ &&
activeCalls_ < std::numeric_limits< std::size_t >::max()); activeCalls_ < std::numeric_limits< std::size_t >::max());
@ -574,7 +574,7 @@ void Bridge::incrementActiveCalls() noexcept {
} }
void Bridge::decrementActiveCalls() noexcept { void Bridge::decrementActiveCalls() noexcept {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(activeCalls_ <= calls_ && activeCalls_ > 0); assert(activeCalls_ <= calls_ && activeCalls_ > 0);
--activeCalls_; --activeCalls_;
if (activeCalls_ == 0) { if (activeCalls_ == 0) {
@ -824,19 +824,19 @@ bool Bridge::isProtocolPropertiesRequest(
} }
void Bridge::setCurrentContextMode() { void Bridge::setCurrentContextMode() {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
currentContextMode_ = true; currentContextMode_ = true;
} }
bool Bridge::isCurrentContextMode() { bool Bridge::isCurrentContextMode() {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
return currentContextMode_; return currentContextMode_;
} }
Bridge::~Bridge() { Bridge::~Bridge() {
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
SAL_WARN_IF( SAL_WARN_IF(
state_ == STATE_STARTED || state_ == STATE_TERMINATED, "binaryurp", state_ == STATE_STARTED || state_ == STATE_TERMINATED, "binaryurp",
"undisposed bridge \"" << name_ <<"\" in state " << state_ "undisposed bridge \"" << name_ <<"\" in state " << state_
@ -925,7 +925,7 @@ void Bridge::addEventListener(
{ {
assert(xListener.is()); assert(xListener.is());
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
assert(state_ != STATE_INITIAL); assert(state_ != STATE_INITIAL);
if (state_ == STATE_STARTED) { if (state_ == STATE_STARTED) {
listeners_.push_back(xListener); listeners_.push_back(xListener);
@ -939,7 +939,7 @@ void Bridge::addEventListener(
void Bridge::removeEventListener( void Bridge::removeEventListener(
css::uno::Reference< css::lang::XEventListener > const & aListener) css::uno::Reference< css::lang::XEventListener > const & aListener)
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
Listeners::iterator i( Listeners::iterator i(
std::find(listeners_.begin(), listeners_.end(), aListener)); std::find(listeners_.begin(), listeners_.end(), aListener));
if (i != listeners_.end()) { if (i != listeners_.end()) {

View file

@ -23,6 +23,7 @@
#include <cstddef> #include <cstddef>
#include <map> #include <map>
#include <mutex>
#include <vector> #include <vector>
#include <com/sun/star/bridge/XBridge.hpp> #include <com/sun/star/bridge/XBridge.hpp>
@ -257,7 +258,7 @@ private:
// decrementActiveCalls, without an intervening exception // decrementActiveCalls, without an intervening exception
osl::Condition terminated_; osl::Condition terminated_;
osl::Mutex mutex_; std::mutex mutex_;
State state_; State state_;
Listeners listeners_; Listeners listeners_;
uno_ThreadPool threadPool_; uno_ThreadPool threadPool_;

View file

@ -31,7 +31,6 @@
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/uno/XCurrentContext.hpp> #include <com/sun/star/uno/XCurrentContext.hpp>
#include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/exc_hlp.hxx>
#include <osl/mutex.hxx>
#include <sal/log.hxx> #include <sal/log.hxx>
#include <uno/dispatcher.hxx> #include <uno/dispatcher.hxx>
@ -108,7 +107,7 @@ void Writer::queueRequest(
std::vector< BinaryAny >&& inArguments) std::vector< BinaryAny >&& inArguments)
{ {
css::uno::UnoInterfaceReference cc(current_context::get()); css::uno::UnoInterfaceReference cc(current_context::get());
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
queue_.emplace_back(tid, oid, type, member, std::move(inArguments), cc); queue_.emplace_back(tid, oid, type, member, std::move(inArguments), cc);
items_.set(); items_.set();
} }
@ -119,7 +118,7 @@ void Writer::queueReply(
bool exception, BinaryAny const & returnValue, bool exception, BinaryAny const & returnValue,
std::vector< BinaryAny >&& outArguments, bool setCurrentContextMode) std::vector< BinaryAny >&& outArguments, bool setCurrentContextMode)
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
queue_.emplace_back( queue_.emplace_back(
tid, member, setter, exception, returnValue, std::move(outArguments), tid, member, setter, exception, returnValue, std::move(outArguments),
setCurrentContextMode); setCurrentContextMode);
@ -135,7 +134,7 @@ void Writer::unblock() {
void Writer::stop() { void Writer::stop() {
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
stop_ = true; stop_ = true;
} }
unblocked_.set(); unblocked_.set();
@ -151,7 +150,7 @@ void Writer::execute() {
items_.wait(); items_.wait();
Item item; Item item;
{ {
osl::MutexGuard g(mutex_); std::lock_guard g(mutex_);
if (stop_) { if (stop_) {
return; return;
} }

View file

@ -22,10 +22,10 @@
#include <sal/config.h> #include <sal/config.h>
#include <deque> #include <deque>
#include <mutex>
#include <vector> #include <vector>
#include <osl/conditn.hxx> #include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <rtl/byteseq.hxx> #include <rtl/byteseq.hxx>
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <rtl/ustring.hxx> #include <rtl/ustring.hxx>
@ -141,7 +141,7 @@ private:
osl::Condition unblocked_; osl::Condition unblocked_;
osl::Condition items_; osl::Condition items_;
osl::Mutex mutex_; std::mutex mutex_;
std::deque< Item > queue_; std::deque< Item > queue_;
bool stop_; bool stop_;
}; };