[Libreoffice-commits] core.git: include/vcl
Noel Grandin
noel.grandin at collabora.co.uk
Wed Mar 8 06:32:16 UTC 2017
include/vcl/vclreferencebase.hxx | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
New commits:
commit 0531ffaf99941ad1d1a1c79b368c086cd9e64516
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Tue Mar 7 14:47:04 2017 +0200
convert VclReferenceBase::mnRefCnt to oslInterlockedCount
Which means that ref-counting VCL widgets is now thread-safe.
Destroying them, however, is not safe without holding the SolarMutex,
which will the subject of a future patch.
According to my tests running 'perf stat make check', this costs us
approx 2% runtime on a non-debug Linux build using gcc.
Costs are quite a bit higher when building with clang, which might need
further investigation.
Change-Id: I737170b74ec79e6b7c7d586ed5be89a73ee83597
Reviewed-on: https://gerrit.libreoffice.org/34948
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/include/vcl/vclreferencebase.hxx b/include/vcl/vclreferencebase.hxx
index af60e2d..f5399c8 100644
--- a/include/vcl/vclreferencebase.hxx
+++ b/include/vcl/vclreferencebase.hxx
@@ -21,6 +21,7 @@
#include <vcl/dllapi.h>
#include <tools/debug.hxx>
+#include <osl/interlck.h>
#include <cassert>
@@ -28,21 +29,19 @@ class VclReferenceBase;
class VCL_DLLPUBLIC VclReferenceBase
{
- mutable int mnRefCnt;
+ mutable oslInterlockedCount mnRefCnt;
template<typename T> friend class VclPtr;
public:
void acquire() const
{
- assert(mnRefCnt>0);
- mnRefCnt++;
+ osl_atomic_increment(&mnRefCnt);
}
void release() const
{
- assert(mnRefCnt>0);
- if (!--mnRefCnt)
+ if (osl_atomic_decrement(&mnRefCnt) == 0)
delete this;
}
private:
More information about the Libreoffice-commits
mailing list