MCPcopy Create free account
hub / github.com/amule-project/amule / CreateSchedulerThread

Method CreateSchedulerThread

src/ThreadScheduler.cpp:139–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137
138
139void CThreadScheduler::CreateSchedulerThread()
140{
141 if ((m_thread && m_thread->IsAlive()) || m_tasks.empty()) {
142 return;
143 }
144
145 // A thread can only be run once, so the old one must be safely disposed of
146 if (m_thread) {
147 AddDebugLogLineN(logThreads, "CreateSchedulerThread: Disposing of old thread.");
148 m_thread->Stop();
149 delete m_thread;
150 }
151
152 m_thread = new CTaskThread(this);
153
154 wxThreadError err = m_thread->Create();
155 if (err == wxTHREAD_NO_ERROR) {
156 // Try to avoid reducing the latency of the main thread
157 m_thread->SetPriority(WXTHREAD_MIN_PRIORITY);
158
159 err = m_thread->Run();
160 if (err == wxTHREAD_NO_ERROR) {
161 AddDebugLogLineN(logThreads, "Scheduler thread started");
162 return;
163 } else {
164 AddDebugLogLineC(logThreads, "Error while starting scheduler thread: " + GetErrMsg(err));
165 }
166 } else {
167 AddDebugLogLineC(logThreads, "Error while creating scheduler thread: " + GetErrMsg(err));
168 }
169
170 // Creation or running failed.
171 m_thread->Stop();
172 delete m_thread;
173 m_thread = NULL;
174}
175
176
177/** This is the sorter functor for the task-queue. */

Callers 1

StartMethod · 0.80

Calls 5

GetErrMsgFunction · 0.85
RunMethod · 0.80
emptyMethod · 0.45
StopMethod · 0.45
CreateMethod · 0.45

Tested by

no test coverage detected