ubthread.c
ubixos/ubthread.h
ubixos/exec.h
ubixos/sched.h
ubixos/time.h
ubixos/spinlock.h
ubixos/vitals.h
lib/kmalloc.h
lib/kprintf.h
sys/thread.h
ubixos/sched.h
ubixos/spinlock.h
ubixos/vitals.h
src/sys/kernel/ubthread.c
ubixos/types.h
sys/_types.h
ubixos/time.h
vfs/file.h
sys/tss.h
lib/kmalloc.h
vfs/vfs.h
vfs/mount.h
lib/kprintf.h
ubixos/ubthread.h
ubixfs/dirCache.h
ubixos/exec.h
sys/sysproto.h
sys/signal.h
ubixos/tty.h
sys/io.h
int int ubthread_cond_destroy (ubthread_cond_t *cond) ubthread_cond_destroy ubthread_cond_t * cond kfree
int int ubthread_cond_init (ubthread_cond_t *cond, const uInt32 attr) ubthread_cond_init ubthread_cond_t * cond const uInt32 attr ubthread_cond::id kmalloc ubthread_cond::locked UNLOCKED
int int ubthread_cond_signal (ubthread_cond_t *cond) ubthread_cond_signal ubthread_cond_t * cond ubthread_cond::locked UNLOCKED
int int ubthread_cond_timedwait (ubthread_cond_t *cond, ubthread_mutex_t *mutex, const struct timespec *abstime) ubthread_cond_timedwait ubthread_cond_t * cond ubthread_mutex_t * mutex const struct timespec * abstime ubthread_mutex::locked ubthread_cond::locked mutex sched_yield systemVitals vitalsStruct::sysUptime UNLOCKED
int int ubthread_cond_wait (ubthread_cond_t *cond, ubthread_mutex_t *mutex) ubthread_cond_wait ubthread_cond_t * cond ubthread_mutex_t * mutex ubthread_mutex::locked LOCKED ubthread_cond::locked mutex sched_yield UNLOCKED
int int ubthread_create (kTask_t **thread, const uInt32 *attr, void(*tproc)(void), void *arg) ubthread_create kTask_t ** thread const uInt32 * attr void(*)(void) tproc void * arg execThread kmalloc x2000
int int ubthread_mutex_destroy (ubthread_mutex_t *mutex) ubthread_mutex_destroy ubthread_mutex_t * mutex kfree mutex
int int ubthread_mutex_init (ubthread_mutex_t *mutex, const uInt32 attr) ubthread_mutex_init ubthread_mutex_t * mutex const uInt32 attr ubthread_mutex::id kmalloc ubthread_mutex::locked mutex UNLOCKED
int int ubthread_mutex_lock (ubthread_mutex_t *mutex) ubthread_mutex_lock ubthread_mutex_t * mutex _current taskStruct::id kprintf LOCKED ubthread_mutex::locked mutex ubthread_mutex::pid
int int ubthread_mutex_unlock (ubthread_mutex_t *mutex) ubthread_mutex_unlock ubthread_mutex_t * mutex _current taskStruct::id ubthread_mutex::locked mutex ubthread_mutex::pid UNLOCKED
kTask_t * kTask_t* ubthread_self () ubthread_self _current
ubthread_cond_list * struct ubthread_cond_list* conds conds 0x0
ubthread_mutex_list * struct ubthread_mutex_list* mutex mutex 0x0 ubthread_cond_timedwait ubthread_cond_wait ubthread_mutex_destroy ubthread_mutex_init ubthread_mutex_lock ubthread_mutex_unlock

    /*****************************************************************************************
    Copyright(c)2002-2004TheUbixOSProject
    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: ubthread_8c.xml 88 2016-01-12 00:11:29Z reddawg $

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

    /*Allthesemustbeconvertedtobedoneatomically*/

    #include<ubixos/ubthread.h>
    #include<ubixos/exec.h>
    #include<ubixos/sched.h>
    #include<ubixos/time.h>
    #include<ubixos/spinlock.h>
    #include<ubixos/vitals.h>
    #include<lib/kmalloc.h>
    #include<lib/kprintf.h>

    structubthread_cond_list*conds=0x0;
    structubthread_mutex_list*mutex=0x0;

    kTask_t*ubthread_self(){
    return(_current);
    }

    intubthread_cond_init(ubthread_cond_t*cond,constuInt32attr){
    ubthread_cond_tubcond=kmalloc(sizeof(structubthread_cond));
    ubcond->id=(int)cond;
    ubcond->locked=UNLOCKED;
    *cond=ubcond;
    return(0x0);
    }

    intubthread_mutex_init(ubthread_mutex_t*mutex,constuInt32attr){
    ubthread_mutex_tubmutex=kmalloc(sizeof(structubthread_mutex));
    ubmutex->id=(int)mutex;
    ubmutex->locked=UNLOCKED;
    *mutex=ubmutex;
    return(0x0);
    }

    intubthread_cond_destroy(ubthread_cond_t*cond){
    kfree(*cond);
    *cond=0x0;
    return(0x0);
    }

    intubthread_mutex_destroy(ubthread_mutex_t*mutex){
    kfree(*mutex);
    *mutex=0x0;
    return(0x0);
    }

    intubthread_create(kTask_t**thread,constuInt32*attr,void(*tproc)(void),void*arg){
    *thread=(void*)execThread(tproc,(int)(kmalloc(0x2000)+0x2000),arg);
    return(0x0);
    }

    intubthread_mutex_lock(ubthread_mutex_t*mutex){
    ubthread_mutex_tubmutex=*mutex;
    if(ubmutex->locked==LOCKED){
    kprintf("MutexAlreadyLockBy%xTryingToBeRelockedBy%x\n",ubmutex->pid,_current->id);
    while(ubmutex->locked==LOCKED);
    }
    ubmutex->locked=LOCKED;
    ubmutex->pid=_current->id;
    return(0x0);
    }

    intubthread_mutex_unlock(ubthread_mutex_t*mutex){
    ubthread_mutex_tubmutex=*mutex;
    if(ubmutex->pid==_current->id){
    ubmutex->locked=UNLOCKED;
    return(0x0);
    }
    else{
    //kprintf("TryingToUnlockMutexFromNoLockingThread\n");
    ubmutex->locked=UNLOCKED;
    return(-1);
    }
    }

    intubthread_cond_timedwait(ubthread_cond_t*cond,ubthread_mutex_t*mutex,conststructtimespec*abstime){
    ubthread_cond_tubcond=*cond;
    ubthread_mutex_tubmutex=*mutex;
    uInt32enterTime=systemVitals->sysUptime+20;
    while(enterTime>systemVitals->sysUptime){
    if(ubcond->locked==UNLOCKED)break;
    sched_yield();
    }
    ubmutex->locked=UNLOCKED;
    return(0x0);
    }

    intubthread_cond_wait(ubthread_cond_t*cond,ubthread_mutex_t*mutex){
    ubthread_cond_tubcond=*cond;
    ubthread_mutex_tubmutex=*mutex;
    while(ubcond->locked==LOCKED)sched_yield();
    ubmutex->locked=UNLOCKED;
    return(0x0);
    }

    intubthread_cond_signal(ubthread_cond_t*cond){
    ubthread_cond_tubcond=*cond;
    ubcond->locked=UNLOCKED;
    return(0x0);
    }

    /***
    END
    ***/