xref: /trunk/main/cppu/source/threadpool/thread.hxx (revision c6ed87c9)
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 _CPPU_THREADPOOL_THREAD_HXX
24 #define _CPPU_THREADPOOL_THREAD_HXX
25 
26 #include <list>
27 #include <sal/types.h>
28 
29 #include <osl/thread.h>
30 
31 #include "jobqueue.hxx"
32 
33 namespace cppu_threadpool {
34 
35 	class JobQueue;
36 	class ThreadAdmin;
37 	typedef boost::shared_ptr<ThreadAdmin> ThreadAdminHolder;
38 
39     //-----------------------------------------
40     // private thread class for the threadpool
41     // independent from vos
42     //-----------------------------------------
43 	class ORequestThread
44 	{
45 	public:
46 		ORequestThread( JobQueue * ,
47 						const ::rtl::ByteSequence &aThreadId,
48 						sal_Bool bAsynchron );
49 		~ORequestThread();
50 
51 		void setTask( JobQueue * , const ::rtl::ByteSequence & aThreadId , sal_Bool bAsynchron );
52 
53 		sal_Bool create();
54 		void join();
55 		void onTerminated();
56 		void run();
setDeleteSelf(sal_Bool b)57 		inline void setDeleteSelf( sal_Bool b )
58 			{ m_bDeleteSelf = b; }
59 
60 	private:
61 		oslThread m_thread;
62 		ThreadAdminHolder m_aThreadAdmin;
63 		JobQueue *m_pQueue;
64 		::rtl::ByteSequence m_aThreadId;
65 		sal_Bool m_bAsynchron;
66 		sal_Bool m_bDeleteSelf;
67 	};
68 
69 	class ThreadAdmin
70 	{
71 	public:
72 		~ThreadAdmin ();
73 		static ThreadAdminHolder &getInstance();
74 		void add( ORequestThread * );
75 		void remove( ORequestThread * );
76 		void join();
77 
78 	private:
79 		::osl::Mutex m_mutex;
80 		::std::list< ORequestThread * > m_lst;
81 	};
82 
83 } // end cppu_threadpool
84 
85 
86 #endif
87 
88