X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=blobdiff_plain;f=tos%2Flib%2Ftosthreads%2Fsystem%2FBlockingAMSenderImplP.nc;h=c519e64cf9d58e44f305de12c607602e02cd5fea;hp=539e074813fd0915428ba034b8db3142859ac64d;hb=e9bfab607e051bae6afb47b44892ce37541d1b44;hpb=adf1de6c009d13b7b52e68535c63b28f59c97400 diff --git a/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc b/tos/lib/tosthreads/system/BlockingAMSenderImplP.nc index 539e0748..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,13 +102,17 @@ 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 SUCCESS; + return FAIL; } }