thread.cpp
来自「一个语言识别引擎」· C++ 代码 · 共 98 行
CPP
98 行
// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
#include "Thread.h"
#include "ThreadImpl.h"
class ThreadCallbackAdapter : public ThreadImpl {
private:
Thread& owner;
public:
ThreadCallbackAdapter(Thread& owner) : owner(owner) {
}
virtual void beforeStart() {
owner.beforeStart();
}
virtual void afterStart(bool success) {
owner.afterStart(success);
}
virtual void run() {
owner.run();
}
virtual void close() {
owner.onStop();
ThreadImpl::close();
}
};
Thread::Thread() {
implementation = new ThreadCallbackAdapter(*this);
if (implementation==NULL) {
ACE_OS::printf("Could not allocate thread, exitting\n");
ACE_OS::exit(1);
}
}
Thread::~Thread() {
if (implementation!=NULL) {
delete ((ThreadImpl*)implementation);
implementation = NULL;
}
}
bool Thread::join(double seconds) {
return ((ThreadImpl*)implementation)->join(seconds);
}
bool Thread::stop() {
return ((ThreadImpl*)implementation)->join(-1);
}
void Thread::run() {
}
void Thread::onStop() {
((ThreadImpl*)implementation)->close();
}
bool Thread::start() {
return ((ThreadImpl*)implementation)->start();
}
bool Thread::isStopping() {
return ((ThreadImpl*)implementation)->isClosing();
}
bool Thread::isRunning() {
return ((ThreadImpl*)implementation)->isRunning();
}
void Thread::beforeStart() {
}
void Thread::afterStart(bool success) {
}
void Thread::setOptions(int stackSize) {
((ThreadImpl*)implementation)->setOptions(stackSize);
}
int Thread::getCount() {
return ThreadImpl::getCount();
}
// get a unique key
long int Thread::getKey() {
return ((ThreadImpl*)implementation)->getKey();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?