xref: /aoo42x/main/cppu/source/threadpool/thread.hxx (revision c6ed87c9)
1*c6ed87c9SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c6ed87c9SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c6ed87c9SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c6ed87c9SAndrew Rist  * distributed with this work for additional information
6*c6ed87c9SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c6ed87c9SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c6ed87c9SAndrew Rist  * "License"); you may not use this file except in compliance
9*c6ed87c9SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c6ed87c9SAndrew Rist  *
11*c6ed87c9SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c6ed87c9SAndrew Rist  *
13*c6ed87c9SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c6ed87c9SAndrew Rist  * software distributed under the License is distributed on an
15*c6ed87c9SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c6ed87c9SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c6ed87c9SAndrew Rist  * specific language governing permissions and limitations
18*c6ed87c9SAndrew Rist  * under the License.
19*c6ed87c9SAndrew Rist  *
20*c6ed87c9SAndrew Rist  *************************************************************/
21*c6ed87c9SAndrew Rist 
22*c6ed87c9SAndrew Rist 
23cdf0e10cSrcweir #ifndef _CPPU_THREADPOOL_THREAD_HXX
24cdf0e10cSrcweir #define _CPPU_THREADPOOL_THREAD_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <list>
27cdf0e10cSrcweir #include <sal/types.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <osl/thread.h>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "jobqueue.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace cppu_threadpool {
34cdf0e10cSrcweir 
35cdf0e10cSrcweir 	class JobQueue;
36cdf0e10cSrcweir 	class ThreadAdmin;
37cdf0e10cSrcweir 	typedef boost::shared_ptr<ThreadAdmin> ThreadAdminHolder;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir     //-----------------------------------------
40cdf0e10cSrcweir     // private thread class for the threadpool
41cdf0e10cSrcweir     // independent from vos
42cdf0e10cSrcweir     //-----------------------------------------
43cdf0e10cSrcweir 	class ORequestThread
44cdf0e10cSrcweir 	{
45cdf0e10cSrcweir 	public:
46cdf0e10cSrcweir 		ORequestThread( JobQueue * ,
47cdf0e10cSrcweir 						const ::rtl::ByteSequence &aThreadId,
48cdf0e10cSrcweir 						sal_Bool bAsynchron );
49cdf0e10cSrcweir 		~ORequestThread();
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 		void setTask( JobQueue * , const ::rtl::ByteSequence & aThreadId , sal_Bool bAsynchron );
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 		sal_Bool create();
54cdf0e10cSrcweir 		void join();
55cdf0e10cSrcweir 		void onTerminated();
56cdf0e10cSrcweir 		void run();
setDeleteSelf(sal_Bool b)57cdf0e10cSrcweir 		inline void setDeleteSelf( sal_Bool b )
58cdf0e10cSrcweir 			{ m_bDeleteSelf = b; }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 	private:
61cdf0e10cSrcweir 		oslThread m_thread;
62cdf0e10cSrcweir 		ThreadAdminHolder m_aThreadAdmin;
63cdf0e10cSrcweir 		JobQueue *m_pQueue;
64cdf0e10cSrcweir 		::rtl::ByteSequence m_aThreadId;
65cdf0e10cSrcweir 		sal_Bool m_bAsynchron;
66cdf0e10cSrcweir 		sal_Bool m_bDeleteSelf;
67cdf0e10cSrcweir 	};
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	class ThreadAdmin
70cdf0e10cSrcweir 	{
71cdf0e10cSrcweir 	public:
72cdf0e10cSrcweir 		~ThreadAdmin ();
73cdf0e10cSrcweir 		static ThreadAdminHolder &getInstance();
74cdf0e10cSrcweir 		void add( ORequestThread * );
75cdf0e10cSrcweir 		void remove( ORequestThread * );
76cdf0e10cSrcweir 		void join();
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 	private:
79cdf0e10cSrcweir 		::osl::Mutex m_mutex;
80cdf0e10cSrcweir 		::std::list< ORequestThread * > m_lst;
81cdf0e10cSrcweir 	};
82cdf0e10cSrcweir 
83cdf0e10cSrcweir } // end cppu_threadpool
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
86cdf0e10cSrcweir #endif
87cdf0e10cSrcweir 
88