Kaydet (Commit) 123c5934 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Adapted GCThread to safer-to-use salhelper::Thread

üst a342b3e3
bgpu pyuno : stoc cpputools cppuhelper bridges tools PYTHON:python LIBXSLT:libxslt NULL bgpu pyuno : salhelper stoc cpputools cppuhelper bridges tools PYTHON:python LIBXSLT:libxslt NULL
pu pyuno usr1 - all br_mkout NULL pu pyuno usr1 - all br_mkout NULL
pu pyuno\zipcore nmake - all pu_zipcore NULL pu pyuno\zipcore nmake - all pu_zipcore NULL
pu pyuno\source\module nmake - all pu_module NULL pu pyuno\source\module nmake - all pu_module NULL
......
...@@ -92,6 +92,7 @@ SHL1STDLIBS= \ ...@@ -92,6 +92,7 @@ SHL1STDLIBS= \
$(CPPULIB) \ $(CPPULIB) \
$(CPPUHELPERLIB) \ $(CPPUHELPERLIB) \
$(SALLIB) \ $(SALLIB) \
$(SALHELPERLIB) \
$(PYTHONLIB) \ $(PYTHONLIB) \
$(EXTRA_FRAMEWORK_FLAG) $(EXTRA_FRAMEWORK_FLAG)
......
...@@ -25,8 +25,14 @@ ...@@ -25,8 +25,14 @@
* for a copy of the LGPLv3 License. * for a copy of the LGPLv3 License.
* *
************************************************************************/ ************************************************************************/
#include <pyuno_impl.hxx>
#include <osl/thread.hxx> #include "pyuno_impl.hxx"
#include "sal/config.h"
#include "rtl/ref.hxx"
#include "salhelper/thread.hxx"
namespace pyuno namespace pyuno
{ {
...@@ -47,25 +53,25 @@ static bool isAfterUnloadOrPy_Finalize() ...@@ -47,25 +53,25 @@ static bool isAfterUnloadOrPy_Finalize()
!Py_IsInitialized(); !Py_IsInitialized();
} }
class GCThread : public ::osl::Thread class GCThread: public salhelper::Thread {
{
PyObject *mPyObject;
PyInterpreterState *mPyInterpreter;
GCThread( const GCThread & ); // not implemented
GCThread &operator =( const GCThread & ); // not implemented
public: public:
GCThread( PyInterpreterState *interpreter, PyObject * object ); GCThread( PyInterpreterState *interpreter, PyObject * object );
virtual void SAL_CALL run();
virtual void SAL_CALL onTerminated();
};
private:
virtual ~GCThread() {}
virtual void execute();
PyObject *mPyObject;
PyInterpreterState *mPyInterpreter;
};
GCThread::GCThread( PyInterpreterState *interpreter, PyObject * object ) : GCThread::GCThread( PyInterpreterState *interpreter, PyObject * object ) :
mPyObject( object ), mPyInterpreter( interpreter ) Thread( "pyunoGCThread" ), mPyObject( object ),
mPyInterpreter( interpreter )
{} {}
void GCThread::run() void GCThread::execute()
{ {
// otherwise we crash here, when main has been left already // otherwise we crash here, when main has been left already
if( isAfterUnloadOrPy_Finalize() ) if( isAfterUnloadOrPy_Finalize() )
...@@ -95,12 +101,6 @@ void GCThread::run() ...@@ -95,12 +101,6 @@ void GCThread::run()
} }
} }
void GCThread::onTerminated()
{
delete this;
}
void decreaseRefCount( PyInterpreterState *interpreter, PyObject *object ) void decreaseRefCount( PyInterpreterState *interpreter, PyObject *object )
{ {
// otherwise we crash in the last after main ... // otherwise we crash in the last after main ...
...@@ -111,11 +111,11 @@ void decreaseRefCount( PyInterpreterState *interpreter, PyObject *object ) ...@@ -111,11 +111,11 @@ void decreaseRefCount( PyInterpreterState *interpreter, PyObject *object )
// to be a method, which tells, whether the global // to be a method, which tells, whether the global
// interpreter lock is held or not // interpreter lock is held or not
// TODO: Look for a more efficient solution // TODO: Look for a more efficient solution
osl::Thread *t = new GCThread( interpreter, object ); rtl::Reference< GCThread >(new GCThread(interpreter, object))->launch();
// don't call create() because Valgrind complains about invalid read in //TODO: a protocol is missing how to join with the launched thread
// the rather bizarre GCThread::onTerminated; try a lame workaround: // before exit(3), to ensure the thread is no longer relying on any
t->createSuspended(); // infrastructure while that infrastructure is being shut down in
t->resume(); // atexit handlers
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment