1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef FRAMEWORKS_BASE_COMMONPOOLBASE_H
18 #define FRAMEWORKS_BASE_COMMONPOOLBASE_H
19 
20 #include <sys/resource.h>
21 
22 #include "renderthread/RenderThread.h"
23 
24 namespace android {
25 namespace uirenderer {
26 
27 class CommonPoolBase {
28     PREVENT_COPY_AND_ASSIGN(CommonPoolBase);
29 
30 protected:
CommonPoolBase()31     CommonPoolBase() {}
32 
setupThread(int i,std::mutex & mLock,std::vector<int> & tids,std::vector<std::condition_variable> & tidConditionVars)33     void setupThread(int i, std::mutex& mLock, std::vector<int>& tids,
34                      std::vector<std::condition_variable>& tidConditionVars) {
35         std::array<char, 20> name{"hwuiTask"};
36         snprintf(name.data(), name.size(), "hwuiTask%d", i);
37         auto self = pthread_self();
38         pthread_setname_np(self, name.data());
39         {
40             std::unique_lock lock(mLock);
41             tids[i] = pthread_gettid_np(self);
42             tidConditionVars[i].notify_one();
43         }
44         setpriority(PRIO_PROCESS, 0, PRIORITY_FOREGROUND);
45         auto startHook = renderthread::RenderThread::getOnStartHook();
46         if (startHook) {
47             startHook(name.data());
48         }
49     }
50 
supportsTid()51     bool supportsTid() { return true; }
52 };
53 
54 }  // namespace uirenderer
55 }  // namespace android
56 
57 #endif  // FRAMEWORKS_BASE_COMMONPOOLBASE_H
58