5 #ifdef TGT_OS_TYPE_VXWORKS
22 #define DEBUG_PRINT(x,...)
24 typedef void* (*pthread_func_ptr)(
void*);
27 Task::Task() : m_handle(0), m_identifier(0), m_affinity(-1), m_started(
false), m_suspendedOnPurpose(
false) {
34 this->m_identifier = identifier;
40 memset(&att,0,
sizeof(att));
42 I32 stat = pthread_attr_init(&att);
48 stat = pthread_attr_setstacksize(&att,stackSize);
53 stat = pthread_attr_setschedpolicy(&att,SCHED_RR);
59 stat = pthread_attr_setinheritsched(&att,PTHREAD_EXPLICIT_SCHED);
64 sched_param schedParam;
65 memset(&schedParam,0,
sizeof(sched_param));
66 schedParam.sched_priority = priority;
67 stat = pthread_attr_setschedparam(&att,&schedParam);
74 if (cpuAffinity != -1) {
78 CPU_SET(cpuAffinity,&cpuset);
80 stat = pthread_attr_setaffinity_np(&att,
sizeof(cpu_set_t), &cpuset);
88 if (Task::s_taskRegistry) {
89 Task::s_taskRegistry->addTask(
this);
92 pthread_t* tid =
new pthread_t;
98 this->m_handle = (POINTER_CAST)tid;
114 stat = pthread_setname_np(*tid,(
char*)this->m_name.
toChar());
122 (void)pthread_attr_destroy(&att);
131 time1.tv_sec = milliseconds/1000;
132 time1.tv_nsec = (milliseconds%1000)*1000000;
138 timespec* sleepTimePtr = &time1;
139 timespec* remTimePtr = &time2;
142 int stat = nanosleep(sleepTimePtr,remTimePtr);
146 if (EINTR == errno) {
147 timespec* temp = remTimePtr;
148 remTimePtr = sleepTimePtr;
163 if (this->m_handle) {
164 delete (pthread_t*)this->m_handle;
167 if (Task::s_taskRegistry) {
168 Task::s_taskRegistry->removeTask(
this);
190 if (!(this->m_handle)) {
193 stat = pthread_join(*((pthread_t*) this->m_handle), value_ptr);