Changeset 43
- Timestamp:
- 11/04/08 19:35:42 (4 years ago)
- Files:
-
- branches/D1.0/src/common/core/thread.d (modified) (29 diffs)
- trunk/src/common/core/thread.d (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/D1.0/src/common/core/thread.d
r36 r43 112 112 // been set and Thread.getThis returns a valid reference to 113 113 // this thread object (this latter condition is not strictly 114 // necessary on Win 32 but it should be followed for the sake115 // of consistency).114 // necessary on Windows but it should be followed for the 115 // sake of consistency). 116 116 117 117 // TODO: Consider putting an auto exception object here (using … … 244 244 // been set and Thread.getThis returns a valid reference to 245 245 // this thread object (this latter condition is not strictly 246 // necessary on Win 32 but it should be followed for the sake247 // of consistency).246 // necessary on Windows but it should be followed for the 247 // sake of consistency). 248 248 249 249 // TODO: Consider putting an auto exception object here (using … … 480 480 } 481 481 482 version( Win 32)482 version( Windows ) 483 483 { 484 484 m_addr = m_addr.init; … … 516 516 body 517 517 { 518 version( Win 32) {} else518 version( Windows ) {} else 519 519 version( Posix ) 520 520 { … … 536 536 synchronized( slock ) 537 537 { 538 version( Win 32)538 version( Windows ) 539 539 { 540 540 m_hndl = cast(HANDLE) _beginthreadex( null, m_sz, &thread_entryPoint, cast(void*) this, 0, &m_addr ); … … 574 574 final Object join( bool rethrow = true ) 575 575 { 576 version( Win 32)576 version( Windows ) 577 577 { 578 578 if( WaitForSingleObject( m_hndl, INFINITE ) != WAIT_OBJECT_0 ) … … 691 691 } 692 692 693 version( Win 32)693 version( Windows ) 694 694 { 695 695 uint ecode = 0; … … 738 738 final int priority() 739 739 { 740 version( Win 32)740 version( Windows ) 741 741 { 742 742 return GetThreadPriority( m_hndl ); … … 762 762 final void priority( int val ) 763 763 { 764 version( Win 32)764 version( Windows ) 765 765 { 766 766 if( !SetThreadPriority( m_hndl, val ) ) … … 806 806 * ------------------------------------------------------------------------ 807 807 * 808 * Thread.sleep( 500 );// sleep for 50 milliseconds808 * Thread.sleep( 500_000 ); // sleep for 50 milliseconds 809 809 * Thread.sleep( 50_000_000 ); // sleep for 5 seconds 810 810 * … … 818 818 body 819 819 { 820 version( Win 32)820 version( Windows ) 821 821 { 822 822 enum : uint … … 826 826 } 827 827 828 period = period < TICKS_PER_MILLI ? 829 1 : 830 period / TICKS_PER_MILLI; 828 // NOTE: In instances where all other threads in the process have a 829 // lower priority than the current thread, the current thread 830 // will not yield with a sleep time of zero. However, unlike 831 // yield(), the user is not asking for a yield to occur but 832 // only for execution to suspend for the requested interval. 833 // Therefore, expected performance may not be met if a yield 834 // is forced upon the user. 835 period /= TICKS_PER_MILLI; 831 836 while( period > MAX_SLEEP_MILLIS ) 832 837 { … … 883 888 static void yield() 884 889 { 885 version( Win 32)890 version( Windows ) 886 891 { 887 892 // NOTE: Sleep(1) is necessary because Sleep(0) does not give … … 914 919 // completed. See thread_suspendAll for more information 915 920 // on why this might occur. 916 version( Win 32)921 version( Windows ) 917 922 { 918 923 return cast(Thread) TlsGetValue( sm_this ); … … 1084 1089 static this() 1085 1090 { 1086 version( Win 32)1091 version( Windows ) 1087 1092 { 1088 1093 PRIORITY_MIN = -15; … … 1154 1159 // Standard types 1155 1160 // 1156 version( Win 32)1161 version( Windows ) 1157 1162 { 1158 1163 alias uint TLSKey; … … 1178 1183 // Standard thread data 1179 1184 // 1180 version( Win 32)1185 version( Windows ) 1181 1186 { 1182 1187 HANDLE m_hndl; … … 1210 1215 static void setThis( Thread t ) 1211 1216 { 1212 version( Win 32)1217 version( Windows ) 1213 1218 { 1214 1219 TlsSetValue( sm_this, cast(void*) t ); … … 1277 1282 bool m_lock; 1278 1283 1279 version( Win 32)1284 version( Windows ) 1280 1285 { 1281 1286 uint[8] m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax … … 1438 1443 assert( t ); 1439 1444 assert( t.next || t.prev ); 1440 version( Win 32)1445 version( Windows ) 1441 1446 { 1442 1447 // NOTE: This doesn't work for Posix as m_isRunning must be set to … … 1496 1501 // functions to detect the condition and return immediately. 1497 1502 1498 version( Win 32)1503 version( Windows ) 1499 1504 { 1500 1505 Thread.sm_this = TlsAlloc(); … … 1558 1563 extern (C) void thread_attachThis() 1559 1564 { 1560 version( Win 32)1565 version( Windows ) 1561 1566 { 1562 1567 Thread thisThread = new Thread(); … … 1698 1703 void suspend( Thread t ) 1699 1704 { 1700 version( Win 32)1705 version( Windows ) 1701 1706 { 1702 1707 if( t.m_addr != GetCurrentThreadId() && SuspendThread( t.m_hndl ) == 0xFFFFFFFF ) … … 1842 1847 void resume( Thread t ) 1843 1848 { 1844 version( Win 32)1849 version( Windows ) 1845 1850 { 1846 1851 if( t.m_addr != GetCurrentThreadId() && ResumeThread( t.m_hndl ) == 0xFFFFFFFF ) … … 1963 1968 } 1964 1969 } 1965 version( Win 32)1970 version( Windows ) 1966 1971 { 1967 1972 for( Thread t = Thread.sm_tbeg; t; t = t.next ) … … 2243 2248 else 2244 2249 { 2245 version( Win 32)2250 version( Windows ) 2246 2251 version = AsmX86_Win32; 2247 2252 else version( Posix ) … … 2762 2767 static Fiber getThis() 2763 2768 { 2764 version( Win 32)2769 version( Windows ) 2765 2770 { 2766 2771 return cast(Fiber) TlsGetValue( sm_this ); … … 2780 2785 static this() 2781 2786 { 2782 version( Win 32)2787 version( Windows ) 2783 2788 { 2784 2789 sm_this = TlsAlloc(); … … 3149 3154 static void setThis( Fiber f ) 3150 3155 { 3151 version( Win 32)3156 version( Windows ) 3152 3157 { 3153 3158 TlsSetValue( sm_this, cast(void*) f ); trunk/src/common/core/thread.d
r36 r43 112 112 // been set and Thread.getThis returns a valid reference to 113 113 // this thread object (this latter condition is not strictly 114 // necessary on Win 32 but it should be followed for the sake115 // of consistency).114 // necessary on Windows but it should be followed for the 115 // sake of consistency). 116 116 117 117 // TODO: Consider putting an auto exception object here (using … … 244 244 // been set and Thread.getThis returns a valid reference to 245 245 // this thread object (this latter condition is not strictly 246 // necessary on Win 32 but it should be followed for the sake247 // of consistency).246 // necessary on Windows but it should be followed for the 247 // sake of consistency). 248 248 249 249 // TODO: Consider putting an auto exception object here (using … … 480 480 } 481 481 482 version( Win 32)482 version( Windows ) 483 483 { 484 484 m_addr = m_addr.init; … … 516 516 body 517 517 { 518 version( Win 32) {} else518 version( Windows ) {} else 519 519 version( Posix ) 520 520 { … … 536 536 synchronized( slock ) 537 537 { 538 version( Win 32)538 version( Windows ) 539 539 { 540 540 m_hndl = cast(HANDLE) _beginthreadex( null, m_sz, &thread_entryPoint, cast(void*) this, 0, &m_addr ); … … 574 574 final Object join( bool rethrow = true ) 575 575 { 576 version( Win 32)576 version( Windows ) 577 577 { 578 578 if( WaitForSingleObject( m_hndl, INFINITE ) != WAIT_OBJECT_0 ) … … 691 691 } 692 692 693 version( Win 32)693 version( Windows ) 694 694 { 695 695 uint ecode = 0; … … 738 738 final int priority() 739 739 { 740 version( Win 32)740 version( Windows ) 741 741 { 742 742 return GetThreadPriority( m_hndl ); … … 762 762 final void priority( int val ) 763 763 { 764 version( Win 32)764 version( Windows ) 765 765 { 766 766 if( !SetThreadPriority( m_hndl, val ) ) … … 806 806 * ------------------------------------------------------------------------ 807 807 * 808 * Thread.sleep( 500 );// sleep for 50 milliseconds808 * Thread.sleep( 500_000 ); // sleep for 50 milliseconds 809 809 * Thread.sleep( 50_000_000 ); // sleep for 5 seconds 810 810 * … … 818 818 body 819 819 { 820 version( Win 32)820 version( Windows ) 821 821 { 822 822 enum : uint … … 826 826 } 827 827 828 period = period < TICKS_PER_MILLI ? 829 1 : 830 period / TICKS_PER_MILLI; 828 // NOTE: In instances where all other threads in the process have a 829 // lower priority than the current thread, the current thread 830 // will not yield with a sleep time of zero. However, unlike 831 // yield(), the user is not asking for a yield to occur but 832 // only for execution to suspend for the requested interval. 833 // Therefore, expected performance may not be met if a yield 834 // is forced upon the user. 835 period /= TICKS_PER_MILLI; 831 836 while( period > MAX_SLEEP_MILLIS ) 832 837 { … … 883 888 static void yield() 884 889 { 885 version( Win 32)890 version( Windows ) 886 891 { 887 892 // NOTE: Sleep(1) is necessary because Sleep(0) does not give … … 914 919 // completed. See thread_suspendAll for more information 915 920 // on why this might occur. 916 version( Win 32)921 version( Windows ) 917 922 { 918 923 return cast(Thread) TlsGetValue( sm_this ); … … 1084 1089 static this() 1085 1090 { 1086 version( Win 32)1091 version( Windows ) 1087 1092 { 1088 1093 PRIORITY_MIN = -15; … … 1154 1159 // Standard types 1155 1160 // 1156 version( Win 32)1161 version( Windows ) 1157 1162 { 1158 1163 alias uint TLSKey; … … 1178 1183 // Standard thread data 1179 1184 // 1180 version( Win 32)1185 version( Windows ) 1181 1186 { 1182 1187 HANDLE m_hndl; … … 1210 1215 static void setThis( Thread t ) 1211 1216 { 1212 version( Win 32)1217 version( Windows ) 1213 1218 { 1214 1219 TlsSetValue( sm_this, cast(void*) t ); … … 1277 1282 bool m_lock; 1278 1283 1279 version( Win 32)1284 version( Windows ) 1280 1285 { 1281 1286 uint[8] m_reg; // edi,esi,ebp,esp,ebx,edx,ecx,eax … … 1438 1443 assert( t ); 1439 1444 assert( t.next || t.prev ); 1440 version( Win 32)1445 version( Windows ) 1441 1446 { 1442 1447 // NOTE: This doesn't work for Posix as m_isRunning must be set to … … 1496 1501 // functions to detect the condition and return immediately. 1497 1502 1498 version( Win 32)1503 version( Windows ) 1499 1504 { 1500 1505 Thread.sm_this = TlsAlloc(); … … 1558 1563 extern (C) void thread_attachThis() 1559 1564 { 1560 version( Win 32)1565 version( Windows ) 1561 1566 { 1562 1567 Thread thisThread = new Thread(); … … 1698 1703 void suspend( Thread t ) 1699 1704 { 1700 version( Win 32)1705 version( Windows ) 1701 1706 { 1702 1707 if( t.m_addr != GetCurrentThreadId() && SuspendThread( t.m_hndl ) == 0xFFFFFFFF ) … … 1842 1847 void resume( Thread t ) 1843 1848 { 1844 version( Win 32)1849 version( Windows ) 1845 1850 { 1846 1851 if( t.m_addr != GetCurrentThreadId() && ResumeThread( t.m_hndl ) == 0xFFFFFFFF ) … … 1963 1968 } 1964 1969 } 1965 version( Win 32)1970 version( Windows ) 1966 1971 { 1967 1972 for( Thread t = Thread.sm_tbeg; t; t = t.next ) … … 2243 2248 else 2244 2249 { 2245 version( Win 32)2250 version( Windows ) 2246 2251 version = AsmX86_Win32; 2247 2252 else version( Posix ) … … 2762 2767 static Fiber getThis() 2763 2768 { 2764 version( Win 32)2769 version( Windows ) 2765 2770 { 2766 2771 return cast(Fiber) TlsGetValue( sm_this ); … … 2780 2785 static this() 2781 2786 { 2782 version( Win 32)2787 version( Windows ) 2783 2788 { 2784 2789 sm_this = TlsAlloc(); … … 3149 3154 static void setThis( Fiber f ) 3150 3155 { 3151 version( Win 32)3156 version( Windows ) 3152 3157 { 3153 3158 TlsSetValue( sm_this, cast(void*) f );
