aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.lua')
-rw-r--r--src/lanes.lua42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/lanes.lua b/src/lanes.lua
index 3ee959c..c5b3315 100644
--- a/src/lanes.lua
+++ b/src/lanes.lua
@@ -280,6 +280,10 @@ local opt_validators =
280 local tv = type(v_) 280 local tv = type(v_)
281 return (tv == "string") and v_ or raise_option_error("name", tv, v_) 281 return (tv == "string") and v_ or raise_option_error("name", tv, v_)
282 end, 282 end,
283 native_priority = function(v_)
284 local tv = type(v_)
285 return (tv == "number") and v_ or raise_option_error("native_priority", tv, v_)
286 end,
283 package = function(v_) 287 package = function(v_)
284 local tv = type(v_) 288 local tv = type(v_)
285 return (tv == "table") and v_ or raise_option_error("package", tv, v_) 289 return (tv == "table") and v_ or raise_option_error("package", tv, v_)
@@ -295,7 +299,7 @@ local opt_validators =
295} 299}
296 300
297-- ############################################################################################# 301-- #############################################################################################
298-- ##################################### lanes.gen() ########################################### 302-- ################################### lanes.gen/coro() ########################################
299-- ############################################################################################# 303-- #############################################################################################
300 304
301local process_gen_opt = function(...) 305local process_gen_opt = function(...)
@@ -367,9 +371,16 @@ local process_gen_opt = function(...)
367 opt[k] = validator(v) 371 opt[k] = validator(v)
368 end 372 end
369 end 373 end
374
375 -- special case: can't have priority and native_priority at the same time
376 if opt.priority and opt.native_priority then
377 error "priority and native_priority cannot be specified together"
378 end
370 return func, libs, opt 379 return func, libs, opt
371end -- process_gen_opt 380end -- process_gen_opt
372 381
382-- #################################################################################################
383
373-- lane_h[1..n]: lane results, same as via 'lane_h:join()' 384-- lane_h[1..n]: lane results, same as via 'lane_h:join()'
374-- lane_h[0]: can be read to make sure a thread has finished (gives the number of available results) 385-- lane_h[0]: can be read to make sure a thread has finished (gives the number of available results)
375-- lane_h[negative]: error message, without propagating the error 386-- lane_h[negative]: error message, without propagating the error
@@ -408,25 +419,28 @@ end -- process_gen_opt
408-- Calling with a function argument ('lane_func') ends the string/table 419-- Calling with a function argument ('lane_func') ends the string/table
409-- modifiers, and prepares a lane generator. 420-- modifiers, and prepares a lane generator.
410 421
411-- receives a sequence of strings and tables, plus a function 422local make_generator = function(is_coro_, ...)
412local gen = function(...)
413 local func, libs, opt = process_gen_opt(...) 423 local func, libs, opt = process_gen_opt(...)
414 local core_lane_new = assert(core.lane_new) 424 local core_lane_new = assert(core.lane_new)
415 local priority, globals, package, required, gc_cb, name, error_trace_level = opt.priority, opt.globals, opt.package or package, opt.required, opt.gc_cb, opt.name, error_trace_levels[opt.error_trace_level] 425 local prio_is_native = opt.native_priority and true or false
426 local priority, globals, package, required, gc_cb, name, error_trace_level = opt.priority or opt.native_priority, opt.globals, opt.package or package, opt.required, opt.gc_cb, opt.name, error_trace_levels[opt.error_trace_level]
416 return function(...) 427 return function(...)
417 -- must pass functions args last else they will be truncated to the first one 428 -- must pass functions args last else they will be truncated to the first one
418 return core_lane_new(func, libs, priority, globals, package, required, gc_cb, name, error_trace_level, false, ...) 429 return core_lane_new(func, libs, prio_is_native, priority, globals, package, required, gc_cb, name, error_trace_level, is_coro_, ...)
419 end 430 end
431end -- make_generator
432
433-- #################################################################################################
434
435-- receives a sequence of strings and tables, plus a function
436local gen = function(...)
437 return make_generator(false, ...)
420end -- gen() 438end -- gen()
421 439
440-- #################################################################################################
441
422local coro = function(...) 442local coro = function(...)
423 local func, libs, opt = process_gen_opt(...) 443 return make_generator(true, ...)
424 local core_lane_new = assert(core.lane_new)
425 local priority, globals, package, required, gc_cb, name, error_trace_level = opt.priority, opt.globals, opt.package or package, opt.required, opt.gc_cb, opt.name, error_trace_levels[opt.error_trace_level]
426 return function(...)
427 -- must pass functions args last else they will be truncated to the first one
428 return core_lane_new(func, libs, priority, globals, package, required, gc_cb, name, error_trace_level, true, ...)
429 end
430end -- coro() 444end -- coro()
431 445
432-- ################################################################################################# 446-- #################################################################################################
@@ -656,7 +670,8 @@ local configure_timers = function()
656 end 670 end
657 end 671 end
658 end -- timer_body() 672 end -- timer_body()
659 timer_lane = gen("lanes_core,table", { name = "LanesTimer", package = {}, priority = core.max_prio }, timer_body)() 673 local min_prio, max_prio = core.thread_priority_range()
674 timer_lane = gen("lanes_core,table", { name = "LanesTimer", package = {}, priority = max_prio }, timer_body)()
660 end -- first_time 675 end -- first_time
661 676
662 ----- 677 -----
@@ -876,6 +891,7 @@ local configure = function(settings_)
876 lanes.set_thread_affinity = core.set_thread_affinity 891 lanes.set_thread_affinity = core.set_thread_affinity
877 lanes.set_thread_priority = core.set_thread_priority 892 lanes.set_thread_priority = core.set_thread_priority
878 lanes.sleep = core.sleep 893 lanes.sleep = core.sleep
894 lanes.thread_priority_range = core.thread_priority_range
879 lanes.threads = core.threads or function() error "lane tracking is not available" end -- core.threads isn't registered if settings.track_lanes is false 895 lanes.threads = core.threads or function() error "lane tracking is not available" end -- core.threads isn't registered if settings.track_lanes is false
880 896
881 lanes.gen = gen 897 lanes.gen = gen