| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 library dart.fletch.os; | 5 library dart.dartino.os; |
| 6 | 6 |
| 7 import 'dart:fletch._system' as fletch; | 7 import 'dart:dartino._system' as dartino; |
| 8 import 'dart:fletch'; | 8 import 'dart:dartino'; |
| 9 import 'dart:fletch.ffi'; | 9 import 'dart:dartino.ffi'; |
| 10 | 10 |
| 11 part 'native_process.dart'; | 11 part 'native_process.dart'; |
| 12 part 'event_handler.dart'; | 12 part 'event_handler.dart'; |
| 13 | 13 |
| 14 final ForeignFunction _nanosleep = ForeignLibrary.main.lookup("nanosleep"); | 14 final ForeignFunction _nanosleep = ForeignLibrary.main.lookup("nanosleep"); |
| 15 | 15 |
| 16 class _Timespec extends Struct { | 16 class _Timespec extends Struct { |
| 17 _Timespec() : super(2); | 17 _Timespec() : super(2); |
| 18 int get tv_sec => getField(0); | 18 int get tv_sec => getField(0); |
| 19 int get tv_nsec => getField(1); | 19 int get tv_nsec => getField(1); |
| 20 void set tv_sec(int value) => setField(0, value); | 20 void set tv_sec(int value) => setField(0, value); |
| 21 void set tv_nsec(int value) => setField(1, value); | 21 void set tv_nsec(int value) => setField(1, value); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Sleep is still here and not in package:os, as it is used in async_patch.dart. | 24 // Sleep is still here and not in package:os, as it is used in async_patch.dart. |
| 25 void sleep(int milliseconds) { | 25 void sleep(int milliseconds) { |
| 26 _Timespec timespec = new _Timespec(); | 26 _Timespec timespec = new _Timespec(); |
| 27 timespec.tv_sec = milliseconds ~/ 1000; | 27 timespec.tv_sec = milliseconds ~/ 1000; |
| 28 timespec.tv_nsec = (milliseconds % 1000) * 1000000; | 28 timespec.tv_nsec = (milliseconds % 1000) * 1000000; |
| 29 int result; | 29 int result; |
| 30 try { | 30 try { |
| 31 result = _nanosleep.icall$2Retry(timespec, timespec); | 31 result = _nanosleep.icall$2Retry(timespec, timespec); |
| 32 } finally { | 32 } finally { |
| 33 timespec.free(); | 33 timespec.free(); |
| 34 } | 34 } |
| 35 if (result != 0) throw "Failed to call 'nanosleep': ${Foreign.errno}"; | 35 if (result != 0) throw "Failed to call 'nanosleep': ${Foreign.errno}"; |
| 36 } | 36 } |
| OLD | NEW |