3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2011 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
23 |
|
|
24 |
#include "Thread.h" |
#include "Thread.h" |
25 |
|
|
26 |
|
#if HAVE_CONFIG_H |
27 |
|
# include <config.h> |
28 |
|
#endif |
29 |
|
|
30 |
// this is the minimum stack size a thread will be spawned with |
// this is the minimum stack size a thread will be spawned with |
31 |
// if this value is too small, the OS will allocate memory on demand and |
// if this value is too small, the OS will allocate memory on demand and |
32 |
// thus might lead to dropouts in realtime threads |
// thus might lead to dropouts in realtime threads |
154 |
RunningCondition.Set(false); |
RunningCondition.Set(false); |
155 |
return res; |
return res; |
156 |
} |
} |
157 |
|
|
158 |
// Create and run the thread |
// Create and run the thread |
159 |
res = pthread_create(&this->__thread_id, &__thread_attr, __pthread_launcher, this); |
res = pthread_create(&this->__thread_id, &__thread_attr, __pthread_launcher, this); |
160 |
switch (res) { |
switch (res) { |
223 |
#else |
#else |
224 |
RunningCondition.Set(false); |
RunningCondition.Set(false); |
225 |
#endif |
#endif |
226 |
#else |
#else |
227 |
pthread_cancel(__thread_id); |
pthread_cancel(__thread_id); |
228 |
#endif |
#endif |
229 |
return 0; |
return 0; |
367 |
return 0; |
return 0; |
368 |
} |
} |
369 |
|
|
370 |
|
void Thread::TestCancel() { |
371 |
|
#if CONFIG_PTHREAD_TESTCANCEL |
372 |
|
pthread_testcancel(); |
373 |
|
#endif |
374 |
|
} |
375 |
|
|
376 |
#if defined(WIN32) |
#if defined(WIN32) |
377 |
DWORD WINAPI __win32thread_launcher(LPVOID lpParameter) { |
DWORD WINAPI __win32thread_launcher(LPVOID lpParameter) { |
378 |
Thread* t; |
Thread* t; |
386 |
#else |
#else |
387 |
/// Callback function for the POSIX thread API |
/// Callback function for the POSIX thread API |
388 |
static void* __pthread_launcher(void* thread) { |
static void* __pthread_launcher(void* thread) { |
389 |
|
#if !CONFIG_PTHREAD_TESTCANCEL |
390 |
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); // let the thread be killable under any circumstances |
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); // let the thread be killable under any circumstances |
391 |
|
#endif |
392 |
|
|
393 |
Thread* t; |
Thread* t; |
394 |
t = (Thread*) thread; |
t = (Thread*) thread; |
395 |
t->SetSchedulingPriority(); |
t->SetSchedulingPriority(); |