xref: /AOO41X/main/cppu/source/threadpool/jobqueue.hxx (revision c6ed87c9b37761ea466ee21111c4a4a314092829)
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 
24 #ifndef _CPPU_THREADPOOL_JOBQUEUE_HXX_
25 #define _CPPU_THREADPOOL_JOBQUEUE_HXX_
26 
27 #include <list>
28 #include <sal/types.h>
29 
30 #include <osl/conditn.h>
31 #include <osl/mutex.hxx>
32 
33 #include <boost/shared_ptr.hpp>
34 
35 namespace cppu_threadpool
36 {
37     extern "C" typedef void (SAL_CALL RequestFun)(void *);
38 
39     struct Job
40     {
41         void *pThreadSpecificData;
42         RequestFun * doRequest;
43     };
44 
45     typedef ::std::list < struct Job > JobList;
46 
47     typedef ::std::list < sal_Int64 > CallStackList;
48 
49     class DisposedCallerAdmin;
50     typedef boost::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
51 
52     class JobQueue
53     {
54     public:
55         JobQueue();
56         ~JobQueue();
57 
58         void add( void *pThreadSpecificData, RequestFun * doRequest );
59 
60         void *enter( sal_Int64 nDisposeId , sal_Bool bReturnWhenNoJob = sal_False );
61         void dispose( sal_Int64 nDisposeId );
62 
63         void suspend();
64         void resume();
65 
66         sal_Bool isEmpty();
67         sal_Bool isCallstackEmpty();
68         sal_Bool isBusy();
69 
70     private:
71         ::osl::Mutex m_mutex;
72         JobList      m_lstJob;
73         CallStackList m_lstCallstack;
74         sal_Int32 m_nToDo;
75         sal_Bool m_bSuspended;
76         oslCondition m_cndWait;
77         DisposedCallerAdminHolder m_DisposedCallerAdmin;
78     };
79 }
80 
81 #endif
82