2018-11-07 12:24:35 -08:00
|
|
|
// Copyright 2013 The Flutter Authors. All rights reserved.
|
2017-03-20 13:41:41 -07:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
#ifndef FLUTTER_FML_THREAD_H_
|
|
|
|
|
#define FLUTTER_FML_THREAD_H_
|
|
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <thread>
|
|
|
|
|
|
2018-04-21 20:50:03 -07:00
|
|
|
#include "flutter/fml/macros.h"
|
2018-04-13 13:48:15 -07:00
|
|
|
#include "flutter/fml/task_runner.h"
|
2017-03-20 13:41:41 -07:00
|
|
|
|
|
|
|
|
namespace fml {
|
|
|
|
|
|
|
|
|
|
class Thread {
|
|
|
|
|
public:
|
|
|
|
|
explicit Thread(const std::string& name = "");
|
|
|
|
|
|
|
|
|
|
~Thread();
|
|
|
|
|
|
2018-07-26 12:49:34 -07:00
|
|
|
fml::RefPtr<fml::TaskRunner> GetTaskRunner() const;
|
2017-03-20 13:41:41 -07:00
|
|
|
|
|
|
|
|
void Join();
|
|
|
|
|
|
2019-04-09 17:03:41 -07:00
|
|
|
static void SetCurrentThreadName(const std::string& name);
|
|
|
|
|
|
2017-03-20 13:41:41 -07:00
|
|
|
private:
|
|
|
|
|
std::unique_ptr<std::thread> thread_;
|
2018-07-26 12:49:34 -07:00
|
|
|
fml::RefPtr<fml::TaskRunner> task_runner_;
|
2017-03-20 13:41:41 -07:00
|
|
|
std::atomic_bool joined_;
|
|
|
|
|
|
2018-04-21 20:50:03 -07:00
|
|
|
FML_DISALLOW_COPY_AND_ASSIGN(Thread);
|
2017-03-20 13:41:41 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace fml
|
|
|
|
|
|
|
|
|
|
#endif // FLUTTER_FML_THREAD_H_
|