Changeset 486
- Timestamp:
- 01/08/11 18:58:01 (14 years ago)
- Files:
-
- trunk/src/core/sync/condition.d (modified) (1 diff)
- trunk/src/core/sync/semaphore.d (modified) (2 diffs)
- trunk/src/core/thread.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/core/sync/condition.d
r483 r486 156 156 */ 157 157 bool wait( Duration val ) 158 158 in 159 159 { 160 160 assert( !val.isNegative ); 161 161 } 162 162 body 163 163 { 164 164 version( Win32 ) 165 165 { 166 auto maxWaitMillis = milliseconds( uint.max - 1 );166 auto maxWaitMillis = dur!("msecs")( uint.max - 1 ); 167 167 168 168 while( val > maxWaitMillis ) 169 169 { 170 170 if( timedWait( cast(uint) 171 maxWaitMillis.total Milliseconds) )171 maxWaitMillis.total!("msecs")() ) ) 172 172 return true; 173 173 val -= maxWaitMillis; 174 174 } 175 return timedWait( cast(uint) val.total Milliseconds);175 return timedWait( cast(uint) val.total!("msecs")() ); 176 176 } 177 177 else version( Posix ) 178 178 { 179 179 timespec t = void; 180 180 mktspec( t, val ); 181 181 182 182 int rc = pthread_cond_timedwait( &m_hndl, m_mutexAddr, &t ); 183 183 if( !rc ) 184 184 return true; 185 185 if( rc == ETIMEDOUT ) trunk/src/core/sync/semaphore.d
r483 r486 156 156 } 157 157 } 158 158 159 159 160 160 /** 161 161 * Suspends the calling thread until the current count moves above zero or 162 162 * until the supplied time period has elapsed. If the count moves above 163 163 * zero in this interval, then atomically decrement the count by one and 164 164 * return true. Otherwise, return false. 165 165 * 166 *167 166 * Params: 168 167 * period = The time to wait. 169 168 * 170 169 * In: 171 170 * val must be non-negative. 172 171 * 173 172 * Throws: 174 173 * SyncException on error. 175 174 * 176 175 * Returns: … … 257 256 } 258 257 } 259 258 } 260 259 261 260 262 261 /** 263 262 * Suspends the calling thread until the current count moves above zero or 264 263 * until the supplied time period has elapsed. If the count moves above 265 264 * zero in this interval, then atomically decrement the count by one and 266 265 * return true. Otherwise, return false. 267 *268 266 * 269 267 * Params: 270 268 * period = The time to wait, in 100 nanosecond intervals. This value may 271 269 * be adjusted to equal to the maximum wait period supported by 272 270 * the target platform if it is too large. 273 271 * 274 272 * In: 275 273 * period must be non-negative. 276 274 * 277 275 * Throws: trunk/src/core/thread.d
r484 r486 1060 1060 * 1061 1061 * Params: 1062 1062 * val = The minimum duration the calling thread should be suspended. 1063 1063 * 1064 1064 * In: 1065 1065 * period must be non-negative. 1066 1066 * 1067 1067 * Example: 1068 1068 * ------------------------------------------------------------------------ 1069 1069 * 1070 * Thread.sleep( milliseconds( 50 ) ); // sleep for 50 milliseconds1071 * Thread.sleep( seconds( 5 ) );// sleep for 5 seconds1070 * Thread.sleep( dur!("msecs")( 50 ) ); // sleep for 50 milliseconds 1071 * Thread.sleep( dur!("seconds")( 5 ) ); // sleep for 5 seconds 1072 1072 * 1073 1073 * ------------------------------------------------------------------------ 1074 1074 */ 1075 1075 static void sleep( Duration val ) 1076 1076 in 1077 1077 { 1078 1078 assert( !val.isNegative ); 1079 1079 } 1080 1080 body 1081 1081 { 1082 1082 version( Windows ) 1083 1083 { 1084 auto maxSleepMillis = milliseconds( uint.max - 1 );1084 auto maxSleepMillis = dur!("msecs")( uint.max - 1 ); 1085 1085 1086 1086 // NOTE: In instances where all other threads in the process have a 1087 1087 // lower priority than the current thread, the current thread 1088 1088 // will not yield with a sleep time of zero. However, unlike 1089 1089 // yield(), the user is not asking for a yield to occur but 1090 1090 // only for execution to suspend for the requested interval. 1091 1091 // Therefore, expected performance may not be met if a yield 1092 1092 // is forced upon the user. 1093 1093 while( val > maxSleepMillis ) 1094 1094 { 1095 1095 Sleep( cast(uint) 1096 maxSleepMillis.total Milliseconds);1096 maxSleepMillis.total!("msecs")() ); 1097 1097 val -= maxSleepMillis; 1098 1098 } 1099 Sleep( cast(uint) val.total Milliseconds);1099 Sleep( cast(uint) val.total!("msecs")() ); 1100 1100 } 1101 1101 else version( Posix ) 1102 1102 { 1103 1103 timespec tin = void; 1104 1104 timespec tout = void; 1105 1105 1106 1106 if( val.total!("seconds")() > tin.tv_sec.max ) 1107 1107 { 1108 1108 tin.tv_sec = tin.tv_sec.max; 1109 1109 tin.tv_nsec = cast(typeof(tin.tv_nsec)) val.fracSec.nsecs;
