History

fix low memory crash issue

huili2 committed 9 years ago

Commit d1c0a931 parent 48c2fe116 files · +401 −386Browse files

Showing the changes to codec/common/src/WelsThreadPool.cpp (1 of 16 files). Show all

Unified · Split

codec/common/src/WelsThreadPool.cpp+28−15
@@ -46,6 +46,7 @@ namespace WelsCommon { · 45 unmodified lines
46int32_t CWelsThreadPool::m_iRefCount = 0;46int32_t CWelsThreadPool::m_iRefCount = 0;
47CWelsLock CWelsThreadPool::m_cInitLock;47CWelsLock CWelsThreadPool::m_cInitLock;
48int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;48int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
49CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;
49 50
50CWelsThreadPool::CWelsThreadPool() :51CWelsThreadPool::CWelsThreadPool() :
51 m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL) {52 m_cWaitedTasks (NULL), m_cIdleThreads (NULL), m_cBusyThreads (NULL) {
@@ -75,13 +76,21 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::SetThreadNum (int32_t iMaxThreadNum) { · 23 unmodified lines
75}76}
76 77
77 78
78CWelsThreadPool& CWelsThreadPool::AddReference () {79CWelsThreadPool* CWelsThreadPool::AddReference() {
79 CWelsAutoLock cLock (m_cInitLock);80 CWelsAutoLock cLock (m_cInitLock);
80 static CWelsThreadPool m_cThreadPoolSelf;81 if (m_pThreadPoolSelf == NULL) {
82 m_pThreadPoolSelf = new CWelsThreadPool();
83 if (!m_pThreadPoolSelf) {
84 return NULL;
85 }
86 }
87
81 if (m_iRefCount == 0) {88 if (m_iRefCount == 0) {
82 //TODO: will remove this afterwards89 if (WELS_THREAD_ERROR_OK != m_pThreadPoolSelf->Init()) {
83 if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init()) {90 m_pThreadPoolSelf->Uninit();
84 m_cThreadPoolSelf.Uninit();91 delete m_pThreadPoolSelf;
92 m_pThreadPoolSelf = NULL;
93 return NULL;
85 }94 }
86 }95 }
87 96
@@ -89,7 +98,7 @@ CWelsThreadPool& CWelsThreadPool::AddReference () { · 1 unmodified line
89 98
90 ++ m_iRefCount;99 ++ m_iRefCount;
91 //fprintf(stdout, "m_iRefCount2=%d\n", m_iRefCount);100 //fprintf(stdout, "m_iRefCount2=%d\n", m_iRefCount);
92 return m_cThreadPoolSelf;101 return m_pThreadPoolSelf;
93}102}
94 103
95void CWelsThreadPool::RemoveInstance() {104void CWelsThreadPool::RemoveInstance() {
@@ -99,6 +108,10 @@ void CWelsThreadPool::RemoveInstance() { · 3 unmodified lines
99 if (0 == m_iRefCount) {108 if (0 == m_iRefCount) {
100 StopAllRunning();109 StopAllRunning();
101 Uninit();110 Uninit();
111 if (m_pThreadPoolSelf) {
112 delete m_pThreadPoolSelf;
113 m_pThreadPoolSelf = NULL;
114 }
102 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());115 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
103 }116 }
104}117}
@@ -106,7 +119,7 @@ void CWelsThreadPool::RemoveInstance() { · 1 unmodified line
106 119
107bool CWelsThreadPool::IsReferenced() {120bool CWelsThreadPool::IsReferenced() {
108 CWelsAutoLock cLock (m_cInitLock);121 CWelsAutoLock cLock (m_cInitLock);
109 return (m_iRefCount>0);122 return (m_iRefCount > 0);
110}123}
111 124
112 125
@@ -137,7 +150,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IW · 24 unmodified lines
137 return WELS_THREAD_ERROR_OK;150 return WELS_THREAD_ERROR_OK;
138}151}
139 152
140WELS_THREAD_ERROR_CODE CWelsThreadPool::Init () {153WELS_THREAD_ERROR_CODE CWelsThreadPool::Init() {
141 //fprintf(stdout, "Enter WelsThreadPool Init\n");154 //fprintf(stdout, "Enter WelsThreadPool Init\n");
142 155
143 CWelsAutoLock cLock (m_cLockPool);156 CWelsAutoLock cLock (m_cLockPool);
@@ -197,9 +210,9 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::Uninit() { · 53 unmodified lines
197 210
198 Kill();211 Kill();
199 212
200 WELS_DELETE_OP(m_cWaitedTasks);213 WELS_DELETE_OP (m_cWaitedTasks);
201 WELS_DELETE_OP(m_cIdleThreads);214 WELS_DELETE_OP (m_cIdleThreads);
202 WELS_DELETE_OP(m_cBusyThreads);215 WELS_DELETE_OP (m_cBusyThreads);
203 216
204 return iReturn;217 return iReturn;
205}218}
@@ -234,8 +247,8 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::QueueTask (IWelsTask* pTask) { · 28 unmodified lines
234 }247 }
235 }248 }
236 //fprintf(stdout, "ThreadPool: AddTaskToWaitedList: %x\n", pTask);249 //fprintf(stdout, "ThreadPool: AddTaskToWaitedList: %x\n", pTask);
237 if (false == AddTaskToWaitedList (pTask)){250 if (false == AddTaskToWaitedList (pTask)) {
238 return WELS_THREAD_ERROR_GENERAL;251 return WELS_THREAD_ERROR_GENERAL;
239 }252 }
240 253
241 //fprintf(stdout, "ThreadPool: SignalThread: %x\n", pTask);254 //fprintf(stdout, "ThreadPool: SignalThread: %x\n", pTask);
@@ -261,7 +274,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::CreateIdleThread() { · 19 unmodified lines
261 274
262void CWelsThreadPool::DestroyThread (CWelsTaskThread* pThread) {275void CWelsThreadPool::DestroyThread (CWelsTaskThread* pThread) {
263 pThread->Kill();276 pThread->Kill();
264 WELS_DELETE_OP(pThread);277 WELS_DELETE_OP (pThread);
265 278
266 return;279 return;
267}280}
@@ -292,7 +305,7 @@ bool CWelsThreadPool::AddTaskToWaitedList (IWelsTask* pTask) { · 24 unmodified lines
292 305
293 int32_t nRet = m_cWaitedTasks->push_back (pTask);306 int32_t nRet = m_cWaitedTasks->push_back (pTask);
294 //fprintf(stdout, "CWelsThreadPool::AddTaskToWaitedList=%d, pTask=%x\n", m_cWaitedTasks->size(), pTask);307 //fprintf(stdout, "CWelsThreadPool::AddTaskToWaitedList=%d, pTask=%x\n", m_cWaitedTasks->size(), pTask);
295 return (0==nRet ? true : false);308 return (0 == nRet ? true : false);
296}309}
297 310
298CWelsTaskThread* CWelsThreadPool::GetIdleThread() {311CWelsTaskThread* CWelsThreadPool::GetIdleThread() {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t