From: liang_mike Date: Tue, 10 Feb 2009 03:36:07 +0000 (+0000) Subject: Check the AM ID to make sure the sendDone event should be signaled (it could be for... X-Git-Tag: rc_6_tinyos_2_1_1~495 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=7bdc0ee50a5686962aad9946df47835c61d37f48 Check the AM ID to make sure the sendDone event should be signaled (it could be for the TinyOS services) --- diff --git a/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc b/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc index c39a0f9c..c519e64c 100644 --- a/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc +++ b/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc @@ -31,6 +31,7 @@ /** * @author Kevin Klues (klueska@cs.stanford.edu) + * @author Chieh-Jan Mike Liang */ generic module BlockingAMSenderImplP() { @@ -55,7 +56,7 @@ implementation { error_t error; } params_t; - syscall_t* send_call; + syscall_t* send_call = NULL; mutex_t my_mutex; void sendTask(syscall_t* s) { @@ -74,13 +75,18 @@ implementation { syscall_t s; params_t p; call Mutex.lock(&my_mutex); - send_call = &s; - - p.addr = addr; - p.msg = msg; - p.len = len; - - call SystemCall.start(&sendTask, &s, am_id, &p); + if (send_call == NULL) { + send_call = &s; + + p.addr = addr; + p.msg = msg; + p.len = len; + + call SystemCall.start(&sendTask, &s, am_id, &p); + send_call = NULL; + } else { + p.error = EBUSY; + } atomic { call Mutex.unlock(&my_mutex); @@ -96,10 +102,14 @@ implementation { } event void AMSend.sendDone[am_id_t am_id](message_t* m, error_t error) { - params_t* p; - p = send_call->params; - p->error = error; - call SystemCall.finish(send_call); + if (send_call != NULL) { + if (send_call->id == am_id) { + params_t* p; + p = send_call->params; + p->error = error; + call SystemCall.finish(send_call); + } + } } default command error_t AMSend.send[am_id_t id](am_addr_t addr, message_t* msg, uint8_t len) { return FAIL;