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

ruby-changes:26032

From: kosaki <ko1@a...>
Date: Sat, 1 Dec 2012 03:55:39 +0900 (JST)
Subject: [ruby-changes:26032] kosaki:r38089 (trunk): * lib/sync.rb (Sync_m#sync_synchronize): add Thread.async_interrupt_timing

kosaki	2012-12-01 03:55:28 +0900 (Sat, 01 Dec 2012)

  New Revision: 38089

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

  Log:
    * lib/sync.rb (Sync_m#sync_synchronize): add Thread.async_interrupt_timing
      for protecting from async interrupt.
    * lib/sync.rb (Sync_m#sync_lock): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/lib/sync.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38088)
+++ ChangeLog	(revision 38089)
@@ -1,3 +1,9 @@
+Sat Dec  1 03:49:45 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
+
+	* lib/sync.rb (Sync_m#sync_synchronize): add Thread.async_interrupt_timing
+	  for protecting from async interrupt.
+	* lib/sync.rb (Sync_m#sync_lock): ditto.
+
 Sat Dec  1 03:38:04 2012  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* lib/thread.rb (ConditionVariable#broadcast): s/RuntimeError/StandardError/
Index: lib/sync.rb
===================================================================
--- lib/sync.rb	(revision 38088)
+++ lib/sync.rb	(revision 38089)
@@ -135,25 +135,26 @@
 
   def sync_lock(m = EX)
     return unlock if m == UN
-
-    while true
-      @sync_mutex.synchronize do
-        begin
-          if sync_try_lock_sub(m)
-            return self
-          else
-            if sync_sh_locker[Thread.current]
-              sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
-              sync_sh_locker.delete(Thread.current)
+    Thread.async_interrupt_timing(StandardError => :on_blocking) do
+      while true
+        @sync_mutex.synchronize do
+          begin
+            if sync_try_lock_sub(m)
+              return self
             else
-              unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
-                sync_waiting.push Thread.current
+              if sync_sh_locker[Thread.current]
+                sync_upgrade_waiting.push [Thread.current, sync_sh_locker[Thread.current]]
+                sync_sh_locker.delete(Thread.current)
+              else
+                unless sync_waiting.include?(Thread.current) || sync_upgrade_waiting.reverse_each.any?{|w| w.first == Thread.current }
+                  sync_waiting.push Thread.current
+                end
               end
+              @sync_mutex.sleep
             end
-            @sync_mutex.sleep
+          ensure
+            sync_waiting.delete(Thread.current)
           end
-        ensure
-          sync_waiting.delete(Thread.current)
         end
       end
     end
@@ -226,11 +227,13 @@
   end
 
   def sync_synchronize(mode = EX)
-    sync_lock(mode)
-    begin
-      yield
-    ensure
-      sync_unlock
+    Thread.async_interrupt_timing(StandardError => :on_blocking) do
+      sync_lock(mode)
+      begin
+        yield
+      ensure
+        sync_unlock
+      end
     end
   end
 

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

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