Changeset 431 for branches/thune/thread_safe/thune.c
- Timestamp:
- 07/16/07 03:30:29 (17 months ago)
- Files:
-
- 1 modified
-
branches/thune/thread_safe/thune.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/thune/thread_safe/thune.c
r427 r431 11 11 extern int ur_lessOrEqual( const UCell*, const UCell* ); 12 12 13 #ifdef UR_CONFIG_T HREADS14 extern void ur_t hreadUnlink( UThread* );15 extern UThread* ur_t hreadNextReady( UThread* );13 #ifdef UR_CONFIG_TASKS 14 extern void ur_taskUnlink( UThread* ); 15 extern UThread* ur_taskNextReady( UThread* ); 16 16 #endif 17 17 … … 164 164 165 165 #ifdef UR_CONFIG_THREADS 166 // (block -- ) 166 #ifdef _WIN32 167 static DWORD WINAPI threadRoutine( LPVOID arg ) 168 #else 169 static void* threadRoutine( void* arg ) 170 #endif 171 { 172 UThread* ut = (UThread*) arg; 173 ur_eval( ut, ut->tos[1].series.n, 0 ); 174 ur_threadFree( ut ); 175 return 0; 176 } 177 178 /* 179 static void ur_threadCloneCell( UThread* ut, UCell* cellA, 180 UThread* to, UCell* cellB ) 181 { 182 UIndex newBlkN; 183 184 switch( ur_type(cell) ) 185 { 186 case UT_BLOCK: 187 { 188 UBlock* blkA; 189 UBlock* blkB; 190 blkA = ur_blockPtr( blkN ); 191 newBlkN = ur_makeBlockT( to, blkA->used, &blkB ); 192 } 193 break; 194 195 case UT_STRING: 196 break; 197 } 198 } 199 */ 200 201 202 // (code -- ) 167 203 UR_CALL( uc_thread ) 168 204 { 205 if( ur_is(tos, UT_BLOCK) || ur_is(tos, UT_STRING) ) 206 { 207 UThread* thr = ur_threadMake( ut->env, 64, 128 ); 208 if( thr ) 209 { 210 OSThread pth; 211 #ifdef _WIN32 212 DWORD winId; 213 #endif 214 215 if( ur_is(tos, UT_STRING) ) 216 { 217 char* cpA; 218 char* cpB; 219 ur_seriesMem( ut, tos, &cpA, &cpB ); 220 thr->tos[1].series.n = ur_tokenize( thr, cpA, cpB ); 221 } 222 223 #ifdef _WIN32 224 pth = CreateThread( NULL, 0, threadRoutine, thr, 0, &winId ); 225 if( pth == NULL ) 226 #else 227 if( pthread_create( &pth, 0, threadRoutine, thr ) != 0 ) 228 #endif 229 { 230 ur_throwErr( UR_ERR_INTERNAL, "Could not create thread" ); 231 return; 232 } 233 234 #if 1 235 { 236 void* status; 237 pthread_join( pth, &status ); //KR 238 } 239 #endif 240 } 241 UR_S_DROP; 242 } 243 else 244 { 245 ur_throwErr( UR_ERR_DATATYPE, "thread expected block!/string!" ); 246 } 247 } 248 #endif 249 250 251 #ifdef UR_CONFIG_TASKS 252 // (block -- ) 253 UR_CALL( uc_task ) 254 { 169 255 if( ur_is(tos, UT_BLOCK) ) 170 256 { 171 257 UThread* thr; 172 258 UThread* save; 173 thr = ur_threadMake( ut->env );259 thr = ur_threadMake( ut->env, 32, 32 ); 174 260 if( thr ) 175 261 { … … 307 393 UCell* pc; 308 394 UCell* end; 309 #ifdef UR_CONFIG_T HREADS395 #ifdef UR_CONFIG_TASKS 310 396 int insCycle = 0; 311 397 #endif … … 323 409 execute: 324 410 325 #ifdef UR_CONFIG_T HREADS411 #ifdef UR_CONFIG_TASKS 326 412 if( ++insCycle == 100 ) 327 413 { 328 if( ut->nextT hread!= ut )329 { 330 ut->state = UR_T HREAD_READY;414 if( ut->nextTask != ut ) 415 { 416 ut->state = UR_TASK_READY; 331 417 switch_thread: 332 418 PUSHC_EVAL( blkN, start, pc ); 333 ut = ur_t hreadNextReady( ut );419 ut = ur_taskNextReady( ut ); 334 420 if( ! ut ) 335 421 goto error; … … 363 449 case UT_UNSET: 364 450 --pc; 365 #ifdef UR_CONFIG_T HREADS366 if( ut->nextT hread!= ut )367 { 368 ut->state = UR_T HREAD_BLOCKED;451 #ifdef UR_CONFIG_TASKS 452 if( ut->nextTask != ut ) 453 { 454 ut->state = UR_TASK_BLOCKED; 369 455 goto switch_thread; 370 456 } … … 956 1042 goto execute; 957 1043 958 #ifdef UR_CONFIG_T HREADS1044 #ifdef UR_CONFIG_TASKS 959 1045 case CC_TERM: 960 if( ut->nextT hread== ut )1046 if( ut->nextTask == ut ) 961 1047 goto finish; 962 term_t hread:1048 term_task: 963 1049 { 964 1050 UThread* thr = ut; 965 ut->state = UR_T HREAD_TERM;966 ut = ur_t hreadNextReady( ut );1051 ut->state = UR_TASK_TERM; 1052 ut = ur_taskNextReady( ut ); 967 1053 if( ! ut ) 968 1054 goto error; 969 ur_t hreadUnlink( thr );1055 ur_taskUnlink( thr ); 970 1056 ur_threadFree( thr ); 971 1057 } … … 974 1060 975 1061 case CC_END: 976 #ifdef UR_CONFIG_T HREADS977 if( ut->nextT hread!= ut )978 goto term_t hread;1062 #ifdef UR_CONFIG_TASKS 1063 if( ut->nextTask != ut ) 1064 goto term_task; 979 1065 #endif 980 1066 goto finish;
