1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 #include <osl/conditn.h>
31 #include <rtl/byteseq.hxx>
33 #include <boost/shared_ptr.hpp>
35 #include "jobqueue.hxx"
38 using namespace ::rtl
;
39 namespace cppu_threadpool
{
44 sal_Int32
operator () ( const ::rtl::ByteSequence
&a
, const ::rtl::ByteSequence
&b
) const
52 sal_Int32
operator () ( const ::rtl::ByteSequence
&a
) const
54 if( a
.getLength() >= 4 )
56 return *(sal_Int32
*)a
.getConstArray();
62 typedef ::std::hash_map
64 ByteSequence
, // ThreadID
65 ::std::pair
< JobQueue
* , JobQueue
* >,
70 typedef ::std::list
< sal_Int64
> DisposedCallerList
;
75 oslCondition condition
;
76 ORequestThread
*thread
;
79 typedef ::std::list
< struct ::cppu_threadpool::WaitingThread
* > WaitingThreadList
;
81 class DisposedCallerAdmin
;
82 typedef boost::shared_ptr
<DisposedCallerAdmin
> DisposedCallerAdminHolder
;
84 class DisposedCallerAdmin
87 ~DisposedCallerAdmin();
89 static DisposedCallerAdminHolder
getInstance();
91 void dispose( sal_Int64 nDisposeId
);
92 void stopDisposing( sal_Int64 nDisposeId
);
93 sal_Bool
isDisposed( sal_Int64 nDisposeId
);
97 DisposedCallerList m_lst
;
101 typedef boost::shared_ptr
<ThreadPool
> ThreadPoolHolder
;
108 static ThreadPoolHolder
getInstance();
110 void dispose( sal_Int64 nDisposeId
);
111 void stopDisposing( sal_Int64 nDisposeId
);
113 void addJob( const ByteSequence
&aThreadId
,
115 void *pThreadSpecificData
,
116 RequestFun
* doRequest
);
118 void prepare( const ByteSequence
&aThreadId
);
119 void * enter( const ByteSequence
&aThreadId
, sal_Int64 nDisposeId
);
122 * @return true, if queue could be succesfully revoked.
124 sal_Bool
revokeQueue( const ByteSequence
& aThreadId
, sal_Bool bAsynchron
);
126 void waitInPool( ORequestThread
*pThread
);
128 void createThread( JobQueue
*pQueue
, const ByteSequence
&aThreadId
, sal_Bool bAsynchron
);
131 ThreadIdHashMap m_mapQueue
;
132 ::osl::Mutex m_mutex
;
134 ::osl::Mutex m_mutexWaitingThreadList
;
135 WaitingThreadList m_lstThreads
;
137 DisposedCallerAdminHolder m_DisposedCallerAdmin
;
140 } // end namespace cppu_threadpool