@ -60,7 +60,7 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
tcb_t * target = ( tcb_t * ) sched_threads [ target_pid ] ;
m - > sender_pid = thread _pid;
m - > sender_pid = sched_active _pid;
if ( m - > sender_pid = = target_pid ) {
return msg_send_to_self ( m ) ;
@ -72,51 +72,51 @@ int msg_send(msg_t *m, unsigned int target_pid, bool block)
dINT ( ) ;
DEBUG ( " msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i \n " , __FILE__ , __LINE__ , thread _pid, target_pid , block , active_thread- > status , target - > status ) ;
DEBUG ( " msg_send() %s:%i: Sending from %i to %i. block=%i src->state=%i target->state=%i \n " , __FILE__ , __LINE__ , sched_active _pid, target_pid , block , sched_ active_thread- > status , target - > status ) ;
if ( target - > status ! = STATUS_RECEIVE_BLOCKED ) {
DEBUG ( " msg_send() %s:%i: Target %i is not RECEIVE_BLOCKED. \n " , __FILE__ , __LINE__ , target_pid ) ;
if ( target - > msg_array & & queue_msg ( target , m ) ) {
DEBUG ( " msg_send() %s:%i: Target %i has a msg_queue. Queueing message. \n " , __FILE__ , __LINE__ , target_pid ) ;
eINT ( ) ;
if ( active_thread- > status = = STATUS_REPLY_BLOCKED ) {
if ( sched_ active_thread- > status = = STATUS_REPLY_BLOCKED ) {
thread_yield ( ) ;
}
return 1 ;
}
if ( ! block ) {
DEBUG ( " msg_send: %s: Receiver not waiting, block=%u \n " , active_thread- > name , block ) ;
DEBUG ( " msg_send: %s: Receiver not waiting, block=%u \n " , sched_ active_thread- > name , block ) ;
eINT ( ) ;
return 0 ;
}
DEBUG ( " msg_send: %s: send_blocked. \n " , active_thread- > name ) ;
DEBUG ( " msg_send: %s: send_blocked. \n " , sched_ active_thread- > name ) ;
queue_node_t n ;
n . priority = active_thread- > priority ;
n . data = ( unsigned int ) active_thread;
n . priority = sched_ active_thread- > priority ;
n . data = ( unsigned int ) sched_ active_thread;
n . next = NULL ;
DEBUG ( " msg_send: %s: Adding node to msg_waiters: \n " , active_thread- > name ) ;
DEBUG ( " msg_send: %s: Adding node to msg_waiters: \n " , sched_ active_thread- > name ) ;
queue_priority_add ( & ( target - > msg_waiters ) , & n ) ;
active_thread- > wait_data = ( void * ) m ;
sched_ active_thread- > wait_data = ( void * ) m ;
int newstatus ;
if ( active_thread- > status = = STATUS_REPLY_BLOCKED ) {
if ( sched_ active_thread- > status = = STATUS_REPLY_BLOCKED ) {
newstatus = STATUS_REPLY_BLOCKED ;
}
else {
newstatus = STATUS_SEND_BLOCKED ;
}
sched_set_status ( ( tcb_t * ) active_thread, newstatus ) ;
sched_set_status ( ( tcb_t * ) sched_ active_thread, newstatus ) ;
DEBUG ( " msg_send: %s: Back from send block. \n " , active_thread- > name ) ;
DEBUG ( " msg_send: %s: Back from send block. \n " , sched_ active_thread- > name ) ;
}
else {
DEBUG ( " msg_send: %s: Direct msg copy from %i to %i. \n " , active_thread- > name , thread_getpid ( ) , target_pid ) ;
DEBUG ( " msg_send: %s: Direct msg copy from %i to %i. \n " , sched_ active_thread- > name , thread_getpid ( ) , target_pid ) ;
/* copy msg to target */
msg_t * target_message = ( msg_t * ) target - > wait_data ;
* target_message = * m ;
@ -133,7 +133,7 @@ int msg_send_to_self(msg_t *m)
{
unsigned int state = disableIRQ ( ) ;
int res = queue_msg ( ( tcb_t * ) active_thread, m ) ;
int res = queue_msg ( ( tcb_t * ) sched_ active_thread, m ) ;
restoreIRQ ( state ) ;
return res ;
@ -165,7 +165,7 @@ int msg_send_int(msg_t *m, unsigned int target_pid)
int msg_send_receive ( msg_t * m , msg_t * reply , unsigned int target_pid )
{
dINT ( ) ;
tcb_t * me = ( tcb_t * ) sched_threads [ thread _pid] ;
tcb_t * me = ( tcb_t * ) sched_threads [ sched_active _pid] ;
sched_set_status ( me , STATUS_REPLY_BLOCKED ) ;
me - > wait_data = ( void * ) reply ;
@ -181,17 +181,17 @@ int msg_reply(msg_t *m, msg_t *reply)
tcb_t * target = ( tcb_t * ) sched_threads [ m - > sender_pid ] ;
if ( ! target ) {
DEBUG ( " msg_reply(): %s: Target \" % " PRIu16 " \" not existing...dropping msg! \n " , active_thread- > name , m - > sender_pid ) ;
DEBUG ( " msg_reply(): %s: Target \" % " PRIu16 " \" not existing...dropping msg! \n " , sched_ active_thread- > name , m - > sender_pid ) ;
return - 1 ;
}
if ( target - > status ! = STATUS_REPLY_BLOCKED ) {
DEBUG ( " msg_reply(): %s: Target \" %s \" not waiting for reply. " , active_thread- > name , target - > name ) ;
DEBUG ( " msg_reply(): %s: Target \" %s \" not waiting for reply. " , sched_ active_thread- > name , target - > name ) ;
restoreIRQ ( state ) ;
return - 1 ;
}
DEBUG ( " msg_reply(): %s: Direct msg copy. \n " , active_thread- > name ) ;
DEBUG ( " msg_reply(): %s: Direct msg copy. \n " , sched_ active_thread- > name ) ;
/* copy msg to target */
msg_t * target_message = ( msg_t * ) target - > wait_data ;
* target_message = * reply ;
@ -207,7 +207,7 @@ int msg_reply_int(msg_t *m, msg_t *reply)
tcb_t * target = ( tcb_t * ) sched_threads [ m - > sender_pid ] ;
if ( target - > status ! = STATUS_REPLY_BLOCKED ) {
DEBUG ( " msg_reply_int(): %s: Target \" %s \" not waiting for reply. " , active_thread- > name , target - > name ) ;
DEBUG ( " msg_reply_int(): %s: Target \" %s \" not waiting for reply. " , sched_ active_thread- > name , target - > name ) ;
return - 1 ;
}
@ -231,9 +231,9 @@ int msg_receive(msg_t *m)
static int _msg_receive ( msg_t * m , int block )
{
dINT ( ) ;
DEBUG ( " _msg_receive: %s: _msg_receive. \n " , active_thread- > name ) ;
DEBUG ( " _msg_receive: %s: _msg_receive. \n " , sched_ active_thread- > name ) ;
tcb_t * me = ( tcb_t * ) sched_threads [ thread _pid] ;
tcb_t * me = ( tcb_t * ) sched_threads [ sched_active _pid] ;
int queue_index = - 1 ;
@ -247,7 +247,7 @@ static int _msg_receive(msg_t *m, int block)
}
if ( queue_index > = 0 ) {
DEBUG ( " _msg_receive: %s: _msg_receive(): We've got a queued message. \n " , active_thread- > name ) ;
DEBUG ( " _msg_receive: %s: _msg_receive(): We've got a queued message. \n " , sched_ active_thread- > name ) ;
* m = me - > msg_array [ queue_index ] ;
}
else {
@ -257,10 +257,10 @@ static int _msg_receive(msg_t *m, int block)
queue_node_t * node = queue_remove_head ( & ( me - > msg_waiters ) ) ;
if ( node = = NULL ) {
DEBUG ( " _msg_receive: %s: _msg_receive(): No thread in waiting list. \n " , active_thread- > name ) ;
DEBUG ( " _msg_receive: %s: _msg_receive(): No thread in waiting list. \n " , sched_ active_thread- > name ) ;
if ( queue_index < 0 ) {
DEBUG ( " _msg_receive(): %s: No msg in queue. Going blocked. \n " , active_thread- > name ) ;
DEBUG ( " _msg_receive(): %s: No msg in queue. Going blocked. \n " , sched_ active_thread- > name ) ;
sched_set_status ( me , STATUS_RECEIVE_BLOCKED ) ;
eINT ( ) ;
@ -272,7 +272,7 @@ static int _msg_receive(msg_t *m, int block)
return 1 ;
}
else {
DEBUG ( " _msg_receive: %s: _msg_receive(): Waking up waiting thread. \n " , active_thread- > name ) ;
DEBUG ( " _msg_receive: %s: _msg_receive(): Waking up waiting thread. \n " , sched_ active_thread- > name ) ;
tcb_t * sender = ( tcb_t * ) node - > data ;
if ( queue_index > = 0 ) {
@ -301,7 +301,7 @@ int msg_init_queue(msg_t *array, int num)
{
/* check if num is a power of two by comparing to its complement */
if ( num & & ( num & ( num - 1 ) ) = = 0 ) {
tcb_t * me = ( tcb_t * ) active_thread;
tcb_t * me = ( tcb_t * ) sched_ active_thread;
me - > msg_array = array ;
cib_init ( & ( me - > msg_queue ) , num ) ;
return 0 ;