diff options
Diffstat (limited to 'tools/iso/kernel.soso/message.c')
-rw-r--r-- | tools/iso/kernel.soso/message.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/tools/iso/kernel.soso/message.c b/tools/iso/kernel.soso/message.c new file mode 100644 index 00000000..d4ef1b57 --- /dev/null +++ b/tools/iso/kernel.soso/message.c @@ -0,0 +1,46 @@ +#include "message.h" +#include "process.h" +#include "fifobuffer.h" + + +void sendMesage(Thread* thread, SosoMessage* message) { + Spinlock_Lock(&(thread->messageQueueLock)); + + FifoBuffer_enqueue(thread->messageQueue, (uint8*)message, sizeof(SosoMessage)); + + Spinlock_Unlock(&(thread->messageQueueLock)); +} + +uint32 getMessageQueueCount(Thread* thread) { + int result = 0; + + Spinlock_Lock(&(thread->messageQueueLock)); + + result = FifoBuffer_getSize(thread->messageQueue) / sizeof(SosoMessage); + + Spinlock_Unlock(&(thread->messageQueueLock)); + + return result; +} + +//returns remaining message count +int32 getNextMessage(Thread* thread, SosoMessage* message) { + uint32 result = -1; + + Spinlock_Lock(&(thread->messageQueueLock)); + + result = FifoBuffer_getSize(thread->messageQueue) / sizeof(SosoMessage); + + if (result > 0) { + FifoBuffer_dequeue(thread->messageQueue, (uint8*)message, sizeof(SosoMessage)); + + --result; + } + else { + result = -1; + } + + Spinlock_Unlock(&(thread->messageQueueLock)); + + return result; +} |