From: klueska Date: Mon, 6 Oct 2008 04:40:02 +0000 (+0000) Subject: Added thread_join functions and fixed the @spontaneous stuff to not create functions... X-Git-Tag: rc_6_tinyos_2_1_1~595 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=4f00f40a7c40b8ba3493abc904f895aeba5d7a09 Added thread_join functions and fixed the @spontaneous stuff to not create functions unless they are bing deployed as part of a kernel and are not called anywhere --- diff --git a/tos/lib/tosthreads/csystem/CAMRadioP.nc b/tos/lib/tosthreads/csystem/CAMRadioP.nc index f9d12e12..bfe3efe0 100644 --- a/tos/lib/tosthreads/csystem/CAMRadioP.nc +++ b/tos/lib/tosthreads/csystem/CAMRadioP.nc @@ -38,82 +38,82 @@ module CAMRadioP { } } implementation { - error_t amRadioStart() @C() @spontaneous() { + error_t amRadioStart() @C() AT_SPONTANEOUS { return call BlockingStdControl.start(); } - error_t amRadioStop() @C() @spontaneous() { + error_t amRadioStop() @C() AT_SPONTANEOUS { return call BlockingStdControl.stop(); } - error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() { + error_t amRadioReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS { if(amId == AM_RECEIVE_FROM_ANY) return call BlockingReceiveAny.receive(m, timeout); else return call BlockingReceive.receive[amId](m, timeout); } - error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() { + error_t amRadioSnoop(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS { if(amId == AM_RECEIVE_FROM_ANY) return call BlockingSnoopAny.receive(m, timeout); else return call BlockingSnoop.receive[amId](m, timeout); } - error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() { + error_t amRadioSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() AT_SPONTANEOUS { return call Send.send[amId](addr, msg, len); } - am_addr_t amRadioGetLocalAddress() @C() @spontaneous() { + am_addr_t amRadioGetLocalAddress() @C() AT_SPONTANEOUS { return call AMPacket.address(); } - am_group_t amRadioGetLocalGroup() @C() @spontaneous() { + am_group_t amRadioGetLocalGroup() @C() AT_SPONTANEOUS { return call AMPacket.localGroup(); } - am_addr_t amRadioGetDestination(message_t* amsg) @C() @spontaneous() { + am_addr_t amRadioGetDestination(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.destination(amsg); } - am_addr_t amRadioGetSource(message_t* amsg) @C() @spontaneous() { + am_addr_t amRadioGetSource(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.source(amsg); } - void amRadioSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() { + void amRadioSetDestination(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS { call AMPacket.setDestination(amsg, addr); } - void amRadioSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() { + void amRadioSetSource(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS { call AMPacket.setSource(amsg, addr); } - bool amRadioIsForMe(message_t* amsg) @C() @spontaneous() { + bool amRadioIsForMe(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.isForMe(amsg); } - am_id_t amRadioGetType(message_t* amsg) @C() @spontaneous() { + am_id_t amRadioGetType(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.type(amsg); } - void amRadioSetType(message_t* amsg, am_id_t t) @C() @spontaneous() { + void amRadioSetType(message_t* amsg, am_id_t t) @C() AT_SPONTANEOUS { call AMPacket.setType(amsg, t); } - am_group_t amRadioGetGroup(message_t* amsg) @C() @spontaneous() { + am_group_t amRadioGetGroup(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.group(amsg); } - void amRadioSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() { + void amRadioSetGroup(message_t* amsg, am_group_t grp) @C() AT_SPONTANEOUS { call AMPacket.setGroup(amsg, grp); } - void radioClear(message_t* msg) @C() @spontaneous() { + void radioClear(message_t* msg) @C() AT_SPONTANEOUS { call Packet.clear(msg); } - uint8_t radioGetPayloadLength(message_t* msg) @C() @spontaneous() { + uint8_t radioGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS { return call Packet.payloadLength(msg); } - void radioSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() { + void radioSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { call Packet.setPayloadLength(msg, len); } - uint8_t radioMaxPayloadLength() @C() @spontaneous() { + uint8_t radioMaxPayloadLength() @C() AT_SPONTANEOUS { return call Packet.maxPayloadLength(); } - void* radioGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() { + void* radioGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { return call Packet.getPayload(msg, len); } - error_t radioRequestAck( message_t* msg ) @C() @spontaneous() { + error_t radioRequestAck( message_t* msg ) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.requestAck(msg); } - error_t radioNoAck( message_t* msg ) @C() @spontaneous() { + error_t radioNoAck( message_t* msg ) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.noAck(msg); } - bool radioWasAcked(message_t* msg) @C() @spontaneous() { + bool radioWasAcked(message_t* msg) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.wasAcked(msg); } } diff --git a/tos/lib/tosthreads/csystem/CAMSerialP.nc b/tos/lib/tosthreads/csystem/CAMSerialP.nc index c0a7bba9..dee9b384 100644 --- a/tos/lib/tosthreads/csystem/CAMSerialP.nc +++ b/tos/lib/tosthreads/csystem/CAMSerialP.nc @@ -36,76 +36,76 @@ module CAMSerialP { } } implementation { - error_t amSerialStart() @C() @spontaneous() { + error_t amSerialStart() @C() AT_SPONTANEOUS { return call BlockingStdControl.start(); } - error_t amSerialStop() @C() @spontaneous() { + error_t amSerialStop() @C() AT_SPONTANEOUS { return call BlockingStdControl.stop(); } - error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() @spontaneous() { + error_t amSerialReceive(message_t* m, uint32_t timeout, am_id_t amId) @C() AT_SPONTANEOUS { if(amId == AM_RECEIVE_FROM_ANY) return call BlockingReceiveAny.receive(m, timeout); else return call BlockingReceive.receive[amId](m, timeout); } - error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() @spontaneous() { + error_t amSerialSend(am_addr_t addr, message_t* msg, uint8_t len, am_id_t amId) @C() AT_SPONTANEOUS { return call Send.send[amId](addr, msg, len); } - am_addr_t amSerialLocalAddress() @C() @spontaneous() { + am_addr_t amSerialLocalAddress() @C() AT_SPONTANEOUS { return call AMPacket.address(); } - am_group_t amSerialGetLocalGroup() @C() @spontaneous() { + am_group_t amSerialGetLocalGroup() @C() AT_SPONTANEOUS { return call AMPacket.localGroup(); } - am_addr_t amSerialGetDestination(message_t* amsg) @C() @spontaneous() { + am_addr_t amSerialGetDestination(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.destination(amsg); } - am_addr_t amSerialGetSource(message_t* amsg) @C() @spontaneous() { + am_addr_t amSerialGetSource(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.source(amsg); } - void amSerialSetDestination(message_t* amsg, am_addr_t addr) @C() @spontaneous() { + void amSerialSetDestination(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS { call AMPacket.setDestination(amsg, addr); } - void amSerialSetSource(message_t* amsg, am_addr_t addr) @C() @spontaneous() { + void amSerialSetSource(message_t* amsg, am_addr_t addr) @C() AT_SPONTANEOUS { call AMPacket.setSource(amsg, addr); } - bool amSerialIsForMe(message_t* amsg) @C() @spontaneous() { + bool amSerialIsForMe(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.isForMe(amsg); } - am_id_t amSerialGetType(message_t* amsg) @C() @spontaneous() { + am_id_t amSerialGetType(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.type(amsg); } - void amSerialSetType(message_t* amsg, am_id_t t) @C() @spontaneous() { + void amSerialSetType(message_t* amsg, am_id_t t) @C() AT_SPONTANEOUS { call AMPacket.setType(amsg, t); } - am_group_t amSerialGetGroup(message_t* amsg) @C() @spontaneous() { + am_group_t amSerialGetGroup(message_t* amsg) @C() AT_SPONTANEOUS { return call AMPacket.group(amsg); } - void amSerialSetGroup(message_t* amsg, am_group_t grp) @C() @spontaneous() { + void amSerialSetGroup(message_t* amsg, am_group_t grp) @C() AT_SPONTANEOUS { call AMPacket.setGroup(amsg, grp); } - void serialClear(message_t* msg) @C() @spontaneous() { + void serialClear(message_t* msg) @C() AT_SPONTANEOUS { call Packet.clear(msg); } - uint8_t serialGetPayloadLength(message_t* msg) @C() @spontaneous() { + uint8_t serialGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS { return call Packet.payloadLength(msg); } - void serialSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() { + void serialSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { call Packet.setPayloadLength(msg, len); } - uint8_t serialMaxPayloadLength() @C() @spontaneous() { + uint8_t serialMaxPayloadLength() @C() AT_SPONTANEOUS { return call Packet.maxPayloadLength(); } - void* serialGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() { + void* serialGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { return call Packet.getPayload(msg, len); } - error_t serialRequestAck( message_t* msg ) @C() @spontaneous() { + error_t serialRequestAck( message_t* msg ) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.requestAck(msg); } - error_t serialNoAck( message_t* msg ) @C() @spontaneous() { + error_t serialNoAck( message_t* msg ) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.noAck(msg); } - bool serialWasAcked(message_t* msg) @C() @spontaneous() { + bool serialWasAcked(message_t* msg) @C() AT_SPONTANEOUS { return call PacketAcknowledgements.wasAcked(msg); } } diff --git a/tos/lib/tosthreads/csystem/CBlockStorageP.nc b/tos/lib/tosthreads/csystem/CBlockStorageP.nc index 82817dcb..1c3a4bb6 100644 --- a/tos/lib/tosthreads/csystem/CBlockStorageP.nc +++ b/tos/lib/tosthreads/csystem/CBlockStorageP.nc @@ -31,27 +31,27 @@ module CBlockStorageP { } implementation { - error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() @spontaneous() + error_t volumeBlockRead(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS { return call BlockingBlock.read[volumeId](addr, buf, len); } - error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() @spontaneous() + error_t volumeBlockWrite(uint8_t volumeId, storage_addr_t addr, void* buf, storage_len_t* len) @C() AT_SPONTANEOUS { return call BlockingBlock.write[volumeId](addr, buf, len); } - error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) @C() @spontaneous() + error_t volumeBlockCrc(uint8_t volumeId, storage_addr_t addr, storage_len_t* len, uint16_t crc, uint16_t *finalCrc) @C() AT_SPONTANEOUS { return call BlockingBlock.computeCrc[volumeId](addr, len, crc, finalCrc); } - error_t volumeBlockErase(uint8_t volumeId) @C() @spontaneous() + error_t volumeBlockErase(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingBlock.erase[volumeId](); } - error_t volumeBlockSync(uint8_t volumeId) @C() @spontaneous() + error_t volumeBlockSync(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingBlock.sync[volumeId](); } diff --git a/tos/lib/tosthreads/csystem/CLedsP.nc b/tos/lib/tosthreads/csystem/CLedsP.nc index cf1944eb..63fa4773 100644 --- a/tos/lib/tosthreads/csystem/CLedsP.nc +++ b/tos/lib/tosthreads/csystem/CLedsP.nc @@ -39,40 +39,40 @@ module CLedsP { } } implementation { - void led0On() @C() @spontaneous(){ + void led0On() @C() AT_SPONTANEOUS { call Leds.led0On(); } - void led0Off() @C() @spontaneous(){ + void led0Off() @C() AT_SPONTANEOUS { call Leds.led0Off(); } - void led0Toggle() @C() @spontaneous(){ + void led0Toggle() @C() AT_SPONTANEOUS{ call Leds.led0Toggle(); } - void led1On() @C() @spontaneous(){ + void led1On() @C() AT_SPONTANEOUS{ call Leds.led1On(); } - void led1Off() @C() @spontaneous(){ + void led1Off() @C() AT_SPONTANEOUS{ call Leds.led1Off(); } - void led1Toggle() @C() @spontaneous(){ + void led1Toggle() @C() AT_SPONTANEOUS{ call Leds.led1Toggle(); } - void led2On() @C() @spontaneous(){ + void led2On() @C() AT_SPONTANEOUS{ call Leds.led2On(); } - void led2Off() @C() @spontaneous(){ + void led2Off() @C() AT_SPONTANEOUS{ call Leds.led2Off(); } - void led2Toggle() @C() @spontaneous(){ + void led2Toggle() @C() AT_SPONTANEOUS{ call Leds.led2Toggle(); } - uint8_t getLeds() @C() @spontaneous(){ + uint8_t getLeds() @C() AT_SPONTANEOUS{ return call Leds.get(); } - void setLeds(uint8_t val) @C() @spontaneous(){ + void setLeds(uint8_t val) @C() AT_SPONTANEOUS{ call Leds.set(val); } } diff --git a/tos/lib/tosthreads/csystem/CLinkedListP.nc b/tos/lib/tosthreads/csystem/CLinkedListP.nc index 33d1cf7a..ec15e4e7 100644 --- a/tos/lib/tosthreads/csystem/CLinkedListP.nc +++ b/tos/lib/tosthreads/csystem/CLinkedListP.nc @@ -38,64 +38,64 @@ module CLinkedListP { uses interface LinkedList; } implementation { - void linked_list_init(linked_list_t* l) @C() @spontaneous() { + void linked_list_init(linked_list_t* l) @C() AT_SPONTANEOUS { call LinkedList.init(l); } - void linked_list_clear(linked_list_t* l) @C() @spontaneous() { + void linked_list_clear(linked_list_t* l) @C() AT_SPONTANEOUS { call LinkedList.clear(l); } - uint8_t linked_list_size(linked_list_t* l) @C() @spontaneous() { + uint8_t linked_list_size(linked_list_t* l) @C() AT_SPONTANEOUS { return call LinkedList.size(l); } - error_t linked_list_addFirst(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + error_t linked_list_addFirst(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.addFirst(l, e); } - list_element_t* linked_list_getFirst(linked_list_t* l) @C() @spontaneous() { + list_element_t* linked_list_getFirst(linked_list_t* l) @C() AT_SPONTANEOUS { return call LinkedList.getFirst(l); } - list_element_t* linked_list_removeFirst(linked_list_t* l) @C() @spontaneous() { + list_element_t* linked_list_removeFirst(linked_list_t* l) @C() AT_SPONTANEOUS { return call LinkedList.removeFirst(l); } - error_t linked_list_addLast(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + error_t linked_list_addLast(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.addLast(l, e); } - list_element_t* linked_list_getLast(linked_list_t* l) @C() @spontaneous() { + list_element_t* linked_list_getLast(linked_list_t* l) @C() AT_SPONTANEOUS { return call LinkedList.getLast(l); } - list_element_t* linked_list_removeLast(linked_list_t* l) @C() @spontaneous() { + list_element_t* linked_list_removeLast(linked_list_t* l) @C() AT_SPONTANEOUS { return call LinkedList.removeLast(l); } - error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i) @C() @spontaneous() { + error_t linked_list_addAt(linked_list_t* l, list_element_t* e, uint8_t i) @C() AT_SPONTANEOUS { return call LinkedList.addAt(l, e, i); } - list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i) @C() @spontaneous() { + list_element_t* linked_list_getAt(linked_list_t* l, uint8_t i) @C() AT_SPONTANEOUS { return call LinkedList.getAt(l, i); } - list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i) @C() @spontaneous() { + list_element_t* linked_list_removeAt(linked_list_t* l, uint8_t i) @C() AT_SPONTANEOUS { return call LinkedList.removeAt(l, i); } - error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) @C() @spontaneous() { + error_t linked_list_addAfter(linked_list_t* l, list_element_t* first, list_element_t* second) @C() AT_SPONTANEOUS { return call LinkedList.addAfter(l, first, second); } - error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) @C() @spontaneous() { + error_t linked_list_addBefore(linked_list_t* l, list_element_t* first, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.addBefore(l, first, e); } - list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + list_element_t* linked_list_getAfter(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.getAfter(l, e); } - list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + list_element_t* linked_list_getBefore(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.getBefore(l, e); } - list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + list_element_t* linked_list_remove(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.remove(l, e); } - list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + list_element_t* linked_list_removeBefore(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.removeBefore(l, e); } - list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + list_element_t* linked_list_removeAfter(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.removeAfter(l, e); } - uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e) @C() @spontaneous() { + uint8_t linked_list_indexOf(linked_list_t* l, list_element_t* e) @C() AT_SPONTANEOUS { return call LinkedList.indexOf(l, e); } } diff --git a/tos/lib/tosthreads/csystem/CLogStorageP.nc b/tos/lib/tosthreads/csystem/CLogStorageP.nc index 04f0db59..92638a7d 100644 --- a/tos/lib/tosthreads/csystem/CLogStorageP.nc +++ b/tos/lib/tosthreads/csystem/CLogStorageP.nc @@ -39,28 +39,28 @@ module CLogStorageP { } } implementation { - error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len) @C() @spontaneous() { + error_t volumeLogRead(uint8_t volumeId, void *buf, storage_len_t *len) @C() AT_SPONTANEOUS { return call BlockingLog.read[volumeId](buf, len); } - storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId) @C() @spontaneous() { + storage_cookie_t volumeLogCurrentReadOffset(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingLog.currentReadOffset[volumeId](); } - error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset) @C() @spontaneous() { + error_t volumeLogSeek(uint8_t volumeId, storage_cookie_t offset) @C() AT_SPONTANEOUS { return call BlockingLog.seek[volumeId](offset); } - storage_len_t volumeLogGetSize(uint8_t volumeId) @C() @spontaneous() { + storage_len_t volumeLogGetSize(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingLog.getSize[volumeId](); } - error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost) @C() @spontaneous() { + error_t volumeLogAppend(uint8_t volumeId, void* buf, storage_len_t *len, bool *recordsLost) @C() AT_SPONTANEOUS { return call BlockingLog.append[volumeId](buf, len, recordsLost); } - storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId) @C() @spontaneous() { + storage_cookie_t volumeLogCurrentWriteOffset(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingLog.currentWriteOffset[volumeId](); } - error_t volumeLogErase(uint8_t volumeId) @C() @spontaneous() { + error_t volumeLogErase(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingLog.erase[volumeId](); } - error_t volumeLogSync(uint8_t volumeId) @C() @spontaneous() { + error_t volumeLogSync(uint8_t volumeId) @C() AT_SPONTANEOUS { return call BlockingLog.sync[volumeId](); } } diff --git a/tos/lib/tosthreads/csystem/CQueueC.nc b/tos/lib/tosthreads/csystem/CQueueC.nc index 267c1c6d..6d958cbd 100644 --- a/tos/lib/tosthreads/csystem/CQueueC.nc +++ b/tos/lib/tosthreads/csystem/CQueueC.nc @@ -38,25 +38,25 @@ module CQueueC {} implementation { - void queue_init(queue_t* q) @C() @spontaneous() { + void queue_init(queue_t* q) @C() AT_SPONTANEOUS { linked_list_init( &(q->l) ); } - void queue_clear(queue_t* q) @C() @spontaneous() { + void queue_clear(queue_t* q) @C() AT_SPONTANEOUS { linked_list_clear( &(q->l) ); } - error_t queue_enqueue(queue_t* q, queue_element_t* e) @C() @spontaneous() { + error_t queue_enqueue(queue_t* q, queue_element_t* e) @C() AT_SPONTANEOUS { return linked_list_addLast(&(q->l), (list_element_t*)e); } - queue_element_t* queue_dequeue(queue_t* q) @C() @spontaneous() { + queue_element_t* queue_dequeue(queue_t* q) @C() AT_SPONTANEOUS { return (queue_element_t*)linked_list_removeFirst( &(q->l) ); } - queue_element_t* queue_remove(queue_t* q, queue_element_t* e) @C() @spontaneous() { + queue_element_t* queue_remove(queue_t* q, queue_element_t* e) @C() AT_SPONTANEOUS { return (queue_element_t*)linked_list_remove(&(q->l), (list_element_t*)e); } - uint8_t queue_size(queue_t* q) @C() @spontaneous() { + uint8_t queue_size(queue_t* q) @C() AT_SPONTANEOUS { return linked_list_size( &(q->l) ); } - bool queue_is_empty(queue_t* q) @C() @spontaneous() { + bool queue_is_empty(queue_t* q) @C() AT_SPONTANEOUS { return (linked_list_size( &(q->l) ) == 0); } } diff --git a/tos/lib/tosthreads/csystem/CThreadP.nc b/tos/lib/tosthreads/csystem/CThreadP.nc index 52f16013..18026f17 100644 --- a/tos/lib/tosthreads/csystem/CThreadP.nc +++ b/tos/lib/tosthreads/csystem/CThreadP.nc @@ -42,19 +42,22 @@ module CThreadP { } implementation { - error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) @C() @spontaneous() { + error_t tosthread_create(tosthread_t* t, void (*start_routine)(void*), void* arg, uint16_t stack_size) @C() AT_SPONTANEOUS { return call DynamicThread.create(t, start_routine, arg, stack_size); } - error_t tosthread_destroy(tosthread_t* t) @C() @spontaneous() { + error_t tosthread_destroy(tosthread_t* t) @C() AT_SPONTANEOUS { return call DynamicThread.destroy(t); } - error_t tosthread_pause(tosthread_t* t) @C() @spontaneous() { + error_t tosthread_pause(tosthread_t* t) @C() AT_SPONTANEOUS { return call DynamicThread.pause(t); } - error_t tosthread_resume(tosthread_t* t) @C() @spontaneous() { + error_t tosthread_resume(tosthread_t* t) @C() AT_SPONTANEOUS { return call DynamicThread.resume(t); } - error_t tosthread_sleep(uint32_t milli) @C() @spontaneous() { + error_t tosthread_sleep(uint32_t milli) @C() AT_SPONTANEOUS { return call DynamicThread.sleep(milli); } + error_t tosthread_join(tosthread_t* t) @C() AT_SPONTANEOUS { + return call DynamicThread.join(t); + } } diff --git a/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc b/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc index 952c48d1..a82b9e0e 100644 --- a/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc +++ b/tos/lib/tosthreads/csystem/CThreadSynchronizationP.nc @@ -44,69 +44,69 @@ module CThreadSynchronizationP { } implementation { /******************** Mutex ***************************/ - void mutex_init(mutex_t* m) @C() @spontaneous() { + void mutex_init(mutex_t* m) @C() AT_SPONTANEOUS { call Mutex.init(m); } - error_t mutex_lock(mutex_t* m) @C() @spontaneous() { + error_t mutex_lock(mutex_t* m) @C() AT_SPONTANEOUS { return call Mutex.lock(m); } - error_t mutex_unlock(mutex_t* m) @C() @spontaneous() { + error_t mutex_unlock(mutex_t* m) @C() AT_SPONTANEOUS { return call Mutex.unlock(m); } /******************** Semaphore ***************************/ - void semaphore_reset(semaphore_t* s, uint8_t v) @C() @spontaneous() { + void semaphore_reset(semaphore_t* s, uint8_t v) @C() AT_SPONTANEOUS { call Semaphore.reset(s, v); } - error_t semaphore_acquire(semaphore_t* s) @C() @spontaneous() { + error_t semaphore_acquire(semaphore_t* s) @C() AT_SPONTANEOUS { return call Semaphore.acquire(s); } - error_t semaphore_release(semaphore_t* s) @C() @spontaneous() { + error_t semaphore_release(semaphore_t* s) @C() AT_SPONTANEOUS { return call Semaphore.release(s); } /******************** Barrier ***************************/ - void barrier_reset(barrier_t* b, uint8_t count) @C() @spontaneous() { + void barrier_reset(barrier_t* b, uint8_t count) @C() AT_SPONTANEOUS { call Barrier.reset(b, count); } - void barrier_block(barrier_t* b) @C() @spontaneous() { + void barrier_block(barrier_t* b) @C() AT_SPONTANEOUS { call Barrier.block(b); } - bool barrier_isBlocking(barrier_t* b) @C() @spontaneous() { + bool barrier_isBlocking(barrier_t* b) @C() AT_SPONTANEOUS { return call Barrier.isBlocking(b); } - void condvar_init(condvar_t* c) @C() @spontaneous() { + void condvar_init(condvar_t* c) @C() AT_SPONTANEOUS { call ConditionVariable.init(c); } /******************** Condition Variable ***************************/ - void condvar_wait(condvar_t* c, mutex_t* m) @C() @spontaneous() { + void condvar_wait(condvar_t* c, mutex_t* m) @C() AT_SPONTANEOUS { call ConditionVariable.wait(c, m); } - void condvar_signalNext(condvar_t* c) @C() @spontaneous() { + void condvar_signalNext(condvar_t* c) @C() AT_SPONTANEOUS { call ConditionVariable.signalNext(c); } - void condvar_signalAll(condvar_t* c) @C() @spontaneous() { + void condvar_signalAll(condvar_t* c) @C() AT_SPONTANEOUS { call ConditionVariable.signalAll(c); } - bool condvar_isBlocking(condvar_t* c) @C() @spontaneous() { + bool condvar_isBlocking(condvar_t* c) @C() AT_SPONTANEOUS { return call ConditionVariable.isBlocking(c); } /******************** Reference Counter ***************************/ - void refcounter_init(refcounter_t* r) @C() @spontaneous() { + void refcounter_init(refcounter_t* r) @C() AT_SPONTANEOUS { call ReferenceCounter.init(r); } - void refcounter_increment(refcounter_t* r) @C() @spontaneous() { + void refcounter_increment(refcounter_t* r) @C() AT_SPONTANEOUS { call ReferenceCounter.increment(r); } - void refcounter_decrement(refcounter_t* r) @C() @spontaneous() { + void refcounter_decrement(refcounter_t* r) @C() AT_SPONTANEOUS { call ReferenceCounter.decrement(r); } - void refcounter_waitOnValue(refcounter_t* r, uint8_t count) @C() @spontaneous() { + void refcounter_waitOnValue(refcounter_t* r, uint8_t count) @C() AT_SPONTANEOUS { call ReferenceCounter.waitOnValue(r, count); } - uint8_t refcounter_count(refcounter_t* r) @C() @spontaneous() { + uint8_t refcounter_count(refcounter_t* r) @C() AT_SPONTANEOUS { return call ReferenceCounter.count(r); } } diff --git a/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc b/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc index d55f5a61..25befbd7 100644 --- a/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc +++ b/tos/lib/tosthreads/csystem/TinyOSEntryPointC.nc @@ -35,6 +35,12 @@ #include "tosthread.h" +#ifdef DYNTHREADS + #define AT_SPONTANEOUS @spontaneous() +#else + #define AT_SPONTANEOUS +#endif + configuration TinyOSEntryPointC { } implementation { diff --git a/tos/lib/tosthreads/csystem/tosthread.h b/tos/lib/tosthreads/csystem/tosthread.h index b032ad54..3c1551c9 100644 --- a/tos/lib/tosthreads/csystem/tosthread.h +++ b/tos/lib/tosthreads/csystem/tosthread.h @@ -120,4 +120,17 @@ extern error_t tosthread_resume(tosthread_t* t); */ extern error_t tosthread_sleep(uint32_t milli); +/** + * tosthread_join(tosthread_t* t) + * + * This function bocks until the thread passed as a parameter has completed + * + * @param id The handle to the thread to block on + * @return An error code indicating whether the thread could be waited on or not + * SUCCESS - The thread has been waited on and is now completed + * EALREADY - The thread we are trying to wait on has already completed + * FAIL - The thread could not waited on + */ +extern error_t tosthread_join(tosthread_t* id); + #endif //TOSTHREAD_H_INCLUDED diff --git a/tos/lib/tosthreads/interfaces/DynamicThread.nc b/tos/lib/tosthreads/interfaces/DynamicThread.nc index aea023c9..d3d26264 100644 --- a/tos/lib/tosthreads/interfaces/DynamicThread.nc +++ b/tos/lib/tosthreads/interfaces/DynamicThread.nc @@ -102,4 +102,17 @@ interface DynamicThread { * FAIL - The thread could not be put to sleep */ command error_t sleep(uint32_t milli); + + /** + * join(tosthread_t* t) + * + * This function bocks until the thread passed as a parameter has completed + * + * @param id The handle to the thread to block on + * @return An error code indicating whether the thread could be waited on or not + * SUCCESS - The thread has been waited on and is now completed + * EALREADY - The thread we are trying to wait on has already completed + * FAIL - The thread could not waited on + */ + command error_t join(tosthread_t* id); } diff --git a/tos/lib/tosthreads/interfaces/Thread.nc b/tos/lib/tosthreads/interfaces/Thread.nc index 15b93f6c..0fc2f460 100644 --- a/tos/lib/tosthreads/interfaces/Thread.nc +++ b/tos/lib/tosthreads/interfaces/Thread.nc @@ -40,4 +40,5 @@ interface Thread { command error_t resume(); command error_t sleep(uint32_t milli); event void run(void* arg); + command error_t join(); } diff --git a/tos/lib/tosthreads/interfaces/ThreadInfo.nc b/tos/lib/tosthreads/interfaces/ThreadInfo.nc index d98379fc..df244c1c 100644 --- a/tos/lib/tosthreads/interfaces/ThreadInfo.nc +++ b/tos/lib/tosthreads/interfaces/ThreadInfo.nc @@ -36,5 +36,6 @@ #include "thread.h" interface ThreadInfo { + async command error_t reset(); async command thread_t* get(); } diff --git a/tos/lib/tosthreads/interfaces/ThreadScheduler.nc b/tos/lib/tosthreads/interfaces/ThreadScheduler.nc index 08946080..c682d28a 100644 --- a/tos/lib/tosthreads/interfaces/ThreadScheduler.nc +++ b/tos/lib/tosthreads/interfaces/ThreadScheduler.nc @@ -48,4 +48,5 @@ interface ThreadScheduler { async command error_t interruptCurrentThread(); async command error_t wakeupThread(thread_id_t id); + async command error_t joinThread(thread_id_t id); } diff --git a/tos/lib/tosthreads/lib/net/ctp/CCollectionP.nc b/tos/lib/tosthreads/lib/net/ctp/CCollectionP.nc index 8b5fbdf2..5b7ee8a7 100644 --- a/tos/lib/tosthreads/lib/net/ctp/CCollectionP.nc +++ b/tos/lib/tosthreads/lib/net/ctp/CCollectionP.nc @@ -54,69 +54,69 @@ implementation { return call CCollectionId.fetch(id); } - error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() @spontaneous() { + error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() AT_SPONTANEOUS { return call CCollectionId.set(clientid, collectionid); } - error_t collectionRoutingStart() @C() @spontaneous() { + error_t collectionRoutingStart() @C() AT_SPONTANEOUS { return call RoutingControl.start(); } - error_t collectionRoutingStop() @C() @spontaneous() { + error_t collectionRoutingStop() @C() AT_SPONTANEOUS { return call RoutingControl.stop(); } - error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() { + error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS { return call BlockingReceive.receive[id](m, timeout); } - error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() { + error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS { return call BlockingSnoop.receive[id](m, timeout); } - error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() @spontaneous() { + error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() AT_SPONTANEOUS { return call BlockingSend.send[id](msg, len); } - void collectionClear(message_t* msg) @C() @spontaneous() { + void collectionClear(message_t* msg) @C() AT_SPONTANEOUS { call Packet.clear(msg); } - uint8_t collectionGetPayloadLength(message_t* msg) @C() @spontaneous() { + uint8_t collectionGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS { return call Packet.payloadLength(msg); } - void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() { + void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { call Packet.setPayloadLength(msg, len); } - uint8_t collectionMaxPayloadLength() @C() @spontaneous() { + uint8_t collectionMaxPayloadLength() @C() AT_SPONTANEOUS { return call Packet.maxPayloadLength(); } - void* collectionGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() { + void* collectionGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { return call Packet.getPayload(msg, len); } - am_addr_t collectionGetOrigin(message_t* msg) @C() @spontaneous() { + am_addr_t collectionGetOrigin(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getOrigin(msg); } - void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() @spontaneous() { + void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() AT_SPONTANEOUS { call CollectionPacket.setOrigin(msg, addr); } - collection_id_t collectionGetType(message_t* msg) @C() @spontaneous() { + collection_id_t collectionGetType(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getType(msg); } - void collectionSetType(message_t* msg, collection_id_t id) @C() @spontaneous() { + void collectionSetType(message_t* msg, collection_id_t id) @C() AT_SPONTANEOUS { call CollectionPacket.setType(msg, id); } - uint8_t collectionGetSequenceNumber(message_t* msg) @C() @spontaneous() { + uint8_t collectionGetSequenceNumber(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getSequenceNumber(msg); } - void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() @spontaneous() { + void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() AT_SPONTANEOUS { call CollectionPacket.setSequenceNumber(msg, seqno); } - error_t collectionSetRoot() @C() @spontaneous() { + error_t collectionSetRoot() @C() AT_SPONTANEOUS { return call RootControl.setRoot(); } - error_t collectionUnsetRoot() @C() @spontaneous() { + error_t collectionUnsetRoot() @C() AT_SPONTANEOUS { return call RootControl.unsetRoot(); } - bool collectionIsRoot() @C() @spontaneous() { + bool collectionIsRoot() @C() AT_SPONTANEOUS { return call RootControl.isRoot(); } } diff --git a/tos/lib/tosthreads/lib/net/lqi/CCollectionP.nc b/tos/lib/tosthreads/lib/net/lqi/CCollectionP.nc index 5782f23f..8d2b3d58 100644 --- a/tos/lib/tosthreads/lib/net/lqi/CCollectionP.nc +++ b/tos/lib/tosthreads/lib/net/lqi/CCollectionP.nc @@ -54,70 +54,70 @@ implementation { return call CCollectionId.fetch(id); } - error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() @spontaneous() { + error_t collectionSetCollectionId(uint8_t clientid, collection_id_t collectionid) @C() AT_SPONTANEOUS { return call CCollectionId.set(clientid, collectionid); } - error_t collectionRoutingStart() @C() @spontaneous() { + error_t collectionRoutingStart() @C() AT_SPONTANEOUS { return call RoutingControl.start(); } - error_t collectionRoutingStop() @C() @spontaneous() { + error_t collectionRoutingStop() @C() AT_SPONTANEOUS { return call RoutingControl.stop(); } - error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() { + error_t collectionReceive(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS { return call BlockingReceive.receive[id](m, timeout); } - error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() @spontaneous() { + error_t collectionSnoop(message_t* m, uint32_t timeout, collection_id_t id) @C() AT_SPONTANEOUS { return call BlockingSnoop.receive[id](m, timeout); } - error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() @spontaneous() { + error_t collectionSend(message_t* msg, uint8_t len, uint8_t id) @C() AT_SPONTANEOUS { call CollectionPacket.setType(msg, call CCollectionId.fetch(id)); return call BlockingSend.send[id](msg, len); } - void collectionClear(message_t* msg) @C() @spontaneous() { + void collectionClear(message_t* msg) @C() AT_SPONTANEOUS { call Packet.clear(msg); } - uint8_t collectionGetPayloadLength(message_t* msg) @C() @spontaneous() { + uint8_t collectionGetPayloadLength(message_t* msg) @C() AT_SPONTANEOUS { return call Packet.payloadLength(msg); } - void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() @spontaneous() { + void collectionSetPayloadLength(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { call Packet.setPayloadLength(msg, len); } - uint8_t collectionMaxPayloadLength() @C() @spontaneous() { + uint8_t collectionMaxPayloadLength() @C() AT_SPONTANEOUS { return call Packet.maxPayloadLength(); } - void* collectionGetPayload(message_t* msg, uint8_t len) @C() @spontaneous() { + void* collectionGetPayload(message_t* msg, uint8_t len) @C() AT_SPONTANEOUS { return call Packet.getPayload(msg, len); } - am_addr_t collectionGetOrigin(message_t* msg) @C() @spontaneous() { + am_addr_t collectionGetOrigin(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getOrigin(msg); } - void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() @spontaneous() { + void collectionSetOrigin(message_t* msg, am_addr_t addr) @C() AT_SPONTANEOUS { call CollectionPacket.setOrigin(msg, addr); } - collection_id_t collectionGetType(message_t* msg) @C() @spontaneous() { + collection_id_t collectionGetType(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getType(msg); } - void collectionSetType(message_t* msg, collection_id_t id) @C() @spontaneous() { + void collectionSetType(message_t* msg, collection_id_t id) @C() AT_SPONTANEOUS { call CollectionPacket.setType(msg, id); } - uint8_t collectionGetSequenceNumber(message_t* msg) @C() @spontaneous() { + uint8_t collectionGetSequenceNumber(message_t* msg) @C() AT_SPONTANEOUS { return call CollectionPacket.getSequenceNumber(msg); } - void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() @spontaneous() { + void collectionSetSequenceNumber(message_t* msg, uint8_t seqno) @C() AT_SPONTANEOUS { call CollectionPacket.setSequenceNumber(msg, seqno); } - error_t collectionSetRoot() @C() @spontaneous() { + error_t collectionSetRoot() @C() AT_SPONTANEOUS { return call RootControl.setRoot(); } - error_t collectionUnsetRoot() @C() @spontaneous() { + error_t collectionUnsetRoot() @C() AT_SPONTANEOUS { return call RootControl.unsetRoot(); } - bool collectionIsRoot() @C() @spontaneous() { + bool collectionIsRoot() @C() AT_SPONTANEOUS { return call RootControl.isRoot(); } } diff --git a/tos/lib/tosthreads/lib/printf/PrintfP.nc b/tos/lib/tosthreads/lib/printf/PrintfP.nc index 5f164bfa..47dcccfe 100644 --- a/tos/lib/tosthreads/lib/printf/PrintfP.nc +++ b/tos/lib/tosthreads/lib/printf/PrintfP.nc @@ -108,7 +108,7 @@ implementation { } } - int printfflush() @C() @spontaneous() { + int printfflush() @C() AT_SPONTANEOUS { call Barrier.block(&flushstart_barrier); call Barrier.reset(&flushstart_barrier, 2); call Barrier.block(&flushdone_barrier); diff --git a/tos/lib/tosthreads/sensorboards/basicsb/CPhotoP.nc b/tos/lib/tosthreads/sensorboards/basicsb/CPhotoP.nc index 51aeeff3..f1baf8e7 100644 --- a/tos/lib/tosthreads/sensorboards/basicsb/CPhotoP.nc +++ b/tos/lib/tosthreads/sensorboards/basicsb/CPhotoP.nc @@ -40,10 +40,10 @@ module CPhotoP { } } implementation { - error_t photo_read(uint16_t* val) @C() @spontaneous() { + error_t photo_read(uint16_t* val) @C() AT_SPONTANEOUS { return call BlockingRead.read(val); } - error_t photo_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() { + error_t photo_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS { return call BlockingReadStream.read(usPeriod, buf, count); } } diff --git a/tos/lib/tosthreads/sensorboards/basicsb/CTempP.nc b/tos/lib/tosthreads/sensorboards/basicsb/CTempP.nc index 1bcc8d9e..a9efc9c2 100644 --- a/tos/lib/tosthreads/sensorboards/basicsb/CTempP.nc +++ b/tos/lib/tosthreads/sensorboards/basicsb/CTempP.nc @@ -40,10 +40,10 @@ module CTempP { } } implementation { - error_t temp_read(uint16_t* val) @C() @spontaneous() { + error_t temp_read(uint16_t* val) @C() AT_SPONTANEOUS { return call BlockingRead.read(val); } - error_t temp_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() { + error_t temp_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS { return call BlockingReadStream.read(usPeriod, buf, count); } } diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc index 8346ee8d..84d43ac4 100644 --- a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc +++ b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS10871TsrP.nc @@ -41,13 +41,13 @@ module CHamamatsuS10871TsrP { } } implementation { - error_t hamamatsuS10871_tsr_read(uint16_t* val) @C() @spontaneous() { + error_t hamamatsuS10871_tsr_read(uint16_t* val) @C() AT_SPONTANEOUS { return call Read.read(val); } - error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() { + error_t hamamatsuS10871_tsr_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS { return call ReadStream.read(usPeriod, buf, count); } - uint8_t hamamatsuS10871_tsr_getNumBits() @C() @spontaneous() { + uint8_t hamamatsuS10871_tsr_getNumBits() @C() AT_SPONTANEOUS { return call DeviceMetadata.getSignificantBits(); } } diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc index 683b606c..6afd3f77 100644 --- a/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc +++ b/tos/lib/tosthreads/sensorboards/tmote_onboard/CHamamatsuS1087ParP.nc @@ -42,13 +42,13 @@ module CHamamatsuS1087ParP { } implementation { - error_t hamamatsuS1087_par_read(uint16_t* val) @C() @spontaneous() { + error_t hamamatsuS1087_par_read(uint16_t* val) @C() AT_SPONTANEOUS { return call Read.read(val); } - error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() @spontaneous() { + error_t hamamatsuS1087_par_readStream(uint32_t* usPeriod, uint16_t* buf, uint16_t count) @C() AT_SPONTANEOUS { return call ReadStream.read(usPeriod, buf, count); } - uint8_t hamamatsuS1087_par_getNumBits() @C() @spontaneous() { + uint8_t hamamatsuS1087_par_getNumBits() @C() AT_SPONTANEOUS { return call DeviceMetadata.getSignificantBits(); } } diff --git a/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc b/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc index 38ba3e80..1e478ab8 100644 --- a/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc +++ b/tos/lib/tosthreads/sensorboards/tmote_onboard/CSensirionSht11P.nc @@ -42,16 +42,16 @@ module CSensirionSht11P { } } implementation { - error_t sensirionSht11_humidity_read(uint16_t* val) @C() @spontaneous() { + error_t sensirionSht11_humidity_read(uint16_t* val) @C() AT_SPONTANEOUS { return call Humidity.read(val); } - uint8_t sensirionSht11_humidity_getNumBits() @C() @spontaneous() { + uint8_t sensirionSht11_humidity_getNumBits() @C() AT_SPONTANEOUS { return call HumidityMetadata.getSignificantBits(); } - error_t sensirionSht11_temperature_read(uint16_t* val) @C() @spontaneous() { + error_t sensirionSht11_temperature_read(uint16_t* val) @C() AT_SPONTANEOUS { return call Temperature.read(val); } - uint8_t sensirionSht11_temperature_getNumBits() @C() @spontaneous() { + uint8_t sensirionSht11_temperature_getNumBits() @C() AT_SPONTANEOUS { return call TemperatureMetadata.getSignificantBits(); } } diff --git a/tos/lib/tosthreads/sensorboards/universal/CSineSensorP.nc b/tos/lib/tosthreads/sensorboards/universal/CSineSensorP.nc index 63f197d5..770362a9 100644 --- a/tos/lib/tosthreads/sensorboards/universal/CSineSensorP.nc +++ b/tos/lib/tosthreads/sensorboards/universal/CSineSensorP.nc @@ -39,7 +39,7 @@ module CSineSensorP { } } implementation { - error_t sinesensor_read(uint16_t* val) @C() @spontaneous() { + error_t sinesensor_read(uint16_t* val) @C() AT_SPONTANEOUS { return call BlockingRead.read(val); } } diff --git a/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc b/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc index c2c7fa4a..e9b6b4ed 100644 --- a/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc +++ b/tos/lib/tosthreads/system/BlockingAMReceiverImplP.nc @@ -52,8 +52,8 @@ generic module BlockingAMReceiverImplP() { implementation { typedef struct params { - message_t* msg; uint32_t* timeout; + message_t* msg; error_t error; } params_t; diff --git a/tos/lib/tosthreads/system/BlockingResourceC.nc b/tos/lib/tosthreads/system/BlockingResourceC.nc index fc14b253..e7a4532e 100644 --- a/tos/lib/tosthreads/system/BlockingResourceC.nc +++ b/tos/lib/tosthreads/system/BlockingResourceC.nc @@ -47,8 +47,8 @@ implementation { BlockingResource = BlockingResourceP; Resource = BlockingResourceP; - components ThreadTimersC; - BlockingResourceP.Timer -> ThreadTimersC; + components ThreadSleepC; + BlockingResourceP.ThreadSleep -> ThreadSleepC; components SystemCallC; components TinyThreadSchedulerC; diff --git a/tos/lib/tosthreads/system/BlockingResourceP.nc b/tos/lib/tosthreads/system/BlockingResourceP.nc index b3e69a72..2821185e 100644 --- a/tos/lib/tosthreads/system/BlockingResourceP.nc +++ b/tos/lib/tosthreads/system/BlockingResourceP.nc @@ -41,12 +41,11 @@ generic module BlockingResourceP() { interface SystemCall; interface ThreadScheduler; interface Resource; - interface Timer[uint8_t id]; + interface ThreadSleep; } } implementation { typedef struct params { - uint32_t* milli; error_t error; } params_t; @@ -108,11 +107,6 @@ implementation { } /************************* Timed Release *****************************/ - void timerTask(syscall_t* s) { - params_t* p = s->params; - call Timer.startOneShot[s->thread->id](*(p->milli)); - } - command error_t BlockingResource.timedRelease(uint32_t milli) { syscall_t s; params_t p; @@ -122,15 +116,12 @@ implementation { resource_call = &s; } - if(milli != 0) { - p.milli = &milli; - call SystemCall.start(timerTask, &s, INVALID_ID, &p); - } - else { - call SystemCall.start(releaseTask, &s, INVALID_ID, &p); - if(p.error == SUCCESS) - call SystemCall.start(requestTask, &s, INVALID_ID, &p); - } + if(milli != 0) + call ThreadSleep.sleep(milli); + + call SystemCall.start(releaseTask, &s, INVALID_ID, &p); + if(p.error == SUCCESS) + call SystemCall.start(requestTask, &s, INVALID_ID, &p); atomic { resource_call = NULL; @@ -138,16 +129,6 @@ implementation { } } - event void Timer.fired[uint8_t id]() { - thread_t* t = call ThreadScheduler.threadInfo(id); - syscall_t* s = t->syscall; - params_t* p = t->syscall->params; - call SystemCall.start(releaseTask, s, INVALID_ID, p); - if(p->error == SUCCESS) - call SystemCall.start(requestTask, s, INVALID_ID, p); - else call SystemCall.finish(s); - } - /************************* isOwner pass through *****************************/ command error_t BlockingResource.isOwner() { return call Resource.isOwner(); diff --git a/tos/lib/tosthreads/system/DynamicThreadP.nc b/tos/lib/tosthreads/system/DynamicThreadP.nc index cb4cd804..de03f20d 100644 --- a/tos/lib/tosthreads/system/DynamicThreadP.nc +++ b/tos/lib/tosthreads/system/DynamicThreadP.nc @@ -137,11 +137,18 @@ happy: command error_t DynamicThread.sleep(uint32_t milli) { return call ThreadSleep.sleep(milli); } + command error_t DynamicThread.join(tosthread_t* t) { + return call ThreadScheduler.joinThread(*t); + } async command thread_t* ThreadInfo.get[uint8_t id]() { atomic return thread_info[id - TOSTHREAD_NUM_STATIC_THREADS]; } + async command error_t ThreadInfo.reset[uint8_t id]() { + return FAIL; + } + async event void ThreadCleanup.cleanup[uint8_t id]() { signal ThreadNotification.aboutToDestroy[id](); atomic { diff --git a/tos/lib/tosthreads/system/StaticThreadP.nc b/tos/lib/tosthreads/system/StaticThreadP.nc index ace29d10..8b10acbc 100644 --- a/tos/lib/tosthreads/system/StaticThreadP.nc +++ b/tos/lib/tosthreads/system/StaticThreadP.nc @@ -54,7 +54,7 @@ implementation { thread_info->start_arg_ptr = arg; thread_info->mutex_count = 0; thread_info->next_thread = NULL; - return call ThreadScheduler.initThread(id); + return ecombine(call ThreadInfo.reset[id](), call ThreadScheduler.initThread(id)); } command error_t Thread.start[uint8_t id](void* arg) { @@ -87,6 +87,10 @@ implementation { return call ThreadSleep.sleep(milli); } + command error_t Thread.join[uint8_t id]() { + return call ThreadScheduler.joinThread(id); + } + event void ThreadFunction.signalThreadRun[uint8_t id](void *arg) { signal Thread.run[id](arg); } @@ -97,6 +101,7 @@ implementation { default event void Thread.run[uint8_t id](void* arg) {} default async command thread_t* ThreadInfo.get[uint8_t id]() {return NULL;} + default async command error_t ThreadInfo.reset[uint8_t id]() {return FAIL;} default async event void ThreadNotification.justCreated[uint8_t id]() {} default async event void ThreadNotification.aboutToDestroy[uint8_t id]() {} diff --git a/tos/lib/tosthreads/system/ThreadInfoP.nc b/tos/lib/tosthreads/system/ThreadInfoP.nc index b971299a..c9cd980e 100644 --- a/tos/lib/tosthreads/system/ThreadInfoP.nc +++ b/tos/lib/tosthreads/system/ThreadInfoP.nc @@ -51,7 +51,7 @@ implementation { signal ThreadFunction.signalThreadRun(arg); } - command error_t Init.init() { + error_t init() { thread_info.next_thread = NULL; thread_info.id = thread_id; thread_info.init_block = NULL; @@ -64,6 +64,14 @@ implementation { return SUCCESS; } + command error_t Init.init() { + return init(); + } + + async command error_t ThreadInfo.reset() { + return init(); + } + async command thread_t* ThreadInfo.get() { return &thread_info; } diff --git a/tos/lib/tosthreads/system/ThreadMapP.nc b/tos/lib/tosthreads/system/ThreadMapP.nc index 9b4861a9..80526051 100644 --- a/tos/lib/tosthreads/system/ThreadMapP.nc +++ b/tos/lib/tosthreads/system/ThreadMapP.nc @@ -50,12 +50,21 @@ implementation { async command thread_t* ThreadInfo.get[uint8_t id]() { return call StaticThreadInfo.get[id](); } + async command error_t ThreadInfo.reset[uint8_t id]() { + return call StaticThreadInfo.reset[id](); + } default async command thread_t* StaticThreadInfo.get[uint8_t id]() { return call DynamicThreadInfo.get[id](); } + default async command error_t StaticThreadInfo.reset[uint8_t id]() { + return call DynamicThreadInfo.reset[id](); + } default async command thread_t* DynamicThreadInfo.get[uint8_t id]() { return call StaticThreadInfo.get[id](); } + default async command error_t DynamicThreadInfo.reset[uint8_t id]() { + return call StaticThreadInfo.reset[id](); + } async event void ThreadCleanup.cleanup[uint8_t id]() { signal StaticThreadCleanup.cleanup[id](); } diff --git a/tos/lib/tosthreads/system/ThreadSleepP.nc b/tos/lib/tosthreads/system/ThreadSleepP.nc index 65554cf0..d78212d9 100644 --- a/tos/lib/tosthreads/system/ThreadSleepP.nc +++ b/tos/lib/tosthreads/system/ThreadSleepP.nc @@ -62,8 +62,20 @@ implementation { return SUCCESS; } + //Need to add a cancel command so that components like + //BlockingAMReceiverImplP can use the ThreadSleep interface + //directly instead of reusing the underlying ThreadTimerC + //component. The current implementation does things this way + //and causes us to be defensive in here since the same + //TimerMilli.fired() event is sent to that component as well. + //Basically its just broken.... cancel() would get rid of this. + + //Also need some sort of a sleepWithSyscall command + //Need to think about this one a little more + event void TimerMilli.fired[uint8_t id]() { thread_t* t = call ThreadScheduler.threadInfo(id); - call SystemCall.finish(t->syscall); + if(t->syscall->syscall_ptr == sleepTask) + call SystemCall.finish(t->syscall); } } diff --git a/tos/lib/tosthreads/system/TinyOSMainP.nc b/tos/lib/tosthreads/system/TinyOSMainP.nc index 2df6d5df..75d06aa1 100644 --- a/tos/lib/tosthreads/system/TinyOSMainP.nc +++ b/tos/lib/tosthreads/system/TinyOSMainP.nc @@ -93,6 +93,10 @@ implementation { call TaskScheduler.taskLoop(); } + + async command error_t ThreadInfo.reset() { + return FAIL; + } async command thread_t* ThreadInfo.get() { return &thread_info; diff --git a/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc b/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc index cf5c283d..0d4d6036 100644 --- a/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc +++ b/tos/lib/tosthreads/system/TinyThreadSchedulerC.nc @@ -57,6 +57,9 @@ implementation { ThreadScheduler = Sched; Sched.McuSleep -> Sleep; + components BitArrayUtilsC; + Sched.BitArrayUtils -> BitArrayUtilsC; + components ThreadQueueC; Sched.ThreadQueue -> ThreadQueueC; diff --git a/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc b/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc index 1ae67708..e93af191 100644 --- a/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc +++ b/tos/lib/tosthreads/system/TinyThreadSchedulerP.nc @@ -43,6 +43,7 @@ module TinyThreadSchedulerP { interface Boot as ThreadSchedulerBoot; interface ThreadInfo[uint8_t id]; interface ThreadQueue; + interface BitArrayUtils; interface McuSleep; interface Leds; interface Timer as PreemptionAlarm; @@ -138,8 +139,13 @@ implementation { * threads by the thread scheduler. */ void stop(thread_t* t) { + int i; t->state = TOSTHREAD_STATE_INACTIVE; num_started_threads--; + for(i=0; ijoinedOnMe, i)) + call ThreadScheduler.wakeupThread(i); + } if(num_started_threads == 1) call PreemptionAlarm.stop(); signal ThreadCleanup.cleanup[t->id](); @@ -178,6 +184,7 @@ implementation { thread_t* t = (call ThreadInfo.get[id]()); t->state = TOSTHREAD_STATE_INACTIVE; t->init_block = current_thread->init_block; + call BitArrayUtils.clrArray(t->joinedOnMe, sizeof(t->joinedOnMe)); PREPARE_THREAD(t, threadWrapper); return SUCCESS; } @@ -232,6 +239,20 @@ implementation { } } + async command error_t ThreadScheduler.joinThread(thread_id_t id) { + thread_t* t = call ThreadInfo.get[id](); + atomic { + if(current_thread == tos_thread) + return FAIL; + if (t->state != TOSTHREAD_STATE_INACTIVE) { + call BitArrayUtils.setBit(t->joinedOnMe, current_thread->id); + call ThreadScheduler.suspendCurrentThread(); + return SUCCESS; + } + } + return EALREADY; + } + async command error_t ThreadScheduler.wakeupThread(uint8_t id) { thread_t* t = call ThreadInfo.get[id](); if((t->state) == TOSTHREAD_STATE_SUSPENDED) { diff --git a/tos/lib/tosthreads/system/TosMallocC.nc b/tos/lib/tosthreads/system/TosMallocC.nc index 7f811e2b..8de2ba39 100644 --- a/tos/lib/tosthreads/system/TosMallocC.nc +++ b/tos/lib/tosthreads/system/TosMallocC.nc @@ -52,7 +52,7 @@ implementation { size_t malloc_heap[MALLOC_HEAP_SIZE]; - void *tos_malloc (size_t size) @C() @spontaneous() + void *tos_malloc (size_t size) @C() AT_SPONTANEOUS { static char once = 0; size_t * heap_bottom = &(malloc_heap[MALLOC_HEAP_SIZE]); @@ -103,7 +103,7 @@ implementation { return NULL; } - void tos_free (void *p) @C() @spontaneous() + void tos_free (void *p) @C() AT_SPONTANEOUS { size_t *t = (size_t*)p - 1; MARK_FREE (t); diff --git a/tos/lib/tosthreads/types/thread.h b/tos/lib/tosthreads/types/thread.h index c86d9f74..87df6121 100644 --- a/tos/lib/tosthreads/types/thread.h +++ b/tos/lib/tosthreads/types/thread.h @@ -94,7 +94,6 @@ struct syscall { }; //This is a thread data structure -//This structure is 43 bytes long... struct thread { //***** next_thread must be at first position in struct for casting purposes ******* volatile struct thread* next_thread; //Pointer to next thread for use in queues when blocked @@ -103,6 +102,7 @@ struct thread { stack_ptr_t stack_ptr; //Pointer to this threads stack volatile uint8_t state; //Current state the thread is in volatile uint8_t mutex_count; //A reference count of the number of mutexes held by this thread + uint8_t joinedOnMe[(TOSTHREAD_MAX_NUM_THREADS - 1) / 8 + 1]; //Bitmask of threads waiting for me to finish void (*start_ptr)(void*); //Pointer to the start function of this thread void* start_arg_ptr; //Pointer to the argument passed as a parameter to the start function of this thread syscall_t* syscall; //Pointer to an instance of a system call