1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CPPU_SOURCE_THREADPOOL_THREADPOOL_HXX
21 #define INCLUDED_CPPU_SOURCE_THREADPOOL_THREADPOOL_HXX
25 #include <boost/unordered_map.hpp>
27 #include <osl/conditn.h>
29 #include <rtl/byteseq.hxx>
30 #include <rtl/ref.hxx>
31 #include <salhelper/simplereferenceobject.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 ::boost::unordered_map
64 ByteSequence
, // ThreadID
65 ::std::pair
< JobQueue
* , JobQueue
* >,
70 typedef ::std::list
< sal_Int64
> DisposedCallerList
;
75 oslCondition condition
;
76 rtl::Reference
< 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 destroy( sal_Int64 nDisposeId
);
93 sal_Bool
isDisposed( sal_Int64 nDisposeId
);
97 DisposedCallerList m_lst
;
106 void add( rtl::Reference
< ORequestThread
> const & );
107 void remove( rtl::Reference
< ORequestThread
> const & );
110 void remove_locked( rtl::Reference
< ORequestThread
> const & );
111 ::osl::Mutex m_mutex
;
114 ::std::list
< rtl::Reference
< ORequestThread
> > m_lst
;
119 typedef rtl::Reference
<ThreadPool
> ThreadPoolHolder
;
121 class ThreadPool
: public salhelper::SimpleReferenceObject
127 void dispose( sal_Int64 nDisposeId
);
128 void destroy( sal_Int64 nDisposeId
);
130 void addJob( const ByteSequence
&aThreadId
,
132 void *pThreadSpecificData
,
133 RequestFun
* doRequest
);
135 void prepare( const ByteSequence
&aThreadId
);
136 void * enter( const ByteSequence
&aThreadId
, sal_Int64 nDisposeId
);
139 * @return true, if queue could be successfully revoked.
141 sal_Bool
revokeQueue( const ByteSequence
& aThreadId
, sal_Bool bAsynchron
);
143 void waitInPool( rtl::Reference
< ORequestThread
> const & pThread
);
147 ThreadAdmin
& getThreadAdmin() { return m_aThreadAdmin
; }
150 void createThread( JobQueue
*pQueue
, const ByteSequence
&aThreadId
, sal_Bool bAsynchron
);
153 ThreadIdHashMap m_mapQueue
;
154 ::osl::Mutex m_mutex
;
156 ::osl::Mutex m_mutexWaitingThreadList
;
157 WaitingThreadList m_lstThreads
;
159 DisposedCallerAdminHolder m_DisposedCallerAdmin
;
160 ThreadAdmin m_aThreadAdmin
;
163 } // end namespace cppu_threadpool
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */