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
4646 int32_t CWelsThreadPool::m_iRefCount = 0;
4747 CWelsLock CWelsThreadPool::m_cInitLock;
4848 int32_t CWelsThreadPool::m_iMaxThreadNum = DEFAULT_THREAD_NUM;
49+CWelsThreadPool* CWelsThreadPool::m_pThreadPoolSelf = NULL;
4950
5051 CWelsThreadPool::CWelsThreadPool() :
5152 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
7576 }
7677
7778
78−CWelsThreadPool& CWelsThreadPool::AddReference () {
79+CWelsThreadPool* CWelsThreadPool::AddReference() {
7980 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+
8188 if (m_iRefCount == 0) {
82− //TODO: will remove this afterwards
83− if (WELS_THREAD_ERROR_OK != m_cThreadPoolSelf.Init()) {
84− m_cThreadPoolSelf.Uninit();
89+ if (WELS_THREAD_ERROR_OK != m_pThreadPoolSelf->Init()) {
90+ m_pThreadPoolSelf->Uninit();
91+ delete m_pThreadPoolSelf;
92+ m_pThreadPoolSelf = NULL;
93+ return NULL;
8594 }
8695 }
8796
@@ -89,7 +98,7 @@ CWelsThreadPool& CWelsThreadPool::AddReference () { · 1 unmodified line
8998
9099 ++ m_iRefCount;
91100 //fprintf(stdout, "m_iRefCount2=%d\n", m_iRefCount);
92− return m_cThreadPoolSelf;
101+ return m_pThreadPoolSelf;
93102 }
94103
95104 void CWelsThreadPool::RemoveInstance() {
@@ -99,6 +108,10 @@ void CWelsThreadPool::RemoveInstance() { · 3 unmodified lines
99108 if (0 == m_iRefCount) {
100109 StopAllRunning();
101110 Uninit();
111+ if (m_pThreadPoolSelf) {
112+ delete m_pThreadPoolSelf;
113+ m_pThreadPoolSelf = NULL;
114+ }
102115 //fprintf(stdout, "m_iRefCount=%d, IdleThreadNum=%d, BusyThreadNum=%d, WaitedTask=%d\n", m_iRefCount, GetIdleThreadNum(), GetBusyThreadNum(), GetWaitedTaskNum());
103116 }
104117 }
@@ -106,7 +119,7 @@ void CWelsThreadPool::RemoveInstance() { · 1 unmodified line
106119
107120 bool CWelsThreadPool::IsReferenced() {
108121 CWelsAutoLock cLock (m_cInitLock);
109− return (m_iRefCount>0);
122+ return (m_iRefCount > 0);
110123 }
111124
112125
@@ -137,7 +150,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::OnTaskStop (CWelsTaskThread* pThread, IW · 24 unmodified lines
137150 return WELS_THREAD_ERROR_OK;
138151 }
139152
140−WELS_THREAD_ERROR_CODE CWelsThreadPool::Init () {
153+WELS_THREAD_ERROR_CODE CWelsThreadPool::Init() {
141154 //fprintf(stdout, "Enter WelsThreadPool Init\n");
142155
143156 CWelsAutoLock cLock (m_cLockPool);
@@ -197,9 +210,9 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::Uninit() { · 53 unmodified lines
197210
198211 Kill();
199212
200− WELS_DELETE_OP(m_cWaitedTasks);
201− WELS_DELETE_OP(m_cIdleThreads);
202− WELS_DELETE_OP(m_cBusyThreads);
213+ WELS_DELETE_OP (m_cWaitedTasks);
214+ WELS_DELETE_OP (m_cIdleThreads);
215+ WELS_DELETE_OP (m_cBusyThreads);
203216
204217 return iReturn;
205218 }
@@ -234,8 +247,8 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::QueueTask (IWelsTask* pTask) { · 28 unmodified lines
234247 }
235248 }
236249 //fprintf(stdout, "ThreadPool: AddTaskToWaitedList: %x\n", pTask);
237− if (false == AddTaskToWaitedList (pTask)){
238− return WELS_THREAD_ERROR_GENERAL;
250+ if (false == AddTaskToWaitedList (pTask)) {
251+ return WELS_THREAD_ERROR_GENERAL;
239252 }
240253
241254 //fprintf(stdout, "ThreadPool: SignalThread: %x\n", pTask);
@@ -261,7 +274,7 @@ WELS_THREAD_ERROR_CODE CWelsThreadPool::CreateIdleThread() { · 19 unmodified lines
261274
262275 void CWelsThreadPool::DestroyThread (CWelsTaskThread* pThread) {
263276 pThread->Kill();
264− WELS_DELETE_OP(pThread);
277+ WELS_DELETE_OP (pThread);
265278
266279 return;
267280 }
@@ -292,7 +305,7 @@ bool CWelsThreadPool::AddTaskToWaitedList (IWelsTask* pTask) { · 24 unmodified lines
292305
293306 int32_t nRet = m_cWaitedTasks->push_back (pTask);
294307 //fprintf(stdout, "CWelsThreadPool::AddTaskToWaitedList=%d, pTask=%x\n", m_cWaitedTasks->size(), pTask);
295− return (0==nRet ? true : false);
308+ return (0 == nRet ? true : false);
296309 }
297310
298311 CWelsTaskThread* 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