1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-02 17:22:27 +03:00

MCOL-513 Optimize by replacing make_pair with a struct

This commit is contained in:
David Hall
2017-02-02 11:45:04 -06:00
parent b6321935fb
commit 94b9d8aed2
4 changed files with 37 additions and 18 deletions

View File

@ -20,7 +20,6 @@
* *
* *
***********************************************************************/ ***********************************************************************/
#define NOLOGGING
#include <stdexcept> #include <stdexcept>
using namespace std; using namespace std;
@ -128,7 +127,7 @@ void ThreadPool::join(uint64_t thrHandle)
for (iter = fWaitingFunctors.begin(); iter != end; ++iter) for (iter = fWaitingFunctors.begin(); iter != end; ++iter)
{ {
foundit = false; foundit = false;
if (iter->first == thrHandle) if (iter->hndl == thrHandle)
{ {
foundit = true; foundit = true;
break; break;
@ -158,7 +157,7 @@ void ThreadPool::join(std::vector<uint64_t> thrHandle)
std::vector<uint64_t>::iterator thrEnd = thrHandle.end(); std::vector<uint64_t>::iterator thrEnd = thrHandle.end();
for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter) for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter)
{ {
if (iter->first == *thrIter) if (iter->hndl == *thrIter)
{ {
foundit = true; foundit = true;
break; break;
@ -282,7 +281,7 @@ void ThreadPool::beginThread() throw()
for (i = 0; i < num; i++) { for (i = 0; i < num; i++) {
try { try {
(*todoList[i]).second(); (*todoList[i]).functor();
} }
catch(exception &e) { catch(exception &e) {
++fFunctorErrors; ++fFunctorErrors;
@ -366,7 +365,11 @@ int64_t ThreadPool::addFunctor(const Functor_T &func)
if (fNextFunctor == fWaitingFunctors.end()) if (fNextFunctor == fWaitingFunctors.end())
bAtEnd = true; bAtEnd = true;
fWaitingFunctors.push_back(make_pair(fNextHandle, func)); // PoolFunction_T poolFunction(fNextHandle, func);
PoolFunction_T poolFunction;
poolFunction.hndl = fNextHandle;
poolFunction.functor = func;
fWaitingFunctors.push_back(poolFunction);
waitingFunctorsSize++; waitingFunctorsSize++;
if (bAtEnd) if (bAtEnd)
{ {

View File

@ -55,12 +55,10 @@ namespace threadpool
* executing tasks. It is responsible for creating threads and tracking which threads are "busy" * executing tasks. It is responsible for creating threads and tracking which threads are "busy"
* and which are idle. Idle threads are utilized as "work" is added to the system. * and which are idle. Idle threads are utilized as "work" is added to the system.
*/ */
class ThreadPool class ThreadPool
{ {
public: public:
typedef boost::function0<void> Functor_T; typedef boost::function0<void> Functor_T;
typedef pair<int64_t, Functor_T> PoolFunction_T;
/********************************************* /*********************************************
* ctor/dtor * ctor/dtor
@ -158,6 +156,13 @@ public:
protected: protected:
private: private:
// Used internally to keep a handle associated with each functor for join()
struct PoolFunction_T
{
int64_t hndl;
Functor_T functor;
};
/** @brief initialize data memebers /** @brief initialize data memebers
*/ */
void init(); void init();
@ -193,8 +198,8 @@ private:
struct NoOp struct NoOp
{ {
void operator () () const void operator () () const
{}} {}
; };
size_t fThreadCount; size_t fThreadCount;
size_t fMaxThreads; size_t fMaxThreads;

View File

@ -56,13 +56,14 @@ struct foo
int64_t fData; int64_t fData;
int64_t fThd; int64_t fThd;
string start; string start;
bool running;
void operator ()() void operator ()()
{ {
start = timeNow(); start = timeNow();
std::cout << "foo thd = " << fThd << " start " << start << std::endl; std::cout << "foo thd = " << fThd << " start " << start << std::endl;
for (int64_t i = 0; i < 1024*1024*fThd*128; i++) for (int64_t i = 0; i < 1024*1024*(fThd+0)*128; i++)
// simulate some work // simulate some work
fData++; fData++;
@ -70,11 +71,11 @@ struct foo
std::cout << "foo thd = " << fThd << " start " << start << " fin " << timeNow() << std::endl; std::cout << "foo thd = " << fThd << " start " << start << " fin " << timeNow() << std::endl;
} }
foo(int64_t i) : fThd(i), fData(i) {start=timeNow();} foo(int64_t i) : fThd(i), fData(i), running(true) {start=timeNow();}
foo(const foo& copy) : fData(copy.fData), fThd(copy.fThd), start(copy.start) {std::cout << "new foo" << endl;} foo(const foo& copy) : fData(copy.fData), fThd(copy.fThd), start(copy.start), running(copy.running) {std::cout << "new foo " << fThd << endl;}
~foo() {} ~foo() {running=false;}
}; };
@ -87,11 +88,18 @@ int main( int argc, char **argv)
int t1 = hndl.capacity(); int t1 = hndl.capacity();
uint64_t testHndl; uint64_t testHndl;
uint64_t thdhndl=999; uint64_t thdhndl=999;
for (int64_t y = 0; y < 20; y++) int64_t thd = 1;
boost::function0<void> foofunc;
boost::function0<void> foofunc2;
for (int64_t y = 0; y < 1; y++)
{ {
foo bar(y); foo bar(y);
// for (int64_t i = 0; i < 10; ++i) // foofunc = bar;
// foofunc2 = foofunc;
std::cout << "Done with assign" << std::endl;
for (int64_t i = 0; i < 1; ++i)
{ {
bar.fThd=thd++;
thdhndl = pool.invoke(bar); thdhndl = pool.invoke(bar);
if (y<10) if (y<10)
{ {
@ -117,5 +125,6 @@ int main( int argc, char **argv)
std::cout << "*** WAIT ***" << std::endl; std::cout << "*** WAIT ***" << std::endl;
pool.wait(); pool.wait();
pool.dump(); pool.dump();
sleep(2);
return 0; return 0;
} }

View File

@ -11,7 +11,8 @@
DebugCallbackName="gdb" DebugCallbackName="gdb"
Version="1" Version="1"
OutputFile="%bdtp" OutputFile="%bdtp"
CompilerConfigName="Latest Version"> CompilerConfigName="Latest Version"
Defines='"/DNOLOGGING"'>
<Menu> <Menu>
<Target <Target
Name="Compile" Name="Compile"
@ -115,7 +116,8 @@
DebugCallbackName="gdb" DebugCallbackName="gdb"
Version="1" Version="1"
OutputFile="%bdtp" OutputFile="%bdtp"
CompilerConfigName="Latest Version"> CompilerConfigName="Latest Version"
Defines='"/DNOLOGGING"'>
<Menu> <Menu>
<Target <Target
Name="Compile" Name="Compile"