| 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 | */ |
| | 96 | void 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 | */ |
| | 110 | void ur_threadDestroy( UThread* ut ) |
| 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 | |
| | 131 | done: |
| | 132 | UNLOCK_GLOBAL |
| | 133 | |
| | 134 | ur_threadFree( ut ); |
| | 135 | } |
| | 136 | |
| | 137 | |
| | 138 | /* |
| | 139 | Return UThread to initial state with empty stacks. |
| | 140 | */ |
| | 141 | void 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 | } |
| 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 | | |