You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-513 Optimize by replacing make_pair with a struct
This commit is contained in:
@ -20,7 +20,6 @@
|
||||
*
|
||||
*
|
||||
***********************************************************************/
|
||||
#define NOLOGGING
|
||||
#include <stdexcept>
|
||||
using namespace std;
|
||||
|
||||
@ -128,7 +127,7 @@ void ThreadPool::join(uint64_t thrHandle)
|
||||
for (iter = fWaitingFunctors.begin(); iter != end; ++iter)
|
||||
{
|
||||
foundit = false;
|
||||
if (iter->first == thrHandle)
|
||||
if (iter->hndl == thrHandle)
|
||||
{
|
||||
foundit = true;
|
||||
break;
|
||||
@ -158,7 +157,7 @@ void ThreadPool::join(std::vector<uint64_t> thrHandle)
|
||||
std::vector<uint64_t>::iterator thrEnd = thrHandle.end();
|
||||
for (thrIter = thrHandle.begin(); thrIter != thrEnd; ++thrIter)
|
||||
{
|
||||
if (iter->first == *thrIter)
|
||||
if (iter->hndl == *thrIter)
|
||||
{
|
||||
foundit = true;
|
||||
break;
|
||||
@ -282,7 +281,7 @@ void ThreadPool::beginThread() throw()
|
||||
|
||||
for (i = 0; i < num; i++) {
|
||||
try {
|
||||
(*todoList[i]).second();
|
||||
(*todoList[i]).functor();
|
||||
}
|
||||
catch(exception &e) {
|
||||
++fFunctorErrors;
|
||||
@ -366,7 +365,11 @@ int64_t ThreadPool::addFunctor(const Functor_T &func)
|
||||
if (fNextFunctor == fWaitingFunctors.end())
|
||||
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++;
|
||||
if (bAtEnd)
|
||||
{
|
||||
|
@ -55,12 +55,10 @@ namespace threadpool
|
||||
* 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.
|
||||
*/
|
||||
|
||||
class ThreadPool
|
||||
{
|
||||
public:
|
||||
typedef boost::function0<void> Functor_T;
|
||||
typedef pair<int64_t, Functor_T> PoolFunction_T;
|
||||
|
||||
/*********************************************
|
||||
* ctor/dtor
|
||||
@ -158,6 +156,13 @@ public:
|
||||
protected:
|
||||
|
||||
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
|
||||
*/
|
||||
void init();
|
||||
@ -193,8 +198,8 @@ private:
|
||||
struct NoOp
|
||||
{
|
||||
void operator () () const
|
||||
{}}
|
||||
;
|
||||
{}
|
||||
};
|
||||
|
||||
size_t fThreadCount;
|
||||
size_t fMaxThreads;
|
||||
|
@ -56,13 +56,14 @@ struct foo
|
||||
int64_t fData;
|
||||
int64_t fThd;
|
||||
string start;
|
||||
bool running;
|
||||
|
||||
void operator ()()
|
||||
{
|
||||
start = timeNow();
|
||||
|
||||
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
|
||||
fData++;
|
||||
|
||||
@ -70,11 +71,11 @@ struct foo
|
||||
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();
|
||||
uint64_t testHndl;
|
||||
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);
|
||||
// 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);
|
||||
if (y<10)
|
||||
{
|
||||
@ -117,5 +125,6 @@ int main( int argc, char **argv)
|
||||
std::cout << "*** WAIT ***" << std::endl;
|
||||
pool.wait();
|
||||
pool.dump();
|
||||
sleep(2);
|
||||
return 0;
|
||||
}
|
||||
|
@ -11,7 +11,8 @@
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdtp"
|
||||
CompilerConfigName="Latest Version">
|
||||
CompilerConfigName="Latest Version"
|
||||
Defines='"/DNOLOGGING"'>
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
@ -115,7 +116,8 @@
|
||||
DebugCallbackName="gdb"
|
||||
Version="1"
|
||||
OutputFile="%bdtp"
|
||||
CompilerConfigName="Latest Version">
|
||||
CompilerConfigName="Latest Version"
|
||||
Defines='"/DNOLOGGING"'>
|
||||
<Menu>
|
||||
<Target
|
||||
Name="Compile"
|
||||
|
Reference in New Issue
Block a user