sc/inc/formularesult.hxx              |   14 --------------
 sc/source/core/tool/formularesult.cxx |    9 +++------
 2 files changed, 3 insertions(+), 20 deletions(-)

New commits:
commit 0dffa005544ca29c8726aa008fadfccc5520e791
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Aug 11 12:14:13 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Aug 11 20:37:17 2022 +0200

    fix tsan data-race
    
    this check is not necessary, we are using a 32/64 bit counter (depending
    on platform) for some years now
    
    WARNING: ThreadSanitizer: data race (pid=90197)
      Atomic write of size 4 at 0x7b08002f474c by thread T90:
        #0 ScInterpreter::Interpret() interpr4.cxx:? (libsclo.so+0xb99c26)
        #1 ScFormulaCell::InterpretTail(ScInterpreterContext&, 
ScFormulaCell::ScInterpretTailParameter) ??:? (libsclo.so+0x95bfeb)
        #2 ScColumn::CalculateInThread(ScInterpreterContext&, int, unsigned 
long, unsigned long, unsigned int, unsigned int) column2.cxx:? 
(libsclo.so+0x754eea)
        #3 ScTable::CalculateInColumnInThread(ScInterpreterContext&, short, 
short, int, int, unsigned int, unsigned int) table1.cxx:? (libsclo.so+0x9e692b)
        #4 ScDocument::CalculateInColumnInThread(ScInterpreterContext&, ScRange 
const&, unsigned int, unsigned int) documen8.cxx:? (libsclo.so+0x83479f)
        #5 
ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope&, 
bool&, bool&, int, int)::Executor::doWork() formulacell.cxx:? 
(libsclo.so+0x96b5e1)
        #6 comphelper::ThreadPool::ThreadWorker::execute() threadpool.cxx:? 
(libcomphelper.so+0x1cb0a1)
        #7 non-virtual thunk to salhelper::Thread::run() ??:? 
(libuno_salhelpergcc3.so.3+0x67f7)
        #8 threadFunc thread.cxx:? (libuno_salhelpergcc3.so.3+0x6aae)
        #9 osl_thread_start_Impl(void*) thread.cxx:? (libuno_sal.so.3+0x86245)
    
      Previous read of size 4 at 0x7b08002f474c by thread T89:
        #0 ScFormulaResult::SetToken(formula::FormulaToken const*) 
formularesult.cxx:? (libsclo.so+0xb0e11f)
        #1 ScFormulaResult::Assign(ScFormulaResult const&) formularesult.cxx:? 
(libsclo.so+0xb0e837)
        #2 ScFormulaCell::InterpretTail(ScInterpreterContext&, 
ScFormulaCell::ScInterpretTailParameter) ??:? (libsclo.so+0x95caa3)
        #3 ScColumn::CalculateInThread(ScInterpreterContext&, int, unsigned 
long, unsigned long, unsigned int, unsigned int) column2.cxx:? 
(libsclo.so+0x754eea)
        #4 ScTable::CalculateInColumnInThread(ScInterpreterContext&, short, 
short, int, int, unsigned int, unsigned int) table1.cxx:? (libsclo.so+0x9e692b)
        #5 ScDocument::CalculateInColumnInThread(ScInterpreterContext&, ScRange 
const&, unsigned int, unsigned int) documen8.cxx:? (libsclo.so+0x83479f)
        #6 
ScFormulaCell::InterpretFormulaGroupThreading(sc::FormulaLogger::GroupScope&, 
bool&, bool&, int, int)::Executor::doWork() formulacell.cxx:? 
(libsclo.so+0x96b5e1)
        #7 comphelper::ThreadPool::ThreadWorker::execute() threadpool.cxx:? 
(libcomphelper.so+0x1cb0a1)
        #8 non-virtual thunk to salhelper::Thread::run() ??:? 
(libuno_salhelpergcc3.so.3+0x67f7)
        #9 threadFunc thread.cxx:? (libuno_salhelpergcc3.so.3+0x6aae)
        #10 osl_thread_start_Impl(void*) thread.cxx:? (libuno_sal.so.3+0x86245)
    
    Change-Id: I3e51db3a8a0a18fee1647657369ecebf5de108e7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138137
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/inc/formularesult.hxx b/sc/inc/formularesult.hxx
index 52be625b7b82..ff036a78bcb3 100644
--- a/sc/inc/formularesult.hxx
+++ b/sc/inc/formularesult.hxx
@@ -55,20 +55,6 @@ class ScFormulaResult
     static const Multiline MULTILINE_FALSE   = 1;
     static const Multiline MULTILINE_TRUE    = 2;
 
-    // Clone token if the 16-bit only reference counter is nearing it's
-    // capacity during fill or copy&paste, leaving 4k for temporary passing
-    // around. (That should be enough for all times (TM) ;-)
-    static const sal_uInt16 MAX_TOKENREF_COUNT = 0xf000;
-    static void IncrementTokenRef( const formula::FormulaToken* & rp )
-    {
-        if (rp)
-        {
-            if (rp->GetRef() >= MAX_TOKENREF_COUNT)
-                rp = rp->Clone();
-            rp->IncRef();
-        }
-    }
-
     union
     {
         double          mfValue;    // double result direct for performance 
and memory consumption
diff --git a/sc/source/core/tool/formularesult.cxx 
b/sc/source/core/tool/formularesult.cxx
index d4b146dfe3bd..31b13af8fea8 100644
--- a/sc/source/core/tool/formularesult.cxx
+++ b/sc/source/core/tool/formularesult.cxx
@@ -52,12 +52,8 @@ ScFormulaResult::ScFormulaResult( const ScFormulaResult & r 
) :
             const ScMatrixFormulaCellToken* pMatFormula =
                 r.GetMatrixFormulaCellToken();
             if (pMatFormula)
-            {
                 mpToken = new ScMatrixFormulaCellToken( *pMatFormula);
-                mpToken->IncRef();
-            }
-            else
-                IncrementTokenRef( mpToken);
+            mpToken->IncRef();
         }
     }
     else
@@ -181,7 +177,8 @@ void ScFormulaResult::Assign( const ScFormulaResult & r )
 void ScFormulaResult::SetToken( const formula::FormulaToken* p )
 {
     ResetToDefaults();
-    IncrementTokenRef( p);
+    if (p)
+        p->IncRef();
     // Handle a result obtained from the interpreter to be assigned to a matrix
     // formula cell's ScMatrixFormulaCellToken.
     ScMatrixFormulaCellToken* pMatFormula = 
GetMatrixFormulaCellTokenNonConst();

Reply via email to