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
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.
#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;
}