diff --git a/src/sys/include/mpi/mpi.h b/src/sys/include/mpi/mpi.h new file mode 100644 index 0000000..255c9b5 --- /dev/null +++ b/src/sys/include/mpi/mpi.h @@ -0,0 +1,69 @@ +/***************************************************************************************** + 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$ + +*****************************************************************************************/ + +#ifndef _MPI_H +#define _MPI_H + +#include + +#define MESSAGE_LENGTH 248 + +struct mpi_message { + char data[MESSAGE_LENGTH]; + uInt32 header; + pidType pid; + struct mpi_message *next; + }; + +struct mpi_mbox { + struct mpi_mbox *next; + struct mpi_mbox *prev; + struct mpi_message *msg; + struct mpi_message *msgLast; + char name[64]; + pidType pid; + }; + +typedef struct mpi_mbox mpi_mbox_t; +typedef struct mpi_message mpi_message_t; + + +int mpi_createMbox(char *); +int mpi_destroyMbox(char *); +int mpi_postMessage(char *,uInt32,mpi_message_t *); +int mpi_fetchMessage(char *,mpi_message_t *); +int mpi_spam(uInt32,void *); + +#endif + +/*** + $Log$ + END + ***/ + diff --git a/src/sys/mpi/Makefile b/src/sys/mpi/Makefile new file mode 100644 index 0000000..8f81032 --- /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 = mpi.o + +all: $(OBJS) + +# Compile Types +.cc.o: + $(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.cc.s: + $(CXX) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.c.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< +.c.s: + $(CC) $(CFLAGS) $(INCLUDES) -S -o $@ $< +.S.o: + $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< + +# Clean up the junk +clean: + $(REMOVE) $(OBJS) diff --git a/src/sys/mpi/mpi.c b/src/sys/mpi/mpi.c new file mode 100644 index 0000000..6d0b9d9 --- /dev/null +++ b/src/sys/mpi/mpi.c @@ -0,0 +1,266 @@ +/***************************************************************************************** + 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 + +#if 0 + +#include +#include +#include + +static mpi_mbox_t *mboxList = 0x0; +static spinLock_t mpiSpinLock = SPIN_LOCK_INITIALIZER; + +/***************************************************************************************** + + Function: static mpiMbox_t * mpiFindMbox(char *name) + + Description: This function will find a mail box that matches the supplied name + + Notes: This function is not task-safe! Lock must be done before call. + +*****************************************************************************************/ +static mpi_mbox_t * mpi_findMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + for (mbox = mboxList;mbox;mbox = mbox->next) { + if (!strcmp(mbox->name,name)) { + return(mbox); + } + } + + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiCreateMbox(char *name) + + Description: This function will create a new mailbox if it fails it will return -1 + otherwise it returns 0x0 + + Notes: + +*****************************************************************************************/ +int mpi_createMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + if (mpi_findMbox(name) != 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + mbox = (mpi_mbox_t *)kmalloc(sizeof(mpi_mbox_t)); + + sprintf(mbox->name,name); + mbox->pid = _current->id; + + 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(0x0); + } + +/***************************************************************************************** + + Function: int mpiSpam(uInt32 type,void *data) + + Description: This function will send a message to every mailbox + + Notes: + +*****************************************************************************************/ +int mpi_spam(uInt32 type,void *data) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *message = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox = mbox->next) { + message = (mpi_message_t *)kmalloc(sizeof(mpi_message_t)); + + message->header = type; + memcpy(message->data,data,MESSAGE_LENGTH); + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + } + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiPostMessage(char *name,uInt32 type,void *data) + + Description: This function will post a message to specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_postMessage(char *name,uInt32 type,mpi_message_t *msg) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *message = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpi_findMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(0x1); + } + + message = (mpi_message_t *)kmalloc(sizeof(mpi_message_t)); + + message->header = msg->header; + memcpy(message->data,msg->data,MESSAGE_LENGTH); + message->pid = _current->id; + message->next = 0x0; + + if (mbox->msg == 0x0) { + mbox->msg = message; + } + else { + mbox->msgLast->next = message; + mbox->msgLast = message; + } + + spinUnlock(&mpiSpinLock); + + if (type == 0x2) { + while (mbox->msgLast != 0x0); + } + + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiFetchMessage(char *name,mpiMessage_t *msg) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_fetchMessage(char *name,mpi_message_t *msg) { + mpi_mbox_t *mbox = 0x0; + mpi_message_t *tmpMsg = 0x0; + + spinLock(&mpiSpinLock); + + mbox = mpi_findMbox(name); + + if (mbox == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->msg == 0x0) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + + msg->header = mbox->msg->header; + memcpy(msg->data,mbox->msg->data,MESSAGE_LENGTH); + msg->pid = mbox->msg->pid; + + tmpMsg = mbox->msg; + mbox->msg = mbox->msg->next; + + kfree(tmpMsg); + + spinUnlock(&mpiSpinLock); + return(0x0); + } + +/***************************************************************************************** + + Function: int mpiDestroyMbox(char *name) + + Description: This function will fetch the next message out of the specified mailbox + + Notes: + +*****************************************************************************************/ +int mpi_destroyMbox(char *name) { + mpi_mbox_t *mbox = 0x0; + + spinLock(&mpiSpinLock); + + for (mbox = mboxList;mbox;mbox=mbox->next) { + if (!strcmp(mbox->name,name)) { + if (mbox->pid != _current->id) { + spinUnlock(&mpiSpinLock); + return(-1); + } + mbox->prev->next = mbox->next; + mbox->next->prev = mbox->prev; + kfree(mbox); + spinUnlock(&mpiSpinLock); + return(0x0); + } + } + + spinUnlock(&mpiSpinLock); + return(-1); + } + +#endif + +/*** + $Log$ + + END + ***/