1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-29 08:21:15 +03:00

MCOL-513 use thread pool for jobsteps

This commit is contained in:
David Hall
2017-02-03 15:22:07 -06:00
parent d50c7c7cab
commit 55d006de1a
30 changed files with 192 additions and 125 deletions

View File

@ -177,10 +177,10 @@ void ThreadPool::join(std::vector<uint64_t> thrHandle)
}
}
int64_t ThreadPool::invoke(const Functor_T &threadfunc)
uint64_t ThreadPool::invoke(const Functor_T &threadfunc)
{
boost::mutex::scoped_lock lock1(fMutex);
int64_t thrHandle=0;
uint64_t thrHandle=0;
for(;;)
{
@ -210,6 +210,22 @@ int64_t ThreadPool::invoke(const Functor_T &threadfunc)
lock1.unlock();
fThreads.create_thread(beginThreadFunc(*this));
if (fDebug)
{
logging::Message::Args args;
logging::Message message(5);
args.add("invoke: Starting thread ");
args.add(fThreadCount);
args.add(" max ");
args.add(fMaxThreads);
args.add(" queue ");
args.add(fQueueSize);
message.format( args );
logging::LoggingID lid(22);
logging::MessageLog ml(lid);
ml.logWarningMessage( message );
}
if (bAdded)
break;
@ -227,7 +243,20 @@ int64_t ThreadPool::invoke(const Functor_T &threadfunc)
break;
}
fThreadAvailable.wait(lock1);
if (fDebug)
{
logging::Message::Args args;
logging::Message message(5);
args.add("invoke: Blocked waiting for thread. Count ");
args.add(fThreadCount);
args.add("max ");
args.add(fMaxThreads);
message.format( args );
logging::LoggingID lid(22);
logging::MessageLog ml(lid);
ml.logWarningMessage( message );
fThreadAvailable.wait(lock1);
}
}
catch(...)
{
@ -358,7 +387,7 @@ void ThreadPool::beginThread() throw()
}
}
int64_t ThreadPool::addFunctor(const Functor_T &func)
uint64_t ThreadPool::addFunctor(const Functor_T &func)
{
bool bAtEnd = false;

View File

@ -131,7 +131,7 @@ public:
* queueSize tasks already waiting, invoke() will block until a slot in the
* queue comes free.
*/
EXPORT int64_t invoke(const Functor_T &threadfunc);
EXPORT uint64_t invoke(const Functor_T &threadfunc);
/** @brief stop the threads
*/
@ -153,13 +153,15 @@ public:
*/
EXPORT void dump();
EXPORT void setDebug(bool d) {fDebug = d;}
protected:
private:
// Used internally to keep a handle associated with each functor for join()
struct PoolFunction_T
{
int64_t hndl;
uint64_t hndl;
Functor_T functor;
};
@ -169,7 +171,7 @@ private:
/** @brief add a functor to the list
*/
int64_t addFunctor(const Functor_T &func);
uint64_t addFunctor(const Functor_T &func);
/** @brief thread entry point
*/
@ -222,6 +224,7 @@ private:
uint32_t waitingFunctorsSize;
uint64_t fNextHandle;
bool fDebug;
};
} // namespace threadpool