1 //////////////////////////////////////////////////////////////////////////////
2 // Filename: vxWorks.cc
3 // Author: Tihomir Sokcevic
5 // Description: vxWorks adaptation of the omnithread wrapper classes
6 // Notes: Munching strategy is imperative
7 //////////////////////////////////////////////////////////////////////////////
9 // Revision 1.1 2004/04/10 18:00:52 eb
12 // Revision 1.1.1.1 2004/03/01 00:20:27 eb
15 // Revision 1.1 2003/05/25 05:29:04 eb
18 // Revision 1.1.2.1 2003/02/17 02:03:11 dgrisby
19 // vxWorks port. (Thanks Michael Sturm / Acterna Eningen GmbH).
21 // Revision 1.1.1.1 2002/11/19 14:58:04 sokcevti
22 // OmniOrb4.0.0 VxWorks port
24 // Revision 1.4 2002/10/15 07:54:09 kuttlest
25 // change semaphore from SEM_FIFO to SEM_PRIO
28 // Revision 1.3 2002/07/05 07:38:52 engeln
29 // made priority redefinable on load time by defining int variables
30 // omni_thread_prio_low = 220;
31 // omni_thread_prio_normal = 110;
32 // omni_thread_prio_high = 55;
33 // the default priority is prio_normal.
34 // The normal priority default has been increased from 200 to 110 and the
35 // high priority from 100 to 55.
38 // Revision 1.2 2002/06/14 12:44:57 engeln
39 // replaced possibly unsafe wakeup procedure in broadcast.
42 // Revision 1.1.1.1 2002/04/02 10:09:34 sokcevti
43 // omniORB4 initial realease
45 // Revision 1.0 2001/10/23 14:22:45 sokcevti
46 // Initial Version 4.00
49 //////////////////////////////////////////////////////////////////////////////
52 //////////////////////////////////////////////////////////////////////////////
54 //////////////////////////////////////////////////////////////////////////////
59 #include <omnithread.h>
62 #include <assert.h> // assert
63 #include <intLib.h> // intContext
66 //////////////////////////////////////////////////////////////////////////////
68 //////////////////////////////////////////////////////////////////////////////
69 #define ERRNO(x) (((x) != 0) ? (errno) : 0)
70 #define THROW_ERRORS(x) { if((x) != OK) throw omni_thread_fatal(errno); }
71 #define OMNI_THREAD_ID 0x7F7155AAl
72 #define OMNI_STACK_SIZE 32768l
76 #define DBG_TRACE(X) X
83 #define DBG_THROW(X) X
85 int omni_thread_prio_low = 220;
86 int omni_thread_prio_normal = 110;
87 int omni_thread_prio_high = 55;
88 ///////////////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////////////
93 omni_mutex::omni_mutex(void):m_bConstructed(false)
95 mutexID = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE);
97 DBG_ASSERT(assert(mutexID != NULL));
101 DBG_TRACE(cout<<"Exception: omni_mutex::omni_mutex() tid: "<<(int)taskIdSelf()<<endl);
102 DBG_THROW(throw omni_thread_fatal(-1));
105 m_bConstructed = true;
108 omni_mutex::~omni_mutex(void)
110 m_bConstructed = false;
112 STATUS status = semDelete(mutexID);
114 DBG_ASSERT(assert(status == OK));
118 DBG_TRACE(cout<<"Exception: omni_mutex::~omni_mutex() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl);
119 DBG_THROW(throw omni_thread_fatal(errno));
124 void omni_mutex::lock(void)
126 DBG_ASSERT(assert(!intContext())); // not in ISR context
127 DBG_ASSERT(assert(m_bConstructed));
129 STATUS status = semTake(mutexID, WAIT_FOREVER);
131 DBG_ASSERT(assert(status == OK));
135 DBG_TRACE(cout<<"Exception: omni_mutex::lock() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl);
136 DBG_THROW(throw omni_thread_fatal(errno));
140 void omni_mutex::unlock(void)
142 DBG_ASSERT(assert(m_bConstructed));
144 STATUS status = semGive(mutexID);
146 DBG_ASSERT(assert(status == OK));
150 DBG_TRACE(cout<<"Exception: omni_mutex::unlock() mutexID: "<<(int)mutexID<<" tid: "<<(int)taskIdSelf()<<endl);
151 DBG_THROW(throw omni_thread_fatal(errno));
156 ///////////////////////////////////////////////////////////////////////////
158 // Condition variable
160 ///////////////////////////////////////////////////////////////////////////
161 omni_condition::omni_condition(omni_mutex* m) : mutex(m)
163 DBG_TRACE(cout<<"omni_condition::omni_condition mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl);
167 sema_ = semCCreate(SEM_Q_PRIORITY, 0);
170 DBG_TRACE(cout<<"Exception: omni_condition::omni_condition() tid: "<<(int)taskIdSelf()<<endl);
171 DBG_THROW(throw omni_thread_fatal(errno));
174 waiters_lock_ = semMCreate(SEM_Q_PRIORITY | SEM_INVERSION_SAFE);
175 if(waiters_lock_ == NULL)
177 DBG_TRACE(cout<<"Exception: omni_condition::omni_condition() tid: "<<(int)taskIdSelf()<<endl);
178 DBG_THROW(throw omni_thread_fatal(errno));
183 omni_condition::~omni_condition(void)
185 STATUS status = semDelete(waiters_lock_);
187 DBG_ASSERT(assert(status == OK));
191 DBG_TRACE(cout<<"Exception: omni_condition::~omni_condition"<<endl);
192 DBG_THROW(throw omni_thread_fatal(errno));
195 status = semDelete(sema_);
197 DBG_ASSERT(assert(status == OK));
201 DBG_TRACE(cout<<"Exception: omni_condition::~omni_condition"<<endl);
202 DBG_THROW(throw omni_thread_fatal(errno));
206 void omni_condition::wait(void)
208 DBG_TRACE(cout<<"omni_condition::wait mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl);
210 // Prevent race conditions on the <waiters_> count.
212 STATUS status = semTake(waiters_lock_,WAIT_FOREVER);
214 DBG_ASSERT(assert(status == OK));
218 DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl);
219 DBG_THROW(throw omni_thread_fatal(errno));
224 status = semGive(waiters_lock_);
226 DBG_ASSERT(assert(status == OK));
230 DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl);
231 DBG_THROW(throw omni_thread_fatal(errno));
234 // disable task lock to have an atomic unlock+semTake
237 // We keep the lock held just long enough to increment the count of
238 // waiters by one. Note that we can't keep it held across the call
239 // to wait() since that will deadlock other calls to signal().
242 // Wait to be awakened by a cond_signal() or cond_broadcast().
243 status = semTake(sema_,WAIT_FOREVER);
245 // reenable task rescheduling
248 DBG_ASSERT(assert(status == OK));
252 DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl);
253 DBG_THROW(throw omni_thread_fatal(errno));
256 // Reacquire lock to avoid race conditions on the <waiters_> count.
257 status = semTake(waiters_lock_,WAIT_FOREVER);
259 DBG_ASSERT(assert(status == OK));
263 DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl);
264 DBG_THROW(throw omni_thread_fatal(errno));
267 // We're ready to return, so there's one less waiter.
270 // Release the lock so that other collaborating threads can make
272 status = semGive(waiters_lock_);
274 DBG_ASSERT(assert(status == OK));
278 DBG_TRACE(cout<<"Exception: omni_condition::wait"<<endl);
279 DBG_THROW(throw omni_thread_fatal(errno));
282 // Bad things happened, so let's just return below.
284 // We must always regain the <external_mutex>, even when errors
285 // occur because that's the guarantee that we give to our callers.
290 // The time given is absolute. Return 0 is timeout
291 int omni_condition::timedwait(unsigned long secs, unsigned long nanosecs)
295 unsigned long timeout;
298 // Prevent race conditions on the <waiters_> count.
299 STATUS status = semTake(waiters_lock_, WAIT_FOREVER);
301 DBG_ASSERT(assert(status == OK));
305 DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl);
306 DBG_THROW(throw omni_thread_fatal(errno));
311 status = semGive(waiters_lock_);
313 DBG_ASSERT(assert(status == OK));
317 DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl);
318 DBG_THROW(throw omni_thread_fatal(errno));
321 clock_gettime(CLOCK_REALTIME, &now);
323 if(((unsigned long)secs <= (unsigned long)now.tv_sec) &&
324 (((unsigned long)secs < (unsigned long)now.tv_sec) ||
325 (nanosecs < (unsigned long)now.tv_nsec)))
328 timeout = (secs-now.tv_sec) * 1000 + (nanosecs-now.tv_nsec) / 1000000l;
330 // disable task lock to have an atomic unlock+semTake
333 // We keep the lock held just long enough to increment the count
334 // of waiters by one.
337 // Wait to be awakened by a signal() or broadcast().
338 ticks = (timeout * sysClkRateGet()) / 1000L;
339 result = semTake(sema_, ticks);
341 // reenable task rescheduling
344 // Reacquire lock to avoid race conditions.
345 status = semTake(waiters_lock_, WAIT_FOREVER);
347 DBG_ASSERT(assert(status == OK));
351 DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl);
352 DBG_THROW(throw omni_thread_fatal(errno));
357 status = semGive(waiters_lock_);
359 DBG_ASSERT(assert(status == OK));
363 DBG_TRACE(cout<<"Exception: omni_condition::timedwait"<<endl);
364 DBG_THROW(throw omni_thread_fatal(errno));
367 // A timeout has occured - fires exception if the origin is other than timeout
368 if(result!=OK && !(errno == S_objLib_OBJ_TIMEOUT || errno == S_objLib_OBJ_UNAVAILABLE))
370 DBG_TRACE(cout<<"omni_condition::timedwait! - thread:"<<omni_thread::self()->id()<<" SemID:"<<(int)sema_<<" errno:"<<errno<<endl);
371 DBG_THROW(throw omni_thread_fatal(errno));
374 // We must always regain the <external_mutex>, even when errors
375 // occur because that's the guarantee that we give to our callers.
378 if(result!=OK) // timeout
384 void omni_condition::signal(void)
386 DBG_TRACE(cout<<"omni_condition::signal mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl);
388 STATUS status = semTake(waiters_lock_, WAIT_FOREVER);
390 DBG_ASSERT(assert(status == OK));
394 DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl);
395 DBG_THROW(throw omni_thread_fatal(errno));
398 int have_waiters = waiters_ > 0;
400 status = semGive(waiters_lock_);
402 DBG_ASSERT(assert(status == OK));
406 DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl);
407 DBG_THROW(throw omni_thread_fatal(errno));
410 if(have_waiters != 0)
412 status = semGive(sema_);
414 DBG_ASSERT(assert(status == OK));
418 DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl);
419 DBG_THROW(throw omni_thread_fatal(errno));
424 void omni_condition::broadcast(void)
426 DBG_TRACE(cout<<"omni_condition::broadcast mutexID: "<<(int)mutex->mutexID<<" tid:"<<(int)taskIdSelf()<<endl);
428 int have_waiters = 0;
430 // The <external_mutex> must be locked before this call is made.
431 // This is needed to ensure that <waiters_> and <was_broadcast_> are
432 // consistent relative to each other.
433 STATUS status = semTake(waiters_lock_, WAIT_FOREVER);
435 DBG_ASSERT(assert(status == OK));
439 DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl);
440 DBG_THROW(throw omni_thread_fatal(errno));
445 // We are broadcasting, even if there is just one waiter...
446 // Record the fact that we are broadcasting. This helps the
447 // cond_wait() method know how to optimize itself. Be sure to
448 // set this with the <waiters_lock_> held.
452 status = semGive(waiters_lock_);
454 DBG_ASSERT(assert(status == OK));
458 DBG_TRACE(cout<<"Exception: omni_condition::signal"<<endl);
459 DBG_THROW(throw omni_thread_fatal(errno));
464 // Wake up all the waiters.
465 status = semFlush(sema_);
467 DBG_ASSERT(assert(status == OK));
471 DBG_TRACE(cout<<"omni_condition::broadcast1! - thread:"<<omni_thread::self()->id()<<" SemID:"<<(int)sema_<<" errno:"<<errno<<endl);
472 DBG_THROW(throw omni_thread_fatal(errno));
479 ///////////////////////////////////////////////////////////////////////////
481 // Counting semaphore
483 ///////////////////////////////////////////////////////////////////////////
484 omni_semaphore::omni_semaphore(unsigned int initial)
487 DBG_ASSERT(assert(0 <= (int)initial)); // POSIX expects only unsigned init values
489 semID = semCCreate(SEM_Q_PRIORITY, (int)initial);
491 DBG_ASSERT(assert(semID!=NULL));
495 DBG_TRACE(cout<<"Exception: omni_semaphore::omni_semaphore"<<endl);
496 DBG_THROW(throw omni_thread_fatal(-1));
500 omni_semaphore::~omni_semaphore(void)
502 STATUS status = semDelete(semID);
504 DBG_ASSERT(assert(status == OK));
508 DBG_TRACE(cout<<"Exception: omni_semaphore::~omni_semaphore"<<endl);
509 DBG_THROW(throw omni_thread_fatal(errno));
513 void omni_semaphore::wait(void)
515 DBG_ASSERT(assert(!intContext())); // no wait in ISR
517 STATUS status = semTake(semID, WAIT_FOREVER);
519 DBG_ASSERT(assert(status == OK));
523 DBG_TRACE(cout<<"Exception: omni_semaphore::wait"<<endl);
524 DBG_THROW(throw omni_thread_fatal(errno));
528 int omni_semaphore::trywait(void)
530 STATUS status = semTake(semID, NO_WAIT);
532 DBG_ASSERT(assert(status == OK));
536 if(errno == S_objLib_OBJ_UNAVAILABLE)
542 DBG_ASSERT(assert(false));
544 DBG_TRACE(cout<<"Exception: omni_semaphore::trywait"<<endl);
545 DBG_THROW(throw omni_thread_fatal(errno));
552 void omni_semaphore::post(void)
554 STATUS status = semGive(semID);
556 DBG_ASSERT(assert(status == OK));
560 DBG_TRACE(cout<<"Exception: omni_semaphore::post"<<endl);
561 DBG_THROW(throw omni_thread_fatal(errno));
567 ///////////////////////////////////////////////////////////////////////////
571 ///////////////////////////////////////////////////////////////////////////
577 omni_mutex* omni_thread::next_id_mutex = 0;
578 int omni_thread::next_id = 0;
580 // omniORB requires a larger stack size than the default (21120) on OSF/1
581 static size_t stack_size = OMNI_STACK_SIZE;
585 // Initialisation function (gets called before any user code).
588 static int& count() {
589 static int the_count = 0;
593 omni_thread::init_t::init_t(void)
595 // Only do it once however many objects get created.
602 omni_thread::init_t::~init_t(void)
604 if (--count() != 0) return;
606 omni_thread* self = omni_thread::self();
609 taskTcb(taskIdSelf())->spare1 = 0;
612 delete next_id_mutex;
617 // Wrapper for thread creation.
619 extern "C" void omni_thread_wrapper(void* ptr)
621 omni_thread* me = (omni_thread*)ptr;
623 DBG_TRACE(cout<<"omni_thread_wrapper: thread "<<me->id()<<" started\n");
626 // We can now tweaked the task info since the tcb exist now
628 me->mutex.lock(); // To ensure that start has had time to finish
629 taskTcb(me->tid)->spare1 = OMNI_THREAD_ID;
630 taskTcb(me->tid)->spare2 = (int)ptr;
634 // Now invoke the thread function with the given argument.
636 if(me->fn_void != NULL)
638 (*me->fn_void)(me->thread_arg);
642 if(me->fn_ret != NULL)
644 void* return_value = (*me->fn_ret)(me->thread_arg);
645 omni_thread::exit(return_value);
650 me->run(me->thread_arg);
655 void* return_value = me->run_undetached(me->thread_arg);
656 omni_thread::exit(return_value);
662 // Special functions for VxWorks only
664 void omni_thread::attach(void)
666 DBG_TRACE(cout<<"omni_thread_attach: VxWorks mapping thread initialising\n");
668 int _tid = taskIdSelf();
670 // Check the task is not already attached
671 if(taskTcb(_tid)->spare1 == OMNI_THREAD_ID)
674 // Create the mutex required to lock the threads debugging id (create before the thread!!!)
675 if(next_id_mutex == 0)
676 next_id_mutex = new omni_mutex;
678 // Create a thread object for THIS running process
679 omni_thread* t = new omni_thread;
681 // Lock its mutex straigh away!
682 omni_mutex_lock l(t->mutex);
684 // Adjust data members of this instance
685 t->_state = STATE_RUNNING;
686 t->tid = taskIdSelf();
688 // Set the thread values so it can be recongnised as a omni_thread
689 // Set the id last can possibly prevent race condition
690 taskTcb(t->tid)->spare2 = (int)t;
691 taskTcb(t->tid)->spare1 = OMNI_THREAD_ID;
693 // Create the running_mutex at this stage, but leave it empty. We are not running
694 // in the task context HERE, so taking it would be disastrous.
695 t->running_cond = new omni_condition(&t->mutex);
699 void omni_thread::detach(void)
701 DBG_TRACE(cout<<"omni_thread_detach: VxWorks detaching thread mapping\n");
703 int _tid = taskIdSelf();
705 // Check the task has a OMNI_THREAD attached
706 if(taskTcb(_tid)->spare1 != OMNI_THREAD_ID)
709 // Invalidate the id NOW !
710 taskTcb(_tid)->spare1 = 0;
712 // Even if NULL, it is safe to delete the thread
713 omni_thread* t = (omni_thread*)taskTcb(_tid)->spare2;
714 // Fininsh cleaning the tcb structure
715 taskTcb(_tid)->spare2 = 0;
722 // Constructors for omni_thread - set up the thread object but don't
726 // construct a detached thread running a given function.
727 omni_thread::omni_thread(void (*fn)(void*), void* arg, priority_t pri)
729 common_constructor(arg, pri, 1);
734 // construct an undetached thread running a given function.
735 omni_thread::omni_thread(void* (*fn)(void*), void* arg, priority_t pri)
737 common_constructor(arg, pri, 0);
742 // construct a thread which will run either run() or run_undetached().
744 omni_thread::omni_thread(void* arg, priority_t pri)
746 common_constructor(arg, pri, 1);
751 // common part of all constructors.
752 void omni_thread::common_constructor(void* arg, priority_t pri, int det)
757 // Set the debugging id
758 next_id_mutex->lock();
760 next_id_mutex->unlock();
762 // Note : tid can only be setup when the task is up and running
766 detached = det; // may be altered in start_undetached()
774 // Destructor for omni_thread.
776 omni_thread::~omni_thread(void)
778 DBG_TRACE(cout<<"omni_thread::~omni_thread for thread "<<id()<<endl);
781 for (key_t i=0; i < _value_alloc; i++) {
796 void omni_thread::start(void)
798 omni_mutex_lock l(mutex);
800 DBG_ASSERT(assert(_state == STATE_NEW));
802 if(_state != STATE_NEW)
803 DBG_THROW(throw omni_thread_invalid());
805 // Allocate memory for the task. (The returned id cannot be trusted by the task)
808 vxworks_priority(_priority), // Priority
810 stack_size, // Stack size
811 (FUNCPTR)omni_thread_wrapper, // Priority
812 (int)this, // First argument is this
813 0,0,0,0,0,0,0,0,0 // Remaining unused args
816 DBG_ASSERT(assert(tid!=ERROR));
819 DBG_THROW(throw omni_thread_invalid());
821 _state = STATE_RUNNING;
823 // Create the running_mutex at this stage, but leave it empty. We are not running
824 // in the task context HERE, so taking it would be disastrous.
825 running_cond = new omni_condition(&mutex);
830 // Start a thread which will run the member function run_undetached().
832 void omni_thread::start_undetached(void)
834 DBG_ASSERT(assert(!((fn_void != NULL) || (fn_ret != NULL))));
836 if((fn_void != NULL) || (fn_ret != NULL))
837 DBG_THROW(throw omni_thread_invalid());
846 // join - Wait for the task to complete before returning to the calling process
848 void omni_thread::join(void** status)
852 if((_state != STATE_RUNNING) && (_state != STATE_TERMINATED))
856 DBG_ASSERT(assert(false));
858 DBG_THROW(throw omni_thread_invalid());
863 DBG_ASSERT(assert(this != self()));
866 DBG_THROW(throw omni_thread_invalid());
868 DBG_ASSERT(assert(!detached));
871 DBG_THROW(throw omni_thread_invalid());
874 running_cond->wait();
878 *status = return_val;
885 // Change this thread's priority.
887 void omni_thread::set_priority(priority_t pri)
889 omni_mutex_lock l(mutex);
891 DBG_ASSERT(assert(_state == STATE_RUNNING));
893 if(_state != STATE_RUNNING)
895 DBG_THROW(throw omni_thread_invalid());
900 if(taskPrioritySet(tid, vxworks_priority(pri))==ERROR)
902 DBG_ASSERT(assert(false));
904 DBG_THROW(throw omni_thread_fatal(errno));
910 // create - construct a new thread object and start it running. Returns thread
911 // object if successful, null pointer if not.
914 // detached version (the entry point is a void)
915 omni_thread* omni_thread::create(void (*fn)(void*), void* arg, priority_t pri)
917 omni_thread* t = new omni_thread(fn, arg, pri);
924 // undetached version (the entry point is a void*)
925 omni_thread* omni_thread::create(void* (*fn)(void*), void* arg, priority_t pri)
927 omni_thread* t = new omni_thread(fn, arg, pri);
936 // exit() _must_ lock the mutex even in the case of a detached thread. This is
937 // because a thread may run to completion before the thread that created it has
938 // had a chance to get out of start(). By locking the mutex we ensure that the
939 // creating thread must have reached the end of start() before we delete the
940 // thread object. Of course, once the call to start() returns, the user can
941 // still incorrectly refer to the thread object, but that's their problem.
943 void omni_thread::exit(void* return_value)
945 omni_thread* me = self();
951 me->return_val = return_value;
952 me->_state = STATE_TERMINATED;
953 me->running_cond->signal();
957 DBG_TRACE(cout<<"omni_thread::exit: thread "<<me->id()<<" detached "<<me->detached<<" return value "<<(int)return_value<<endl);
963 DBG_TRACE(cout<<"omni_thread::exit: called with a non-omnithread. Exit quietly."<<endl);
965 taskDelete(taskIdSelf());
969 omni_thread* omni_thread::self(void)
971 if(taskTcb(taskIdSelf())->spare1 != OMNI_THREAD_ID)
974 return (omni_thread*)taskTcb(taskIdSelf())->spare2;
978 void omni_thread::yield(void)
984 void omni_thread::sleep(unsigned long secs, unsigned long nanosecs)
986 int tps = sysClkRateGet();
988 // Convert to us to avoid overflow in the multiplication
989 // tps should always be less than 1000 !
992 taskDelay(secs*tps + (nanosecs*tps)/1000000l);
996 void omni_thread::get_time( unsigned long* abs_sec,
997 unsigned long* abs_nsec,
998 unsigned long rel_sec,
999 unsigned long rel_nsec)
1002 clock_gettime(CLOCK_REALTIME, &abs);
1003 abs.tv_nsec += rel_nsec;
1004 abs.tv_sec += rel_sec + abs.tv_nsec / 1000000000;
1005 abs.tv_nsec = abs.tv_nsec % 1000000000;
1006 *abs_sec = abs.tv_sec;
1007 *abs_nsec = abs.tv_nsec;
1011 int omni_thread::vxworks_priority(priority_t pri)
1016 return omni_thread_prio_low;
1018 case PRIORITY_NORMAL:
1019 return omni_thread_prio_normal;
1022 return omni_thread_prio_high;
1025 DBG_ASSERT(assert(false));
1027 DBG_THROW(throw omni_thread_invalid());
1031 void omni_thread::stacksize(unsigned long sz)
1037 unsigned long omni_thread::stacksize()
1043 void omni_thread::show(void)
1045 omni_thread *pThread;
1047 int tid = taskIdSelf();
1049 printf("TaskId is %.8x\n", tid);
1051 s1 = taskTcb(tid)->spare1;
1053 if(s1 != OMNI_THREAD_ID)
1055 printf("Spare 1 is %.8x, and not recongnized\n", s1);
1061 printf("Spare 1 indicate an omni_thread.\n");
1064 s2 = taskTcb(tid)->spare2;
1068 printf("Spare 2 is NULL! - No thread object attached !!\n");
1074 printf("Thread object at %.8x\n", s2);
1077 pThread = (omni_thread *)s2;
1079 state_t status = pThread->_state;
1081 printf(" | Thread status is ");
1086 printf("NEW\n"); break;
1088 printf("STATE_RUNNING\n"); break;
1089 case STATE_TERMINATED:
1090 printf("TERMINATED\n"); break;
1092 printf("Illegal (=%.8x)\n", (unsigned int)status);
1097 if(pThread->tid != tid)
1099 printf(" | Task ID in thread object is different!! (=%.8x)\n", pThread->tid);
1105 printf(" | Task ID in thread consistent\n");
1116 class omni_thread_dummy : public omni_thread {
1118 inline omni_thread_dummy() : omni_thread()
1121 _state = STATE_RUNNING;
1123 // Adjust data members of this instance
1126 // Set the thread values so it can be recongnised as a omni_thread
1127 // Set the id last can possibly prevent race condition
1128 taskTcb(tid)->spare2 = (int)this;
1129 taskTcb(tid)->spare1 = OMNI_THREAD_ID;
1131 inline ~omni_thread_dummy()
1133 taskTcb(taskIdSelf())->spare1 = 0;
1138 omni_thread::create_dummy()
1140 if (omni_thread::self())
1141 throw omni_thread_invalid();
1143 return new omni_thread_dummy;
1147 omni_thread::release_dummy()
1149 omni_thread* self = omni_thread::self();
1150 if (!self || !self->_dummy)
1151 throw omni_thread_invalid();
1153 omni_thread_dummy* dummy = (omni_thread_dummy*)self;
1158 #define INSIDE_THREAD_IMPL_CC
1159 #include "threaddata.cc"
1160 #undef INSIDE_THREAD_IMPL_CC