Show
Ignore:
Timestamp:
07/16/07 03:30:29 (17 months ago)
Author:
krobillard
Message:

Atoms should now be thread safe. First thread experiment runs.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/thune/thread_safe/thread.c

    r408 r431  
    3838 
    3939 
     40extern UCellContext ur_thrGlobal; 
     41 
    4042UThread* ur_threadMake( UrlanEnv* env, int binCount, int blkCount ) 
    4143{ 
     
    5355        if( env->threads ) 
    5456        { 
     57#if 0 
    5558            UThread* link = env->threads; 
    5659            ut->nextThread = link->nextThread; 
    5760            link->nextThread = ut; 
     61#endif 
    5862        } 
    5963        else 
     
    7175        //ur_hold( ut, UT_BINARY, binN );       // Hardcoded in recycle 
    7276        } 
     77 
     78        // Make hold & global context blocks. 
     79        ur_makeBlock( 8 );        // 0 - BLK_THREAD_HOLD 
     80        ur_makeBlock( 1024 );     // 1 - BLK_GLOBAL_WORD 
     81        ur_makeBlock( 1024 );     // 2 - BLK_GLOBAL_VAL 
     82        ur_makeBlock( 1 );        // 3 - BLK_CTX_STACK 
     83        //ur_makeBlock( 0 );        // 4 - BLK_DSTACK 
     84 
     85        ur_pushContext( ut, (UCell*) &ur_thrGlobal ); 
    7386    } 
    7487    return ut; 
     
    7689 
    7790 
    78 #ifdef UR_CONFIG_THREADS 
     91/* 
    7992void ur_threadUnlink( UThread* th ) 
    8093{ 
     
    8295    it = ((UrlanEnv*) th->env)->threads; 
    8396    if( it == th ) 
    84         ((UrlanEnv*) th->env)->threads = (UThread*) th->nextThread; 
    85     while( it->nextThread != th ) 
    86         it = it->nextThread; 
    87     it->nextThread = th->nextThread; 
     97        ((UrlanEnv*) th->env)->threads = (UThread*) th->nextTask; 
     98    while( it->nextTask != th ) 
     99        it = it->nextTask; 
     100    it->nextTask = th->nextTask; 
     101} 
     102*/ 
     103 
     104 
     105#ifdef UR_CONFIG_TASKS 
     106void ur_taskUnlink( UThread* th ) 
     107{ 
     108    UThread* it; 
     109    it = ((UrlanEnv*) th->env)->threads; 
     110    if( it == th ) 
     111        ((UrlanEnv*) th->env)->threads = (UThread*) th->nextTask; 
     112    while( it->nextTask != th ) 
     113        it = it->nextTask; 
     114    it->nextTask = th->nextTask; 
    88115} 
    89116 
    90117 
    91118// Returns zero and sets error if no threads are ready. 
    92 UThread* ur_threadNextReady( UThread* cur ) 
     119UThread* ur_taskNextReady( UThread* cur ) 
    93120{ 
    94121    UThread* next = cur; 
     
    96123    do 
    97124    { 
    98         next = next->nextThread; 
    99         if( next->state == UR_THREAD_READY ) 
    100         { 
    101             next->state = UR_THREAD_RUNNING; 
     125        next = next->nextTask; 
     126        if( next->state == UR_TASK_READY ) 
     127        { 
     128            next->state = UR_TASK_RUNNING; 
    102129            return next; 
    103130        } 
    104         else if( next->state == UR_THREAD_BLOCKED ) 
     131        else if( next->state == UR_TASK_BLOCKED ) 
    105132        { 
    106133            UCell* pc; 
     
    113140                if( pc && ! ur_is(pc, UT_UNSET) ) 
    114141                { 
    115                     next->state = UR_THREAD_RUNNING; 
     142                    next->state = UR_TASK_RUNNING; 
    116143                    return next; 
    117144                } 
     
    121148    while( next != cur ); 
    122149 
    123     ur_throwErr( cur, UR_EX_SCRIPT, "All threads are blocked" );  
     150    ur_throwErr( cur, UR_EX_SCRIPT, "All tasks are blocked" );  
    124151    return 0; 
    125152} 
     
    145172    */ 
    146173 
    147     th->state  = UR_THREAD_READY; 
     174    th->state  = UR_TASK_READY; 
    148175    th->callOp = 0; 
    149176    th->tos = th->dstack; 
     
    183210 
    184211/** 
    185   \returns cell pointer to TOS. 
     212  \return  cell pointer to TOS. 
    186213  Pops TOS if pop is non-zero. 
    187214*/