1.
using pthread_mutex_t for lock
using pthread_cond_t for signal
using std::vector for queue
using singleton in class
static TaskQueue* Get();
static void Free();
2. task queue source clip
int TaskQueue::Process(int type, NODE_YUV* node_yuv)
{
int ret; //each thread own it's local variable address
pthread_mutex_lock(&m_process_lock);
switch(type)
{
case 0: //read first node
if ( ret = m_vqueue.size() > 0 )
{
memcpy(node_yuv, &(*m_vqueue.begin()), sizeof(NODE_YUV));
m_vqueue.erase(m_vqueue.begin());
}
break;
case 1: //save last node
m_vqueue.push_back(*node_yuv);
break;
}
pthread_mutex_unlock(&m_process_lock);
return ret;
}
void TaskQueue::TaskThreadLoop()
{
int ret;
NODE_YUV node_yuv;
while(m_thread_work)
{
ret = Process(0, &node_yuv);
if( ret )
{
//ur work start
//ur work end
printf("free %p size=%d\n", node_yuv.buf, node_yuv.size);
free(node_yuv.buf);
}
else
{
//wait signal when queue empty
pthread_mutex_lock(&m_taskqueue_work_lock);
pthread_cond_wait(&m_taskqueue_work_cond, &m_taskqueue_work_lock);
pthread_mutex_unlock(&m_taskqueue_work_lock);
}
}
}
3.
using std::ifstream for reading
using std::ofstream for writing
4. ini source clip
std::ifstream inifile;
inifile.open(m_filepath, std::ifstream::in);
std::ofstream inifile;
inifile.open(m_filepath, std::ofstream::out | std::ofstream::trunc);
source download:
https://www.mediafire.com/file/pry0z0x8pdsnm29/taskqueueini.tar.gz
沒有留言:
張貼留言