xref: /trunk/main/cppu/source/threadpool/jobqueue.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CPPU_THREADPOOL_JOBQUEUE_HXX_
29 #define _CPPU_THREADPOOL_JOBQUEUE_HXX_
30 
31 #include <list>
32 #include <sal/types.h>
33 
34 #include <osl/conditn.h>
35 #include <osl/mutex.hxx>
36 
37 #include <boost/shared_ptr.hpp>
38 
39 namespace cppu_threadpool
40 {
41     extern "C" typedef void (SAL_CALL RequestFun)(void *);
42 
43 	struct Job
44 	{
45 		void *pThreadSpecificData;
46 		RequestFun * doRequest;
47 	};
48 
49 	typedef	::std::list	< struct Job > JobList;
50 
51 	typedef	::std::list	< sal_Int64 > CallStackList;
52 
53 	class DisposedCallerAdmin;
54 	typedef boost::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
55 
56 	class JobQueue
57 	{
58 	public:
59 		JobQueue();
60 		~JobQueue();
61 
62 		void add( void *pThreadSpecificData, RequestFun * doRequest );
63 
64 		void *enter( sal_Int64 nDisposeId , sal_Bool bReturnWhenNoJob = sal_False );
65 		void dispose( sal_Int64 nDisposeId );
66 
67 		void suspend();
68 		void resume();
69 
70 		sal_Bool isEmpty();
71 		sal_Bool isCallstackEmpty();
72 		sal_Bool isBusy();
73 
74 	private:
75 		::osl::Mutex m_mutex;
76 		JobList      m_lstJob;
77 		CallStackList m_lstCallstack;
78 		sal_Int32 m_nToDo;
79 		sal_Bool m_bSuspended;
80 		oslCondition m_cndWait;
81 		DisposedCallerAdminHolder m_DisposedCallerAdmin;
82 	};
83 }
84 
85 #endif
86