Skip to content

Commit

Permalink
Enable Mutex on Windows (#12213)
Browse files Browse the repository at this point in the history
This enables the fiber-safe `Mutex` on Windows and removes the stub implementation. It is mostly unrelated to [`Thread::Mutex`](#11647).

The standard library uses `Mutex` in `Log::SyncDispatcher`; it does not seem to break. (On the other hand, the specs for `Log::AsyncDispatcher` require non-blocking pipes, which are not available yet.)
  • Loading branch information
HertzDevil authored Jul 15, 2022
1 parent 305f081 commit c19df0b
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 32 deletions.
2 changes: 1 addition & 1 deletion spec/win32_std_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ require "./std/mime/multipart/builder_spec.cr"
require "./std/mime/multipart/parser_spec.cr"
require "./std/mime/multipart_spec.cr"
require "./std/mime_spec.cr"
# require "./std/mutex_spec.cr" (failed codegen)
require "./std/mutex_spec.cr"
require "./std/named_tuple_spec.cr"
require "./std/number_spec.cr"
require "./std/oauth/access_token_spec.cr"
Expand Down
1 change: 1 addition & 0 deletions src/crystal/system/win32/process.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "c/processthreadsapi"
require "c/handleapi"
require "c/synchapi"
require "process/shell"

struct Crystal::System::Process
Expand Down
4 changes: 1 addition & 3 deletions src/prelude.cr
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ require "intrinsics"
require "io"
require "kernel"
require "math/math"
{% unless flag?(:win32) %}
require "mutex"
{% end %}
require "mutex"
require "named_tuple"
require "nil"
require "humanize"
Expand Down
28 changes: 0 additions & 28 deletions src/windows_stubs.cr
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
require "c/synchapi"

class Mutex
enum Protection
Checked
Reentrant
Unchecked
end

def initialize(@protection : Protection = :checked)
end

def lock
end

def unlock
end

def synchronize
lock
begin
yield
ensure
unlock
end
end
end

enum Signal
KILL = 0
end

0 comments on commit c19df0b

Please sign in to comment.