diff --git a/src/sys/mpi/Makefile b/src/sys/mpi/Makefile new file mode 100644 index 0000000..a74968d --- /dev/null +++ b/src/sys/mpi/Makefile @@ -0,0 +1,27 @@ +# (C) 2002-2004 The UbixOS Project +# $Id$ + +# Include Global 'Source' Options +include ../../Makefile.inc +include ../Makefile.inc + +# Objects +OBJS = message.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../include -c -o $@ $< +.cc.s: + $(CXX) ${CFLAGS} -fno-exceptions -DNOBOOL -Wall -fomit-frame-pointer -O -I../include -S -o $@ $< +.c.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../include -c -o $@ $< +.c.s: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../include -S -o $@ $< +.S.o: + $(CC) ${CFLAGS} -Wall -fomit-frame-pointer -O -I../include -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/mpi/message.c b/src/sys/mpi/message.c new file mode 100644 index 0000000..1d8644f --- /dev/null +++ b/src/sys/mpi/message.c @@ -0,0 +1,138 @@ +/***************************************************************************************** + Copyright (c) 2002-2004 The UbixOS Project + All rights reserved. + + Redistribution and use in source and binary forms, with or without modification, are + permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright notice, this list of + conditions, the following disclaimer and the list of authors. Redistributions in binary + form must reproduce the above copyright notice, this list of conditions, the following + disclaimer and the list of authors in the documentation and/or other materials provided + with the distribution. Neither the name of the UbixOS Project nor the names of its + contributors may be used to endorse or promote products derived from this software + without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + $Id$ + +*****************************************************************************************/ + +#include +#include +#include +#include + +static mpiMbox_t *mboxList = 0x0; +static spinLock_t mpiSpinLock = SPIN_LOCK_INITIALIZER; + +mpiMbox_t * mpiCreateMbox(char *name) { + mpiMbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + + if (mpiFindMbox(name) != 0x0) { + spinUnlock(&mpiSpinLock); + return(0x0); + } + + mbox = (mpiMbox_t *)kmalloc(sizeof(mpiMbox_t)); + + sprintf(mbox->name,name); + + if (mboxList == 0x0) { + mbox->prev = 0x0; + mbox->next = 0x0; + mboxList = mbox; + } + else { + mbox->next = mboxList; + mbox->prev = 0x0; + mboxList->prev = mbox; + mboxList = mbox; + } + + spinUnlock(&mpiSpinLock); + return(mbox); + } + +mpiMbox_t * mpiFindMbox(char *name) { + mpiMbox_t *mbox = 0x0; + + for (mbox = mboxList;mbox;mbox = mbox->next) { + if (!kstrcmp(mbox->name,name)) { + spinUnlock(&mpiSpinLock); + return(mbox); + } + } + + return(0x0); + } + +int mpiPostMessage(char *name,uInt32 type,void *data) { + mpiMbox_t *mbox = 0x0; + mpiMessage_t *message = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpiFindMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + message = (mpiMessage_t *)kmalloc(sizeof(mpiMessage_t)); + + message->type = type; + kmemcpy(message->data,data,512); + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +int mpiFetchMessage(mpiMbox_t *mbox,mpiMessage_t *msg) { + mpiMessage_t *tmpMsg = 0x0; + + spinLock(&mpiSpinLock); + + if (mbox->msg == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + msg->type = mbox->msg->type; + kmemcpy(msg->data,mbox->msg->data,512); + + tmpMsg = mbox->msg; + mbox->msg = mbox->msg->next; + + kfree(tmpMsg); + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/*** + $Log$ + END + ***/ +