about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-03-17 01:57:34 +0000
committerEric Wong <e@80x24.org>2017-03-18 01:13:59 +0000
commit33a2540fb12cec9052f9b92810f2a9aa5b395911 (patch)
treefbac9c92882d164b9bcb30e01b198b39ca2d9c75
parentedb5542d0d5911d2712321db469c6bddf07e2d21 (diff)
downloadraindrops-33a2540fb12cec9052f9b92810f2a9aa5b395911.tar.gz
errno is in the thread-specific section and it is slightly
cheaper to read it once rather than twice.  Recent versions
of mainline Ruby itself follows the same pattern.
-rw-r--r--ext/raindrops/raindrops.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/ext/raindrops/raindrops.c b/ext/raindrops/raindrops.c
index 390b8b8..9090839 100644
--- a/ext/raindrops/raindrops.c
+++ b/ext/raindrops/raindrops.c
@@ -117,7 +117,9 @@ retry:
         r->drops = mmap(NULL, tmp,
                         PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0);
         if (r->drops == MAP_FAILED) {
-                if ((errno == EAGAIN || errno == ENOMEM) && tries-- > 0) {
+                int err = errno;
+
+                if ((err == EAGAIN || err == ENOMEM) && tries-- > 0) {
                         rb_gc();
                         goto retry;
                 }
@@ -153,7 +155,9 @@ static void resize(struct raindrops *r, size_t new_rd_size)
 
         rv = mremap(old_address, old_size, new_size, MREMAP_MAYMOVE);
         if (rv == MAP_FAILED) {
-                if (errno == EAGAIN || errno == ENOMEM) {
+                int err = errno;
+
+                if (err == EAGAIN || err == ENOMEM) {
                         rb_gc();
                         rv = mremap(old_address, old_size, new_size, 0);
                 }