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

View file

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

View file

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

View file

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