update dev300-m58
[ooovba.git] / cppu / source / threadpool / threadpool.hxx
blob9ee1dc42e0c9fb6f7295f764a9b7ab2b3e793594
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: threadpool.hxx,v $
10 * $Revision: 1.6 $
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 ************************************************************************/
30 #include <hash_map>
32 #include <osl/conditn.h>
34 #include <rtl/byteseq.hxx>
36 #include "jobqueue.hxx"
39 using namespace ::rtl;
40 namespace cppu_threadpool {
41 class ORequestThread;
43 struct EqualThreadId
45 sal_Int32 operator () ( const ::rtl::ByteSequence &a , const ::rtl::ByteSequence &b ) const
47 return a == b;
51 struct HashThreadId
53 sal_Int32 operator () ( const ::rtl::ByteSequence &a ) const
55 if( a.getLength() >= 4 )
57 return *(sal_Int32 *)a.getConstArray();
59 return 0;
63 typedef ::std::hash_map
65 ByteSequence, // ThreadID
66 ::std::pair < JobQueue * , JobQueue * >,
67 HashThreadId,
68 EqualThreadId
69 > ThreadIdHashMap;
71 typedef ::std::list < sal_Int64 > DisposedCallerList;
74 struct WaitingThread
76 oslCondition condition;
77 ORequestThread *thread;
80 typedef ::std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList;
82 class DisposedCallerAdmin
84 public:
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 );
93 private:
94 ::osl::Mutex m_mutex;
95 DisposedCallerList m_lst;
98 class ThreadPool
100 public:
101 ~ThreadPool();
102 static ThreadPool *getInstance();
104 void dispose( sal_Int64 nDisposeId );
105 void stopDisposing( sal_Int64 nDisposeId );
107 void addJob( const ByteSequence &aThreadId,
108 sal_Bool bAsynchron,
109 void *pThreadSpecificData,
110 RequestFun * doRequest );
112 void prepare( const ByteSequence &aThreadId );
113 void * enter( const ByteSequence &aThreadId, sal_Int64 nDisposeId );
115 /********
116 * @return true, if queue could be succesfully revoked.
117 ********/
118 sal_Bool revokeQueue( const ByteSequence & aThreadId , sal_Bool bAsynchron );
120 void waitInPool( ORequestThread *pThread );
121 private:
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