mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-17 04:52:59 +01:00
core/msg: split msg_send_int() into helper function
So it can be re-used for the message bus.
This commit is contained in:
parent
0beb48a286
commit
866c37c6b0
30
core/msg.c
30
core/msg.c
@ -95,7 +95,7 @@ static int _msg_send(msg_t *m, kernel_pid_t target_pid, bool block,
|
||||
m->sender_pid = sched_active_pid;
|
||||
|
||||
if (target == NULL) {
|
||||
DEBUG("msg_send(): target thread does not exist\n");
|
||||
DEBUG("msg_send(): target thread %d does not exist\n", target_pid);
|
||||
irq_restore(state);
|
||||
return -1;
|
||||
}
|
||||
@ -187,41 +187,51 @@ int msg_send_to_self(msg_t *m)
|
||||
return res;
|
||||
}
|
||||
|
||||
int msg_send_int(msg_t *m, kernel_pid_t target_pid)
|
||||
static int _msg_send_oneway(msg_t *m, kernel_pid_t target_pid)
|
||||
{
|
||||
#ifdef DEVELHELP
|
||||
if (!pid_is_valid(target_pid)) {
|
||||
DEBUG("msg_send(): target_pid is invalid, continuing anyways\n");
|
||||
DEBUG("%s: target_pid is invalid, continuing anyways\n", __func__);
|
||||
}
|
||||
#endif /* DEVELHELP */
|
||||
|
||||
thread_t *target = (thread_t *)sched_threads[target_pid];
|
||||
|
||||
if (target == NULL) {
|
||||
DEBUG("msg_send_int(): target thread does not exist\n");
|
||||
DEBUG("%s: target thread %d does not exist\n", __func__, target_pid);
|
||||
return -1;
|
||||
}
|
||||
|
||||
m->sender_pid = KERNEL_PID_ISR;
|
||||
if (target->status == STATUS_RECEIVE_BLOCKED) {
|
||||
DEBUG("msg_send_int: Direct msg copy from %" PRIkernel_pid " to %"
|
||||
PRIkernel_pid ".\n", thread_getpid(), target_pid);
|
||||
|
||||
DEBUG("%s: Direct msg copy from %" PRIkernel_pid " to %"
|
||||
PRIkernel_pid ".\n", __func__, thread_getpid(), target_pid);
|
||||
|
||||
/* copy msg to target */
|
||||
msg_t *target_message = (msg_t *)target->wait_data;
|
||||
*target_message = *m;
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
|
||||
sched_set_status(target, STATUS_PENDING);
|
||||
sched_context_switch_request = 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
DEBUG("msg_send_int: Receiver not waiting.\n");
|
||||
DEBUG("%s: Receiver not waiting.\n", __func__);
|
||||
return (queue_msg(target, m));
|
||||
}
|
||||
}
|
||||
|
||||
int msg_send_int(msg_t *m, kernel_pid_t target_pid)
|
||||
{
|
||||
int res;
|
||||
|
||||
m->sender_pid = KERNEL_PID_ISR;
|
||||
|
||||
res = _msg_send_oneway(m, target_pid);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int msg_send_receive(msg_t *m, msg_t *reply, kernel_pid_t target_pid)
|
||||
{
|
||||
assert(sched_active_pid != target_pid);
|
||||
|
Loading…
Reference in New Issue
Block a user