[前][次][番号順一覧][スレッド一覧]

ruby-changes:38943

From: nobu <ko1@a...>
Date: Thu, 25 Jun 2015 15:32:45 +0900 (JST)
Subject: [ruby-changes:38943] nobu:r51024 (trunk): random.c: refactor

nobu	2015-06-25 15:32:23 +0900 (Thu, 25 Jun 2015)

  New Revision: 51024

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51024

  Log:
    random.c: refactor
    
    * random.c (fill_random_bytes): separate non-raced and raced
      conditions, on Windows.

  Modified files:
    trunk/random.c
Index: random.c
===================================================================
--- random.c	(revision 51023)
+++ random.c	(revision 51024)
@@ -486,17 +486,16 @@ fill_random_bytes(void *seed, size_t siz https://github.com/ruby/ruby/blob/trunk/random.c#L486
 	    prov = (HCRYPTPROV)INVALID_HANDLE_VALUE;
 	}
 	old_prov = (HCRYPTPROV)ATOMIC_PTR_CAS(perm_prov, 0, prov);
-	if (prov == (HCRYPTPROV)INVALID_HANDLE_VALUE) {
-	    if (old_prov) prov = old_prov;
-	}
-	else {
-	    if (!old_prov) {
+	if (LIKELY(!old_prov)) { /* no other threads acquried */
+	    if (prov != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
 		rb_gc_register_mark_object(Data_Wrap_Struct(0, 0, release_crypt, &perm_prov));
 	    }
-	    else {
+	}
+	else {			/* another thread acquried */
+	    if (prov != (HCRYPTPROV)INVALID_HANDLE_VALUE) {
 		CryptReleaseContext(prov, 0);
-		prov = old_prov;
 	    }
+	    prov = old_prov;
 	}
     }
     if (prov == (HCRYPTPROV)INVALID_HANDLE_VALUE) return -1;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]