Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 2624

Show
Ignore:
Timestamp:
10/05/07 01:53:08 (1 year ago)
Author:
sean
Message:

Added thread_attachThis() and thread_detachThis() to register and unregister foreign threads. Also used to register the main thread during initialization.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/common/tango/core/Thread.d

    r2534 r2624  
    14251425        Thread.sm_this = TlsAlloc(); 
    14261426        assert( Thread.sm_this != TLS_OUT_OF_INDEXES ); 
    1427  
    1428         Thread          mainThread  = new Thread(); 
    1429         Thread.Context* mainContext = &mainThread.m_main; 
    1430         assert( mainContext == mainThread.m_curr ); 
    1431  
    1432         mainThread.m_addr  = GetCurrentThreadId(); 
    1433         mainThread.m_hndl  = GetCurrentThreadHandle(); 
    1434         mainContext.bstack = getStackBottom(); 
    1435         mainContext.tstack = mainContext.bstack; 
    1436  
    1437         mainThread.m_isDaemon = true; 
    1438  
    1439         Thread.setThis( mainThread ); 
    14401427    } 
    14411428    else version( Posix ) 
     
    14841471        status = pthread_key_create( &Thread.sm_this, null ); 
    14851472        assert( status == 0 ); 
    1486  
    1487         Thread          mainThread  = new Thread(); 
    1488         Thread.Context* mainContext = mainThread.m_curr; 
    1489         assert( mainContext == &mainThread.m_main ); 
    1490  
    1491         mainThread.m_addr  = pthread_self(); 
    1492         mainContext.bstack = getStackBottom(); 
    1493         mainContext.tstack = mainContext.bstack; 
    1494  
    1495         mainThread.m_isRunning = true; 
    1496         mainThread.m_isDaemon  = true; 
    1497  
    1498         Thread.setThis( mainThread ); 
    1499     } 
    1500  
    1501     Thread.add( mainThread ); 
    1502     Thread.add( mainContext ); 
     1473    } 
     1474 
     1475    thread_attachThis(); 
     1476
     1477 
     1478 
     1479/** 
     1480 * Registers the calling thread for use with Tango.  If this routine is called 
     1481 * for a thread which is already registered, the result is undefined. 
     1482 */ 
     1483extern (C) void thread_attachThis() 
     1484
     1485    version( Win32 ) 
     1486    { 
     1487        Thread          thisThread  = new Thread(); 
     1488        Thread.Context* thisContext = &thisThread.m_main; 
     1489        assert( thisContext == thisThread.m_curr ); 
     1490 
     1491        thisThread.m_addr  = GetCurrentThreadId(); 
     1492        thisThread.m_hndl  = GetCurrentThreadHandle(); 
     1493        thisContext.bstack = getStackBottom(); 
     1494        thisContext.tstack = thisContext.bstack; 
     1495 
     1496        thisThread.m_isDaemon = true; 
     1497 
     1498        Thread.setThis( thisThread ); 
     1499    } 
     1500    else version( Posix ) 
     1501    { 
     1502        Thread          thisThread  = new Thread(); 
     1503        Thread.Context* thisContext = thisThread.m_curr; 
     1504        assert( thisContext == &thisThread.m_main ); 
     1505 
     1506        thisThread.m_addr  = pthread_self(); 
     1507        thisContext.bstack = getStackBottom(); 
     1508        thisContext.tstack = thisContext.bstack; 
     1509 
     1510        thisThread.m_isRunning = true; 
     1511        thisThread.m_isDaemon  = true; 
     1512 
     1513        Thread.setThis( thisThread ); 
     1514    } 
     1515 
     1516    Thread.add( thisThread ); 
     1517    Thread.add( thisContext ); 
     1518
     1519 
     1520 
     1521/** 
     1522 * Deregisters the calling thread from use with Tango.  If this routine is 
     1523 * called for a thread which is already registered, the result is undefined. 
     1524 */ 
     1525extern (C) void thread_detachThis() 
     1526
     1527    Thread.remove( Thread.getThis() ); 
    15031528} 
    15041529