Skip to content

Commit 0ccc44b

Browse files
committed
TVar: use the new ThreadLocalVar to store the current transaction.
1 parent ae1dcc7 commit 0ccc44b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/concurrent/tvar.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
require 'concurrent/threadlocalvar'
2+
13
module Concurrent
24

35
ABORTED = Object.new
46

7+
CURRENT_TRANSACTION = ThreadLocalVar.new(nil)
8+
9+
UndoLogEntry = Struct.new(:tvar, :value)
10+
511
class TVar
612

713
def initialize(value)
@@ -30,8 +36,6 @@ def unsafe_value=(value)
3036

3137
end
3238

33-
UndoLogEntry = Struct.new(:tvar, :value)
34-
3539
class Transaction
3640

3741
LOCK = Mutex.new
@@ -74,11 +78,11 @@ def unlock
7478
end
7579

7680
def self.current
77-
Thread.current.thread_variable_get(:transaction)
81+
CURRENT_TRANSACTION.value
7882
end
7983

8084
def self.current=(transaction)
81-
Thread.current.thread_variable_set(:transaction, transaction)
85+
CURRENT_TRANSACTION.value = transaction
8286
end
8387

8488
end

0 commit comments

Comments
 (0)