1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: threadpool.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <osl/conditn.h>
34 #include <rtl/byteseq.hxx>
36 #include "jobqueue.hxx"
39 using namespace ::rtl
;
40 namespace cppu_threadpool
{
45 sal_Int32
operator () ( const ::rtl::ByteSequence
&a
, const ::rtl::ByteSequence
&b
) const
53 sal_Int32
operator () ( const ::rtl::ByteSequence
&a
) const
55 if( a
.getLength() >= 4 )
57 return *(sal_Int32
*)a
.getConstArray();
63 typedef ::std::hash_map
65 ByteSequence
, // ThreadID
66 ::std::pair
< JobQueue
* , JobQueue
* >,
71 typedef ::std::list
< sal_Int64
> DisposedCallerList
;
76 oslCondition condition
;
77 ORequestThread
*thread
;
80 typedef ::std::list
< struct ::cppu_threadpool::WaitingThread
* > WaitingThreadList
;
82 class DisposedCallerAdmin
85 ~DisposedCallerAdmin();
87 static DisposedCallerAdmin
*getInstance();
89 void dispose( sal_Int64 nDisposeId
);
90 void stopDisposing( sal_Int64 nDisposeId
);
91 sal_Bool
isDisposed( sal_Int64 nDisposeId
);
95 DisposedCallerList m_lst
;
102 static ThreadPool
*getInstance();
104 void dispose( sal_Int64 nDisposeId
);
105 void stopDisposing( sal_Int64 nDisposeId
);
107 void addJob( const ByteSequence
&aThreadId
,
109 void *pThreadSpecificData
,
110 RequestFun
* doRequest
);
112 void prepare( const ByteSequence
&aThreadId
);
113 void * enter( const ByteSequence
&aThreadId
, sal_Int64 nDisposeId
);
116 * @return true, if queue could be succesfully revoked.
118 sal_Bool
revokeQueue( const ByteSequence
& aThreadId
, sal_Bool bAsynchron
);
120 void waitInPool( ORequestThread
*pThread
);
122 void createThread( JobQueue
*pQueue
, const ByteSequence
&aThreadId
, sal_Bool bAsynchron
);
125 ThreadIdHashMap m_mapQueue
;
126 ::osl::Mutex m_mutex
;
128 ::osl::Mutex m_mutexWaitingThreadList
;
129 WaitingThreadList m_lstThreads
;
132 } // end namespace cppu_threadpool