Coverage Report

Created: 2026-06-16 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/muduo/muduo/base/Thread.h
Line
Count
Source
1
// Use of this source code is governed by a BSD-style license
2
// that can be found in the License file.
3
//
4
// Author: Shuo Chen (chenshuo at chenshuo dot com)
5
6
#ifndef MUDUO_BASE_THREAD_H
7
#define MUDUO_BASE_THREAD_H
8
9
#include "muduo/base/Atomic.h"
10
#include "muduo/base/CountDownLatch.h"
11
#include "muduo/base/Types.h"
12
13
#include <functional>
14
#include <memory>
15
#include <pthread.h>
16
17
namespace muduo
18
{
19
20
class Thread : noncopyable
21
{
22
 public:
23
  typedef std::function<void ()> ThreadFunc;
24
25
  explicit Thread(ThreadFunc, const string& name = string());
26
  // FIXME: make it movable in C++11
27
  ~Thread();
28
29
  void start();
30
  int join(); // return pthread_join()
31
32
0
  bool started() const { return started_; }
33
  // pthread_t pthreadId() const { return pthreadId_; }
34
0
  pid_t tid() const { return tid_; }
35
0
  const string& name() const { return name_; }
36
37
0
  static int numCreated() { return numCreated_.get(); }
38
39
 private:
40
  void setDefaultName();
41
42
  bool       started_;
43
  bool       joined_;
44
  pthread_t  pthreadId_;
45
  pid_t      tid_;
46
  ThreadFunc func_;
47
  string     name_;
48
  CountDownLatch latch_;
49
50
  static AtomicInt32 numCreated_;
51
};
52
53
}  // namespace muduo
54
#endif  // MUDUO_BASE_THREAD_H