system.c
mpi/mpi.h
lib/kmalloc.h
lib/string.h
ubixos/spinlock.h
sys/thread.h
ubixos/sched.h
ubixos/spinlock.h
src/sys/mpi/system.c
ubixos/types.h
sys/_types.h
lib/string.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
mpi/mpi.h
vfs/mount.h
ubixfs/dirCache.h
ubixos/tty.h
int int mpi_createMbox (char *name) mpi_createMbox char * name _current taskStruct::id kmalloc mboxList mpi_findMbox mpiSpinLock mpi_mbox::name mpi_mbox::next mpi_mbox::pid mpi_mbox::prev spinLock spinUnlock sprintf sysMpiCreateMbox systemTask ubixfs_thread
int int mpi_destroyMbox (char *name) mpi_destroyMbox char * name _current taskStruct::id kfree mboxList mpiSpinLock mpi_mbox::name mpi_mbox::next mpi_mbox::pid mpi_mbox::prev spinLock spinUnlock strcmp sysMpiDestroyMbox
int int mpi_fetchMessage (char *name, mpi_message_t *msg) mpi_fetchMessage char * name mpi_message_t * msg _current mpi_message::data mpi_message::header taskStruct::id kfree memcpy MESSAGE_LENGTH mpi_findMbox mpiSpinLock mpi_mbox::msg mpi_message::next mpi_message::pid mpi_mbox::pid spinLock spinUnlock sysMpiFetchMessage systemTask ubixfs_thread
mpi_mbox_t * static mpi_mbox_t* mpi_findMbox (char *name) mpi_findMbox char * name mboxList mpi_mbox::name mpi_mbox::next strcmp mpi_createMbox mpi_fetchMessage mpi_postMessage
int int mpi_postMessage (char *name, uInt32 type, mpi_message_t *msg) mpi_postMessage char * name uInt32 type mpi_message_t * msg _current mpi_message::data mpi_message::header taskStruct::id kmalloc memcpy MESSAGE_LENGTH mpi_findMbox mpiSpinLock mpi_mbox::msg mpi_mbox::msgLast mpi_message::next mpi_message::pid spinLock spinUnlock x1 sysMpiPostMessage
int int mpi_spam (uInt32 type, void *data) mpi_spam uInt32 type void * data mpi_message::data mpi_message::header kmalloc mboxList memcpy MESSAGE_LENGTH mpiSpinLock mpi_mbox::msg mpi_mbox::msgLast mpi_message::next mpi_mbox::next spinLock spinUnlock sysMpiSpam
mpi_mbox_t * mpi_mbox_t* mboxList mboxList 0x0 mpi_createMbox mpi_destroyMbox mpi_findMbox mpi_spam
spinLock_t spinLock_t mpiSpinLock mpiSpinLock SPIN_LOCK_INITIALIZER mpi_createMbox mpi_destroyMbox mpi_fetchMessage mpi_postMessage mpi_spam

    /*****************************************************************************************
    Copyright(c)2002-2005TheUbixOSProject
    Allrightsreserved.

    Redistributionanduseinsourceandbinaryforms,withorwithoutmodification,are
    permittedprovidedthatthefollowingconditionsaremet:

    Redistributionsofsourcecodemustretaintheabovecopyrightnotice,thislistof
    conditions,thefollowingdisclaimerandthelistofauthors.Redistributionsinbinary
    formmustreproducetheabovecopyrightnotice,thislistofconditions,thefollowing
    disclaimerandthelistofauthorsinthedocumentationand/orothermaterialsprovided
    withthedistribution.NeitherthenameoftheUbixOSProjectnorthenamesofits
    contributorsmaybeusedtoendorseorpromoteproductsderivedfromthissoftware
    withoutspecificpriorwrittenpermission.

    THISSOFTWAREISPROVIDEDBYTHECOPYRIGHTHOLDERSANDCONTRIBUTORS"ASIS"ANDANY
    EXPRESSORIMPLIEDWARRANTIES,INCLUDING,BUTNOTLIMITEDTO,THEIMPLIEDWARRANTIESOF
    MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAREDISCLAIMED.INNOEVENTSHALL
    THECOPYRIGHTOWNERORCONTRIBUTORSBELIABLEFORANYDIRECT,INDIRECT,INCIDENTAL,
    SPECIAL,EXEMPLARY,ORCONSEQUENTIALDAMAGES(INCLUDING,BUTNOTLIMITEDTO,PROCUREMENT
    OFSUBSTITUTEGOODSORSERVICES;LOSSOFUSE,DATA,ORPROFITS;ORBUSINESSINTERRUPTION)
    HOWEVERCAUSEDANDONANYTHEORYOFLIABILITY,WHETHERINCONTRACT,STRICTLIABILITY,OR
    TORT(INCLUDINGNEGLIGENCEOROTHERWISE)ARISINGINANYWAYOUTOFTHEUSEOFTHIS
    SOFTWARE,EVENIFADVISEDOFTHEPOSSIBILITYOFSUCHDAMAGE.

    $Id: system_8c.xml 88 2016-01-12 00:11:29Z reddawg $

    *****************************************************************************************/

    #include<mpi/mpi.h>
    #include<lib/kmalloc.h>
    #include<lib/string.h>
    #include<ubixos/spinlock.h>

    staticmpi_mbox_t*mboxList=0x0;
    staticspinLock_tmpiSpinLock=SPIN_LOCK_INITIALIZER;

    /*****************************************************************************************

    Function:staticmpiMbox_t*mpiFindMbox(char*name)

    Description:Thisfunctionwillfindamailboxthatmatchesthesuppliedname

    Notes:Thisfunctionisnottask-safe!Lockmustbedonebeforecall.

    *****************************************************************************************/
    staticmpi_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:intmpiCreateMbox(char*name)

    Description:Thisfunctionwillcreateanewmailboxifitfailsitwillreturn-1
    otherwiseitreturns0x0

    Notes:

    *****************************************************************************************/
    intmpi_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:intmpiSpam(uInt32type,void*data)

    Description:Thisfunctionwillsendamessagetoeverymailbox

    Notes:

    *****************************************************************************************/
    intmpi_spam(uInt32type,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:intmpiPostMessage(char*name,uInt32type,void*data)

    Description:Thisfunctionwillpostamessagetospecifiedmailbox

    Notes:

    *****************************************************************************************/
    intmpi_postMessage(char*name,uInt32type,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:intmpiFetchMessage(char*name,mpiMessage_t*msg)

    Description:Thisfunctionwillfetchthenextmessageoutofthespecifiedmailbox

    Notes:

    *****************************************************************************************/
    intmpi_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:intmpiDestroyMbox(char*name)

    Description:Thisfunctionwillfetchthenextmessageoutofthespecifiedmailbox

    Notes:

    *****************************************************************************************/
    intmpi_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);
    }

    /***
    END
    ***/