Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fiber: visual code fixes #4693

Merged
merged 1 commit into from Jul 13, 2017

Conversation

bew
Copy link
Contributor

@bew bew commented Jul 9, 2017

Reasons of changes

--- a/src/fiber.cr
+++ b/src/fiber.cr
@@ -28,7 +28,7 @@ class Fiber
     @stack_bottom = @stack + STACK_SIZE
     fiber_main = ->(f : Fiber) { f.run }
 
-    stack_ptr = @stack + STACK_SIZE - sizeof(Void*)
+    stack_ptr = @stack_bottom - sizeof(Void*)
 
     # Align the stack pointer to 16 bytes
     stack_ptr = Pointer(Void*).new(stack_ptr.address & ~0x0f_u64)

As @stack_bottom is defined 3 lines above as @stack + STACK_SIZE, I think we can use it instead of re-doing the addition.


--- a/src/fiber.cr
+++ b/src/fiber.cr
@@ -93,7 +93,8 @@ class Fiber
     @@stack_pool.pop? || LibC.mmap(nil, Fiber::STACK_SIZE,
       LibC::PROT_READ | LibC::PROT_WRITE,
       LibC::MAP_PRIVATE | LibC::MAP_ANON,
-      -1, 0).tap do |pointer|
+      -1, 0
+    ).tap do |pointer|
       raise Errno.new("Cannot allocate new fiber stack") if pointer == LibC::MAP_FAILED
       {% if flag?(:linux) %}
         LibC.madvise(pointer, Fiber::STACK_SIZE, LibC::MADV_NOHUGEPAGE)

This is a visual improvement, checkout the difference:

@@stack_pool.pop? || LibC.mmap(nil, Fiber::STACK_SIZE,
  LibC::PROT_READ | LibC::PROT_WRITE,
  LibC::MAP_PRIVATE | LibC::MAP_ANON,
  -1, 0).tap do |pointer|
  raise Errno.new("Cannot allocate new fiber stack") if pointer == LibC::MAP_FAILED
  {% if flag?(:linux) %}
    LibC.madvise(pointer, Fiber::STACK_SIZE, LibC::MADV_NOHUGEPAGE)
  {% end %}
  LibC.mprotect(pointer, 4096, LibC::PROT_NONE)
end

Against:

@@stack_pool.pop? || LibC.mmap(nil, Fiber::STACK_SIZE,
  LibC::PROT_READ | LibC::PROT_WRITE,
  LibC::MAP_PRIVATE | LibC::MAP_ANON,
  -1, 0
).tap do |pointer|
  raise Errno.new("Cannot allocate new fiber stack") if pointer == LibC::MAP_FAILED
  {% if flag?(:linux) %}
    LibC.madvise(pointer, Fiber::STACK_SIZE, LibC::MADV_NOHUGEPAGE)
  {% end %}
  LibC.mprotect(pointer, 4096, LibC::PROT_NONE)
end

I find the second easier to read, the endof the call and the start of the block is visually easier to locate.

Copy link
Contributor

@ggiraldez ggiraldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ggiraldez
Copy link
Contributor

ggiraldez commented Jul 10, 2017

Btw, the failed build seems to point to a bug in the compiler. Probably debugging info related, but it's a long shot.

@bew
Copy link
Contributor Author

bew commented Jul 13, 2017

Is it good to merge then?

@RX14
Copy link
Contributor

RX14 commented Jul 13, 2017

@bew i've restarted the build, if the build passes it's fine to merge.

@RX14 RX14 merged commit 944c083 into crystal-lang:master Jul 13, 2017
@RX14 RX14 added this to the Next milestone Jul 13, 2017
@bew bew deleted the fiber-little-fixes-while-reading branch July 13, 2017 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants