forked from ithzhang/ThreadpoolLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyStack.cpp
61 lines (61 loc) · 919 Bytes
/
MyStack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "MyStack.h"
#include<cassert>
#include"MyThread.h"
CMyStack::CMyStack(void)
{
}
CMyStack::~CMyStack(void)
{
}
CMyThread* CMyStack::pop()
{
m_mutext.Lock();
if(!m_stack.empty())
{
CMyThread *t=m_stack.top();
m_stack.pop();
m_mutext.Unlock();
return t;
}
m_mutext.Unlock();
return NULL;
}
bool CMyStack::push( CMyThread* t)
{
assert(t);
if(!t)
return false;
m_mutext.Lock();
m_stack.push(t);
m_mutext.Unlock();
return true;
}
int CMyStack::getSize()
{
m_mutext.Lock();
int size= m_stack.size();
m_mutext.Unlock();
return size;
}
bool CMyStack::isEmpty()
{
m_mutext.Lock();
bool ret= m_stack.empty();
m_mutext.Unlock();
return ret;
}
bool CMyStack::clear()
{
m_mutext.Lock();
CMyThread*pThread=NULL;
while(!m_stack.empty())
{
pThread=m_stack.top();
m_stack.pop();
pThread->resumeThread();
pThread->m_bIsExit=true;
delete pThread;
}
m_mutext.Unlock();
return true;
}