comparison src/luan/modules/Thread.luan @ 1099:a5406f076726

improve Thread.global
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 05 Apr 2017 16:24:02 -0600
parents bae2d0c2576c
children 772d16c89056
comparison
equal deleted inserted replaced
1098:bae624e455e2 1099:a5406f076726
10 Thread.fork = ThreadLuan.fork 10 Thread.fork = ThreadLuan.fork
11 Thread.schedule = ThreadLuan.schedule 11 Thread.schedule = ThreadLuan.schedule
12 12
13 13
14 Thread.global = {} -- shared across threads 14 Thread.global = {} -- shared across threads
15 local map = ThreadLuan.StringMap.new() 15 local map = ThreadLuan.GlobalMap.new()
16 local global_mt = {} 16 local global_mt = {}
17 set_metatable(Thread.global,global_mt) 17 set_metatable(Thread.global,global_mt)
18 18
19 function global_mt.__index(_,key) 19 function global_mt.__index(_,key)
20 return map.get(key) 20 return map.get(key)
21 end 21 end
22 22
23 function global_mt.__new_index(_,key,value) 23 function global_mt.__new_index(_,key,value)
24 map.set(key,value) 24 map.put(key,value)
25 end 25 end
26 26
27 function global_mt.get_timeout() 27 function Thread.get_global_timeout()
28 return map.timeout 28 return map.timeout
29 end 29 end
30 30
31 function global_mt.set_timeout(timeout) 31 function Thread.set_global_timeout(timeout)
32 map.timeout = timeout 32 map.timeout = timeout
33 end 33 end
34 34
35 function Thread.global_put(key,value)
36 return map.put(key,value)
37 end
35 38
36 return Thread 39 return Thread