• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (C) 2022 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 #include <IImsMediaThread.h>
18 #include <ImsMediaTrace.h>
19 #include <thread>
20 
21 extern void setAudioThreadPriority(int threadId);
22 
IImsMediaThread()23 IImsMediaThread::IImsMediaThread()
24 {
25     mThreadStopped = true;
26 }
27 
~IImsMediaThread()28 IImsMediaThread::~IImsMediaThread() {}
29 
runThread(void * arg)30 void* runThread(void* arg)
31 {
32     if (arg == nullptr)
33     {
34         IMLOGE0("[runThread] invalid argument");
35         return nullptr;
36     }
37 
38     IImsMediaThread* thread = reinterpret_cast<IImsMediaThread*>(arg);
39     return thread->runBase();
40 }
41 
StartThread()42 bool IImsMediaThread::StartThread()
43 {
44     std::lock_guard<std::mutex> guard(mThreadMutex);
45     mThreadStopped = false;
46 
47     std::thread t1(&runThread, this);
48     t1.detach();
49     return true;
50 }
51 
SetAudioThreadPriority(pid_t tid)52 void IImsMediaThread::SetAudioThreadPriority(pid_t tid)
53 {
54     setAudioThreadPriority(tid);
55 }
56 
StopThread()57 void IImsMediaThread::StopThread()
58 {
59     std::lock_guard<std::mutex> guard(mThreadMutex);
60     mThreadStopped = true;
61 }
62 
IsThreadStopped()63 bool IImsMediaThread::IsThreadStopped()
64 {
65     std::lock_guard<std::mutex> guard(mThreadMutex);
66     return mThreadStopped;
67 }
68 
runBase()69 void* IImsMediaThread::runBase()
70 {
71     return run();
72 }