• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_APP_DISPATCHER_THREADING_THREAD_FACTORY_H
17 #define OHOS_APP_DISPATCHER_THREADING_THREAD_FACTORY_H
18 
19 #include "runnable.h"
20 #include <thread>
21 #include <memory>
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 class Thread {
26 public:
Thread()27     Thread() : thread_name_("Thread_0"), thread_(){};
28     ~Thread() = default;
29     Thread(const Thread &) = delete;
30     Thread &operator=(const Thread &) = delete;
31 
32 public:
33     std::string thread_name_;
34     std::shared_ptr<std::thread> thread_;
35 };
36 
37 /**
38  *  ThreadFactory is an interface for producing thread.
39  */
40 class ThreadFactory {
41 public:
42     ThreadFactory() = default;
~ThreadFactory()43     virtual ~ThreadFactory(){};
44     /**
45      *  Create a new Thread with |task| as the body of thread.
46      *
47      *  @param task The run body of the thread to create.
48      *
49      *  @return a new created thread. maybe null.
50      *
51      */
52     virtual std::shared_ptr<Thread> Create() = 0;
53 };
54 }  // namespace AppExecFwk
55 }  // namespace OHOS
56 #endif
57