DelegateSimpleThread
来源:互联网 发布:杂志 知乎 编辑:程序博客网 时间:2024/06/06 11:44
class SimpleThread : public PlatformThread::Delegate {
public:
class Options {
public:
Options() : stack_size_(0) { }
~Options() { }
// We use the standard compiler-supplied copy constructor.
// A custom stack size, or 0 for the system default.
void set_stack_size(size_t size) { stack_size_ = size; }
size_t stack_size() const { return stack_size_; }
private:
size_t stack_size_;
};
// Create a SimpleThread. |options| should be used to manage any specific
// configuration involving the thread creation and management.
// Every thread has a name, in the form of |name_prefix|/TID, for example
// "my_thread/321". The thread will not be created until Start() is called.
explicit SimpleThread(const std::string& name_prefix)
: name_prefix_(name_prefix), name_(name_prefix),
thread_(), event_(true, false), tid_(0), joined_(false) { }
SimpleThread(const std::string& name_prefix, const Options& options)
: name_prefix_(name_prefix), name_(name_prefix), options_(options),
thread_(), event_(true, false), tid_(0), joined_(false) { }
virtual ~SimpleThread();
virtual void Start();
virtual void Join();
// We follow the PlatformThread Delegate interface.
virtual void ThreadMain();
// Subclasses should override the Run method.
virtual void Run() = 0;
// Return the thread name prefix, or "unnamed" if none was supplied.
std::string name_prefix() { return name_prefix_; }
// Return the completed name including TID, only valid after Start().
std::string name() { return name_; }
// Return the thread id, only valid after Start().
PlatformThreadId tid() { return tid_; }
// Return True if Start() has ever been called.
bool HasBeenStarted() { return event_.IsSignaled(); }
// Return True if Join() has evern been called.
bool HasBeenJoined() { return joined_; }
private:
const std::string name_prefix_;
std::string name_;
const Options options_;
PlatformThreadHandle thread_; // PlatformThread handle, invalid after Join!
WaitableEvent event_; // Signaled if Start() was ever called.
PlatformThreadId tid_; // The backing thread's id.
bool joined_; // True if Join has been called.
};
- DelegateSimpleThread
- 移植内核中无法进入shell的问题
- 网页自动刷新代码
- 在nand flash上实现JFFS2根文件文件系统
- mysql在linux下备份日志的清除,过多会导致mysql远程连接不上
- 转]一个计算机专业学生几年的Java编程经验汇总
- DelegateSimpleThread
- 基于S3C2410的SD卡linux驱动工作原理(一)
- action请求正则表达式
- 7号信令概述
- 合并多行列值
- 在ubuntu下用squirrelmail架设webmail
- SSH中使用getCurrentSession()获得session
- DelegateSimpleThreadPool
- Webwork项目总结(三)