1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_FML_THREAD_H_
6#define FLUTTER_FML_THREAD_H_
7
8#include <atomic>
9#include <memory>
10#include <thread>
11
12#include "flutter/fml/macros.h"
13#include "flutter/fml/task_runner.h"
14
15namespace fml {
16
17class Thread {
18 public:
19 explicit Thread(const std::string& name = "");
20
21 ~Thread();
22
23 fml::RefPtr<fml::TaskRunner> GetTaskRunner() const;
24
25 void Join();
26
27 static void SetCurrentThreadName(const std::string& name);
28
29 private:
30 std::unique_ptr<std::thread> thread_;
31 fml::RefPtr<fml::TaskRunner> task_runner_;
32 std::atomic_bool joined_;
33
34 FML_DISALLOW_COPY_AND_ASSIGN(Thread);
35};
36
37} // namespace fml
38
39#endif // FLUTTER_FML_THREAD_H_
40