git-svn-id: svn://db.shs.com.ru/pip@888 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -120,6 +120,22 @@ PIVector<PIThread * > __PIThreadCollection::threads() const {
|
||||
}
|
||||
|
||||
|
||||
void __PIThreadCollection::startedAuto(PIThread * t) {
|
||||
PIMutexLocker _ml(auto_mutex);
|
||||
auto_threads_ << t;
|
||||
}
|
||||
|
||||
|
||||
void __PIThreadCollection::stoppedAuto() {
|
||||
PIThread * t = emitter()->cast<PIThread>();
|
||||
if (!t) return;
|
||||
auto_mutex.lock();
|
||||
auto_threads_.removeAll(t);
|
||||
auto_mutex.unlock();
|
||||
delete t;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int __PIThreadCollection_Initializer__::count_(0);
|
||||
@@ -549,10 +565,26 @@ void PIThread::__thread_func_once__() {
|
||||
}
|
||||
|
||||
|
||||
PIThread * PIThread::runOnce(std::function<void ()> func) {
|
||||
void PIThread::runOnce(PIObject * object, const char * handler, const PIString & name) {
|
||||
PIThread * t = new PIThread();
|
||||
t->setSlot(func);
|
||||
t->setName(name);
|
||||
if (!PIObject::piConnectU(t, PIStringAscii("started"), object, object, PIStringAscii(handler), "PIThread::runOnce")) {
|
||||
delete t;
|
||||
return;
|
||||
}
|
||||
__PIThreadCollection::instance()->startedAuto(t);
|
||||
CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||
t->startOnce();
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
void PIThread::runOnce(std::function<void ()> func, const PIString & name) {
|
||||
PIThread * t = new PIThread();
|
||||
t->setName(name);
|
||||
t->setSlot(func);
|
||||
__PIThreadCollection::instance()->startedAuto(t);
|
||||
CONNECTU(t, stopped, __PIThreadCollection::instance(), stoppedAuto);
|
||||
t->startOnce();
|
||||
//return t;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user