-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread.h
More file actions
58 lines (44 loc) · 1.08 KB
/
Copy pathThread.h
File metadata and controls
58 lines (44 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// excerpts from http://code.google.com/p/muduo/
//
// Use of this source code is governed by a BSD-style license
// that can be found in the License file.
//
// Author: Shuo Chen (giantchen at gmail dot com)
#ifndef MUDUO_BASE_THREAD_H
#define MUDUO_BASE_THREAD_H
#include "Atomic.h"
#include <functional>
#include <pthread.h>
#include <string>
namespace muduo
{
class Thread
{
public:
using ThreadFunc = std::function<void ()>;
explicit Thread(const ThreadFunc&, const std::string& name = std::string());
~Thread();
void start();
void join();
bool started() const { return started_; }
// pthread_t pthreadId() const { return pthreadId_; }
pid_t tid() const { return *tid_; }
const std::string& name() const { return name_; }
static int numCreated() { return numCreated_.get(); }
private:
bool started_;
bool joined_;
pthread_t pthreadId_;
std::shared_ptr<pid_t> tid_;
ThreadFunc func_;
std::string name_;
static AtomicInt32 numCreated_;
};
namespace CurrentThread
{
pid_t tid();
const char* name();
bool isMainThread();
}
}
#endif