Skip to content

Commit 68c8051

Browse files
authoredApr 15, 2018
Stub out ::sleep for win32 (#5947)
Just calls LibC.Sleep for now, which blocks the whole program.
1 parent 19360bc commit 68c8051

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

Diff for: ‎src/lib_c/x86_64-windows-msvc/c/synchapi.cr

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "c/int_safe"
2+
3+
lib LibC
4+
fun Sleep(dwMilliseconds : DWORD)
5+
end

Diff for: ‎src/prelude.cr

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ require "lib_c"
1818
require "macros"
1919
require "object"
2020
require "comparable"
21-
require "windows_stubs"
21+
{% if flag?(:win32) %}
22+
require "windows_stubs"
23+
{% end %}
2224
require "exception"
2325
require "iterable"
2426
require "iterator"

Diff for: ‎src/windows_stubs.cr

+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "c/synchapi"
2+
13
struct CallStack
24
def self.skip(*args)
35
# do nothing
@@ -63,3 +65,11 @@ class Process
6365
LibC.exit(status)
6466
end
6567
end
68+
69+
def sleep(seconds : Number)
70+
sleep(seconds.seconds)
71+
end
72+
73+
def sleep(time : Time::Span)
74+
LibC.Sleep(time.total_milliseconds)
75+
end

0 commit comments

Comments
 (0)
Please sign in to comment.