about summary refs log tree commit diff stats
path: root/tools/iso/kernel.soso/message.c
blob: d4ef1b5757ba4fd105a449a4f2f505f3d2a5bf57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}