1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _SWTHREADMANAGER_HXX
24 #define _SWTHREADMANAGER_HXX
25 
26 #include <osl/interlck.h>
27 #include <osl/mutex.hxx>
28 #include <rtl/ref.hxx>
29 
30 #include <boost/utility.hpp>
31 #include <memory>
32 
33 
34 class ObservableThread;
35 class ThreadManager;
36 
37 /** class to manage threads in Writer using a <ThreadManager> instance
38 
39     OD 2007-04-13 #i73788#
40     Conforms the singleton pattern
41 
42     @author OD
43 */
44 class SwThreadManager
45     : private ::boost::noncopyable
46 {
47     public:
48 
49         static SwThreadManager& GetThreadManager();
50 
51         static bool ExistsThreadManager();
52 
53         // private: don't call!
54         SwThreadManager();
55         // private: don't call!
56         ~SwThreadManager();
57 
58         oslInterlockedCount AddThread( const rtl::Reference< ObservableThread >& rThread );
59 
60         void RemoveThread( const oslInterlockedCount nThreadID );
61 
62         /** suspend the starting of threads
63 
64             Suspending the starting of further threads is sensible during the
65             destruction of a Writer document.
66 
67             @author OD
68         */
69         void SuspendStartingOfThreads();
70 
71         /** continues the starting of threads after it has been suspended
72 
73             @author OD
74         */
75         void ResumeStartingOfThreads();
76 
77         bool StartingOfThreadsSuspended();
78 
79     private:
80         static bool mbThreadManagerInstantiated;
81 
82         ::std::auto_ptr<ThreadManager> mpThreadManagerImpl;
83 
84 };
85 #endif
86