• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 
26 class Thread {
27 public:
Thread()28     Thread() : thread_name_("Thread_0"), thread_(){};
29     ~Thread() = default;
30     Thread(const Thread &) = delete;
31     Thread &operator=(const Thread &) = delete;
32 
33 public:
34     std::string thread_name_;
35     std::shared_ptr<std::thread> thread_;
36 };
37 
38 /**
39  *  ThreadFactory is an interface for producing thread.
40  */
41 class ThreadFactory {
42 public:
43     ThreadFactory() = default;
~ThreadFactory()44     virtual ~ThreadFactory(){};
45     /**
46      *  Create a new Thread with |task| as the body of thread.
47      *
48      *  @param task The run body of the thread to create.
49      *
50      *  @return a new created thread. maybe null.
51      *
52      */
53     virtual std::shared_ptr<Thread> Create() = 0;
54 };
55 
56 }  // namespace AppExecFwk
57 }  // namespace OHOS
58 #endif
59