diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2012-05-23 09:42:37 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-05-23 10:10:51 +0200 |
commit | 2fa2660b55a34a5780f9ea8dbbbe92d05dc9a818 (patch) | |
tree | f0f32866a6b5e5cf0c2650c207d7405610a852e2 /binaryurp/source/bridge.hxx | |
parent | 124c020f4290911d2bfb8216c9680734722c8db7 (diff) |
Better fix for ThreadPool/ORequestThread life cycle
This is a follow up to d015384e1d98fe77fd59339044f58efb1ab9fb25 "Fixed
ThreadPool (and dependent ORequestThread) life cycle" that still had some
problems:
* First, if Bridge::terminate was first entered from the reader or writer
thread, it would not join on that thread, so that thread could still be running
during exit.
That has been addressed by giving Bridge::dispose new semantics: It waits until
both Bridge::terminate has completed (even if that was called from a different
thread) and all spawned threads (reader, writer, ORequestThread workers) have
been joined. (This implies that Bridge::dispose must not be called from such a
thread, to avoid deadlock.)
* Second, if Bridge::terminate was first entered from an ORequestThread, the
call to uno_threadpool_dispose(0) to join on all such worker threads could
deadlock.
That has been addressed by making the last call to uno_threadpool_destroy wait
to join on all worker threads, and by calling uno_threadpool_destroy only from
the final Bridge::terminate (from Bridge::dispose), to avoid deadlock. (The
special semantics of uno_threadpool_dispose(0) are no longer needed and have
been removed, as they conflicted with the fix for the third problem below.)
* Third, once uno_threadpool_destroy had called uno_threadpool_dispose(0), the
ThreadAdmin singleton had been disposed, so no new remote bridges could
successfully be created afterwards.
That has been addressed by making ThreadAdmin a member of ThreadPool, and making
(only) those uno_ThreadPool handles with overlapping life spans share one
ThreadPool instance (which thus is no longer a singleton, either).
Additionally, ORequestThread has been made more robust (in the style of
salhelper::Thread) to avoid races.
Change-Id: I2cbd1b3f9aecc1bf4649e482d2c22b33b471788f
Diffstat (limited to 'binaryurp/source/bridge.hxx')
-rw-r--r-- | binaryurp/source/bridge.hxx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/binaryurp/source/bridge.hxx b/binaryurp/source/bridge.hxx index 8d667897d253..3ffbfbaeb43b 100644 --- a/binaryurp/source/bridge.hxx +++ b/binaryurp/source/bridge.hxx @@ -93,8 +93,11 @@ public: void start(); // Internally waits for all incoming and outgoing remote calls to terminate, - // so must not be called from within such a call: - void terminate(); + // so must not be called from within such a call; when final is true, also + // joins all remaining threads (reader, writer, and worker threads from the + // thread pool), so must not be called with final set to true from such a + // thread: + void terminate(bool final); com::sun::star::uno::Reference< com::sun::star::connection::XConnection > getConnection() const; @@ -228,6 +231,9 @@ private: void terminateWhenUnused(bool unused); + // Must only be called with mutex_ locked: + void checkDisposed(); + typedef std::list< com::sun::star::uno::Reference< @@ -240,6 +246,8 @@ private: typedef std::map< rtl::OUString, Stub > Stubs; + enum State { STATE_INITIAL, STATE_STARTED, STATE_TERMINATED, STATE_FINAL }; + enum Mode { MODE_REQUESTED, MODE_REPLY_MINUS1, MODE_REPLY_0, MODE_REPLY_1, MODE_WAIT, MODE_NORMAL, MODE_NORMAL_WAIT }; @@ -259,8 +267,15 @@ private: com::sun::star::uno::TypeDescription protPropRequest_; com::sun::star::uno::TypeDescription protPropCommit_; OutgoingRequests outgoingRequests_; + osl::Condition passive_; + // to guarantee that passive_ is eventually set (to avoid deadlock, see + // dispose), activeCalls_ only counts those calls for which it can be + // guaranteed that incrementActiveCalls is indeed followed by + // decrementActiveCalls, without an intervening exception + osl::Condition terminated_; osl::Mutex mutex_; + State state_; Listeners listeners_; uno_ThreadPool threadPool_; rtl::Reference< Writer > writer_; @@ -271,12 +286,6 @@ private: std::size_t calls_; bool normalCall_; std::size_t activeCalls_; - osl::Condition passive_; - // to guarantee that passive_ is eventually set (to avoid deadlock, see - // dispose), activeCalls_ only counts those calls for which it can be - // guaranteed that incrementActiveCalls is indeed followed by - // decrementActiveCalls, without an intervening exception - bool terminated_; // Only accessed from reader_ thread: Mode mode_; |