fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / cppu / source / threadpool / threadpool.hxx
blobdc17d6490ac8f65f7b613c7286ba166651208199
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <list>
24 #include <unordered_map>
26 #include <osl/conditn.h>
28 #include <rtl/byteseq.hxx>
29 #include <rtl/ref.hxx>
30 #include <salhelper/simplereferenceobject.hxx>
32 #include <boost/shared_ptr.hpp>
34 #include "jobqueue.hxx"
37 namespace cppu_threadpool {
38 class ORequestThread;
40 struct EqualThreadId
42 bool operator () ( const ::rtl::ByteSequence &a , const ::rtl::ByteSequence &b ) const
44 return a == b;
48 struct HashThreadId
50 sal_Int32 operator () ( const ::rtl::ByteSequence &a ) const
52 if( a.getLength() >= 4 )
54 return *reinterpret_cast<sal_Int32 const *>(a.getConstArray());
56 return 0;
60 typedef std::unordered_map
62 ::rtl::ByteSequence, // ThreadID
63 ::std::pair < JobQueue * , JobQueue * >,
64 HashThreadId,
65 EqualThreadId
66 > ThreadIdHashMap;
68 typedef ::std::list < sal_Int64 > DisposedCallerList;
71 struct WaitingThread
73 oslCondition condition;
74 rtl::Reference< ORequestThread > thread;
77 typedef ::std::list < struct ::cppu_threadpool::WaitingThread * > WaitingThreadList;
79 class DisposedCallerAdmin;
80 typedef boost::shared_ptr<DisposedCallerAdmin> DisposedCallerAdminHolder;
82 class DisposedCallerAdmin
84 public:
85 ~DisposedCallerAdmin();
87 static DisposedCallerAdminHolder getInstance();
89 void dispose( sal_Int64 nDisposeId );
90 void destroy( sal_Int64 nDisposeId );
91 bool isDisposed( sal_Int64 nDisposeId );
93 private:
94 ::osl::Mutex m_mutex;
95 DisposedCallerList m_lst;
98 class ThreadAdmin
100 public:
101 ThreadAdmin();
102 ~ThreadAdmin ();
104 bool add( rtl::Reference< ORequestThread > const & );
105 void remove( rtl::Reference< ORequestThread > const & );
106 void join();
108 void remove_locked( rtl::Reference< ORequestThread > const & );
109 ::osl::Mutex m_mutex;
111 private:
112 ::std::list< rtl::Reference< ORequestThread > > m_lst;
113 bool m_disposed;
116 class ThreadPool;
117 typedef rtl::Reference<ThreadPool> ThreadPoolHolder;
119 class ThreadPool: public salhelper::SimpleReferenceObject
121 public:
122 ThreadPool();
123 virtual ~ThreadPool();
125 void dispose( sal_Int64 nDisposeId );
126 void destroy( sal_Int64 nDisposeId );
128 bool addJob( const ::rtl::ByteSequence &aThreadId,
129 bool bAsynchron,
130 void *pThreadSpecificData,
131 RequestFun * doRequest );
133 void prepare( const ::rtl::ByteSequence &aThreadId );
134 void * enter( const ::rtl::ByteSequence &aThreadId, sal_Int64 nDisposeId );
136 /********
137 * @return true, if queue could be successfully revoked.
138 ********/
139 bool revokeQueue( const ::rtl::ByteSequence & aThreadId , bool bAsynchron );
141 void waitInPool( rtl::Reference< ORequestThread > const & pThread );
143 void joinWorkers();
145 ThreadAdmin & getThreadAdmin() { return m_aThreadAdmin; }
147 private:
148 bool createThread( JobQueue *pQueue, const ::rtl::ByteSequence &aThreadId, bool bAsynchron);
151 ThreadIdHashMap m_mapQueue;
152 ::osl::Mutex m_mutex;
154 ::osl::Mutex m_mutexWaitingThreadList;
155 WaitingThreadList m_lstThreads;
157 DisposedCallerAdminHolder m_DisposedCallerAdmin;
158 ThreadAdmin m_aThreadAdmin;
161 } // end namespace cppu_threadpool
163 #endif
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */