Changeset 499 for trunk/thune/thread.c

Show
Ignore:
Timestamp:
12/05/07 03:12:00 (12 months ago)
Author:
krobillard
Message:

Added ur_threadDestroy(). Removed ur_threadFree() from public API.
c_string.t should now handle all quotes properly.
Minor fix in GL boot
Documented stack.level.
Increased OpenAL music buffer size and now handle alutInit() failure.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/thread.c

    r461 r499  
    5555        if( env->threads ) 
    5656        { 
    57 #if 0 
    5857            UThread* link = env->threads; 
    5958            ut->nextThread = link->nextThread; 
    6059            link->nextThread = ut; 
    61 #endif 
    6260        } 
    6361        else 
     
    9189 
    9290/* 
    93 void ur_threadUnlink( UThread* th ) 
     91   Free memory used by UThread. 
     92 
     93   This does NOT remove the thread from the environemnt thread list. 
     94   ur_threadDestroy() must be used for that. 
     95*/ 
     96void ur_threadFree( UThread* ut ) 
     97{ 
     98    _freeResources( ut->env, &ut->resources.arr ); 
     99 
     100    _freeArrayOfArray( &ut->blocks.arr ); 
     101    _freeArrayOfArray( &ut->bin.arr ); 
     102 
     103    memFree( ut ); 
     104} 
     105 
     106 
     107/** 
     108  Remove UThread from environment thread list and free memory. 
     109*/ 
     110void ur_threadDestroy( UThread* ut ) 
    94111{ 
    95112    UThread* it; 
    96     it = ((UrlanEnv*) th->env)->threads; 
    97     if( it == th ) 
    98         ((UrlanEnv*) th->env)->threads = (UThread*) th->nextTask; 
    99     while( it->nextTask != th ) 
    100         it = it->nextTask; 
    101     it->nextTask = th->nextTask; 
    102 } 
    103 */ 
     113    UrlanEnv* env = ut->env; 
     114 
     115    LOCK_GLOBAL 
     116 
     117    it = env->threads; 
     118    if( it == ut ) 
     119    { 
     120        if( ut == ut->nextThread ) 
     121        { 
     122            env->threads = 0; 
     123            goto done; 
     124        } 
     125        env->threads = (UThread*) ut->nextThread; 
     126    } 
     127    while( it->nextThread != ut ) 
     128        it = it->nextThread; 
     129    it->nextThread = ut->nextThread; 
     130 
     131done: 
     132    UNLOCK_GLOBAL 
     133 
     134    ur_threadFree( ut ); 
     135} 
     136 
     137 
     138/* 
     139   Return UThread to initial state with empty stacks. 
     140*/ 
     141void ur_threadReset( UThread* th ) 
     142{ 
     143    /* 
     144      Data Stack     [BOS --> TOS      eos [2 reserved]] 
     145      Control Stack  [BOC --> TOC    [<-- Local Frames]] 
     146    */ 
     147 
     148    th->state  = UR_TASK_READY; 
     149    th->callOp = 0; 
     150    th->tos = th->dstack; 
     151    // Eos reserves 2 cells for temporary call use & select! evaluation. 
     152    th->eos = th->dstack + UR_DSTACK_SIZE - 2; 
     153    th->toc = th->cstack; 
     154    th->localFT = (LocalFrame*) th->cstack + UR_CSTACK_SIZE; 
     155    ur_initType( th->tos, UT_UNSET ); 
     156 
     157    //th->localWordBlk = 0; 
     158    //th->localPos = 0; 
     159} 
    104160 
    105161 
     
    155211 
    156212 
    157 void ur_threadFree( UThread* ut ) 
    158 { 
    159     _freeResources( ut->env, &ut->resources.arr ); 
    160  
    161     _freeArrayOfArray( &ut->blocks.arr ); 
    162     _freeArrayOfArray( &ut->bin.arr ); 
    163  
    164     memFree( ut ); 
    165 } 
    166  
    167  
    168 void ur_threadReset( UThread* th ) 
    169 { 
    170     /* 
    171       Data Stack     [BOS --> TOS      eos [2 reserved]] 
    172       Control Stack  [BOC --> TOC    [<-- Local Frames]] 
    173     */ 
    174  
    175     th->state  = UR_TASK_READY; 
    176     th->callOp = 0; 
    177     th->tos = th->dstack; 
    178     // Eos reserves 2 cells for temporary call use & select! evaluation. 
    179     th->eos = th->dstack + UR_DSTACK_SIZE - 2; 
    180     th->toc = th->cstack; 
    181     th->localFT = (LocalFrame*) th->cstack + UR_CSTACK_SIZE; 
    182     ur_initType( th->tos, UT_UNSET ); 
    183  
    184     //th->localWordBlk = 0; 
    185     //th->localPos = 0; 
    186 } 
    187  
    188  
    189213void ur_pushContext( UThread* ut, UContext* ctx ) 
    190214{