|
|
|
@ -27,7 +27,7 @@
|
|
|
|
|
//#define ENABLE_DEBUG
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
|
|
static int queue_msg(tcb *target, msg *m) {
|
|
|
|
|
static int queue_msg(tcb *target, msg_t *m) {
|
|
|
|
|
int n = cib_put(&(target->msg_queue));
|
|
|
|
|
|
|
|
|
|
if (n != -1) {
|
|
|
|
@ -38,7 +38,7 @@ static int queue_msg(tcb *target, msg *m) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_send(msg* m, unsigned int target_pid, bool block) {
|
|
|
|
|
int msg_send(msg_t* m, unsigned int target_pid, bool block) {
|
|
|
|
|
if (inISR()) {
|
|
|
|
|
return msg_send_int(m, target_pid);
|
|
|
|
|
}
|
|
|
|
@ -90,7 +90,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) {
|
|
|
|
|
} else {
|
|
|
|
|
DEBUG("%s: direct msg copy.\n", active_thread->name);
|
|
|
|
|
/* copy msg to target */
|
|
|
|
|
msg* target_message = (msg*)target->wait_data;
|
|
|
|
|
msg_t* target_message = (msg_t*)target->wait_data;
|
|
|
|
|
*target_message = *m;
|
|
|
|
|
sched_set_status(target, STATUS_PENDING);
|
|
|
|
|
}
|
|
|
|
@ -101,7 +101,7 @@ int msg_send(msg* m, unsigned int target_pid, bool block) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_send_int(msg* m, unsigned int target_pid) {
|
|
|
|
|
int msg_send_int(msg_t* m, unsigned int target_pid) {
|
|
|
|
|
tcb *target = (tcb*)sched_threads[target_pid];
|
|
|
|
|
|
|
|
|
|
if (target->status == STATUS_RECEIVE_BLOCKED) {
|
|
|
|
@ -110,7 +110,7 @@ int msg_send_int(msg* m, unsigned int target_pid) {
|
|
|
|
|
m->sender_pid = target_pid;
|
|
|
|
|
|
|
|
|
|
/* copy msg to target */
|
|
|
|
|
msg* target_message = (msg*)target->wait_data;
|
|
|
|
|
msg_t* target_message = (msg_t*)target->wait_data;
|
|
|
|
|
*target_message = *m;
|
|
|
|
|
sched_set_status(target, STATUS_PENDING);
|
|
|
|
|
|
|
|
|
@ -122,7 +122,7 @@ int msg_send_int(msg* m, unsigned int target_pid) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) {
|
|
|
|
|
int msg_send_receive(msg_t *m, msg_t *reply, unsigned int target_pid) {
|
|
|
|
|
dINT();
|
|
|
|
|
tcb *me = (tcb*) sched_threads[thread_pid];
|
|
|
|
|
sched_set_status(me, STATUS_REPLY_BLOCKED);
|
|
|
|
@ -134,7 +134,7 @@ int msg_send_receive(msg *m, msg *reply, unsigned int target_pid) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_reply(msg *m, msg *reply) {
|
|
|
|
|
int msg_reply(msg_t *m, msg_t *reply) {
|
|
|
|
|
int state = disableIRQ();
|
|
|
|
|
|
|
|
|
|
tcb *target = (tcb*)sched_threads[m->sender_pid];
|
|
|
|
@ -146,7 +146,7 @@ int msg_reply(msg *m, msg *reply) {
|
|
|
|
|
|
|
|
|
|
DEBUG("%s: msg_reply(): direct msg copy.\n", active_thread->name);
|
|
|
|
|
/* copy msg to target */
|
|
|
|
|
msg* target_message = (msg*)target->wait_data;
|
|
|
|
|
msg_t* target_message = (msg_t*)target->wait_data;
|
|
|
|
|
*target_message = *reply;
|
|
|
|
|
sched_set_status(target, STATUS_PENDING);
|
|
|
|
|
restoreIRQ(state);
|
|
|
|
@ -155,20 +155,20 @@ int msg_reply(msg *m, msg *reply) {
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_reply_int(msg *m, msg *reply) {
|
|
|
|
|
int msg_reply_int(msg_t *m, msg_t *reply) {
|
|
|
|
|
tcb *target = (tcb*)sched_threads[m->sender_pid];
|
|
|
|
|
if (target->status != STATUS_REPLY_BLOCKED) {
|
|
|
|
|
DEBUG("%s: msg_reply_int(): target \"%s\" not waiting for reply.", active_thread->name, target->name);
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
msg* target_message = (msg*)target->wait_data;
|
|
|
|
|
msg_t* target_message = (msg_t*)target->wait_data;
|
|
|
|
|
*target_message = *reply;
|
|
|
|
|
sched_set_status(target, STATUS_PENDING);
|
|
|
|
|
sched_context_switch_request = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_receive(msg* m) {
|
|
|
|
|
int msg_receive(msg_t* m) {
|
|
|
|
|
dINT();
|
|
|
|
|
DEBUG("%s: msg_receive.\n", active_thread->name);
|
|
|
|
|
|
|
|
|
@ -212,7 +212,7 @@ int msg_receive(msg* m) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy msg */
|
|
|
|
|
msg* sender_msg = (msg*)sender->wait_data;
|
|
|
|
|
msg_t* sender_msg = (msg_t*)sender->wait_data;
|
|
|
|
|
*m = *sender_msg;
|
|
|
|
|
|
|
|
|
|
/* remove sender from queue */
|
|
|
|
@ -224,7 +224,7 @@ int msg_receive(msg* m) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int msg_init_queue(msg* array, int num) {
|
|
|
|
|
int msg_init_queue(msg_t* array, int num) {
|
|
|
|
|
/* make sure brainfuck condition is met */
|
|
|
|
|
if (num && (num & (num - 1)) == 0) {
|
|
|
|
|
tcb *me = (tcb*)active_thread;
|
|
|
|
|