#include <notepad_commandqueue.h>
Public Member Functions | |
CmdQueue () | |
~CmdQueue () | |
bool | start () |
void | stop () |
void | add (Command *new_command) |
void | flush () |
Definition at line 131 of file notepad_commandqueue.h.
notepad::CmdQueue::CmdQueue | ( | ) |
Definition at line 35 of file notepad_commandqueue.cpp.
notepad::CmdQueue::~CmdQueue | ( | ) |
Definition at line 43 of file notepad_commandqueue.cpp.
void notepad::CmdQueue::add | ( | Command * | new_command | ) |
Definition at line 162 of file notepad_commandqueue.cpp.
References LOGPRINTF, and notepad::CSemaphore::v().
Referenced by notepad::CNotepadPages::get_page().
00163 { 00164 LOGPRINTF("entry"); 00165 g_assert(thread); // cmd can only be added when an workerthread is active 00166 00167 // if being flushed wait for flush to ready 00168 while (flush_flag) 00169 { 00170 g_thread_yield(); 00171 } 00172 00173 // Append task to the end of the task queue. 00174 { 00175 MutexLocker ml(&queue_mutex); //guard 00176 the_queue.push_back(new_command); 00177 sem.v(); 00178 } 00179 LOGPRINTF("exit"); 00180 }
void notepad::CmdQueue::flush | ( | ) |
Definition at line 116 of file notepad_commandqueue.cpp.
References LOGPRINTF, and notepad::CSemaphore::v().
Referenced by notepad::CNotepadPages::delete_page(), notepad::CNotepadPages::get_page(), and notepad::CNotepadPages::insert_page().
00117 { 00118 LOGPRINTF("entry"); 00119 if (thread == 0) 00120 { 00121 return; 00122 } 00123 flush_flag = true; 00124 sem.v(); 00125 00126 LOGPRINTF("exit"); 00127 }
bool notepad::CmdQueue::start | ( | ) |
Definition at line 129 of file notepad_commandqueue.cpp.
References LOGPRINTF.
Referenced by notepad::CNotepadPages::init().
00130 { 00131 LOGPRINTF("entry"); 00132 if (thread != 0) 00133 { 00134 // The thread has been started. 00135 return false; 00136 } 00137 00138 thread = g_thread_create(thread_func, this, TRUE, 0); 00139 LOGPRINTF("exit"); 00140 return thread != 0; 00141 }
void notepad::CmdQueue::stop | ( | void | ) |
Definition at line 143 of file notepad_commandqueue.cpp.
References LOGPRINTF, and notepad::CSemaphore::v().
Referenced by notepad::CNotepadPages::stop().
00144 { 00145 LOGPRINTF("entry"); 00146 if (thread == 0) 00147 { 00148 return; 00149 } 00150 stop_flag = true; 00151 sem.v(); 00152 00153 // Wait for worker thread to die. 00154 g_thread_join(thread); 00155 LOGPRINTF("thread is stopped"); 00156 00157 // Set the thread to be NULL 00158 thread = 0; 00159 LOGPRINTF("exit"); 00160 }