aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.c
diff options
context:
space:
mode:
authorBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2013-12-04 08:40:23 +0100
committerBenoit Germain <b n t DOT g e r m a i n AT g m a i l DOT c o m>2013-12-04 08:40:23 +0100
commit49f8b961cc230280e4cf86cc8d50c8a6d8687a65 (patch)
tree9b096414f00dc12a3893158622e150c7085b0599 /src/lanes.c
parent653dff5dc2c1a5764ef1afb6ffa5dd96758865ea (diff)
downloadlanes-49f8b961cc230280e4cf86cc8d50c8a6d8687a65.tar.gz
lanes-49f8b961cc230280e4cf86cc8d50c8a6d8687a65.tar.bz2
lanes-49f8b961cc230280e4cf86cc8d50c8a6d8687a65.zip
new API lanes.set_thread_priority()
Diffstat (limited to 'src/lanes.c')
-rw-r--r--src/lanes.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/lanes.c b/src/lanes.c
index ec7fd9e..467c920 100644
--- a/src/lanes.c
+++ b/src/lanes.c
@@ -35,10 +35,10 @@
35 * 35 *
36 * Defines: 36 * Defines:
37 * -DLINUX_SCHED_RR: all threads are lifted to SCHED_RR category, to 37 * -DLINUX_SCHED_RR: all threads are lifted to SCHED_RR category, to
38 * allow negative priorities (-2,-1) be used. Even without this, 38 * allow negative priorities [-3,-1] be used. Even without this,
39 * using priorities will require 'sudo' privileges on Linux. 39 * using priorities will require 'sudo' privileges on Linux.
40 * 40 *
41 * -DUSE_PTHREAD_TIMEDJOIN: use 'pthread_timedjoin_np()' for waiting 41 * -DUSE_PTHREAD_TIMEDJOIN: use 'pthread_timedjoin_np()' for waiting
42 * for threads with a timeout. This changes the thread cleanup 42 * for threads with a timeout. This changes the thread cleanup
43 * mechanism slightly (cleans up at the join, not once the thread 43 * mechanism slightly (cleans up at the join, not once the thread
44 * has finished). May or may not be a good idea to use it. 44 * has finished). May or may not be a good idea to use it.
@@ -52,7 +52,7 @@
52 * ... 52 * ...
53 */ 53 */
54 54
55char const* VERSION = "3.7.3"; 55char const* VERSION = "3.7.4";
56 56
57/* 57/*
58=============================================================================== 58===============================================================================
@@ -1734,6 +1734,20 @@ LUAG_FUNC( set_debug_threadname)
1734 return 0; 1734 return 0;
1735} 1735}
1736 1736
1737LUAG_FUNC( set_thread_priority)
1738{
1739 int const prio = luaL_checkint( L, 1);
1740 // public Lanes API accepts a generic range -3/+3
1741 // that will be remapped into the platform-specific scheduler priority scheme
1742 // On some platforms, -3 is equivalent to -2 and +3 to +2
1743 if( prio < THREAD_PRIO_MIN || prio > THREAD_PRIO_MAX)
1744 {
1745 return luaL_error( L, "priority out of range: %d..+%d (%d)", THREAD_PRIO_MIN, THREAD_PRIO_MAX, prio);
1746 }
1747 THREAD_SET_PRIORITY( prio);
1748 return 0;
1749}
1750
1737#if USE_DEBUG_SPEW 1751#if USE_DEBUG_SPEW
1738// can't use direct LUA_x errcode indexing because the sequence is not the same between Lua 5.1 and 5.2 :-( 1752// can't use direct LUA_x errcode indexing because the sequence is not the same between Lua 5.1 and 5.2 :-(
1739// LUA_ERRERR doesn't have the same value 1753// LUA_ERRERR doesn't have the same value
@@ -2693,6 +2707,7 @@ static const struct luaL_Reg lanes_functions [] = {
2693 {"linda", LG_linda}, 2707 {"linda", LG_linda},
2694 {"now_secs", LG_now_secs}, 2708 {"now_secs", LG_now_secs},
2695 {"wakeup_conv", LG_wakeup_conv}, 2709 {"wakeup_conv", LG_wakeup_conv},
2710 {"set_thread_priority", LG_set_thread_priority},
2696 {"nameof", luaG_nameof}, 2711 {"nameof", luaG_nameof},
2697 {"set_singlethreaded", LG_set_singlethreaded}, 2712 {"set_singlethreaded", LG_set_singlethreaded},
2698 {NULL, NULL} 2713 {NULL, NULL}
@@ -2754,16 +2769,18 @@ static void init_once_LOCKED( lua_State* L)
2754 // be enabled also for Linux. 2769 // be enabled also for Linux.
2755 // 2770 //
2756#ifdef PLATFORM_LINUX 2771#ifdef PLATFORM_LINUX
2757 sudo= geteuid()==0; // we are root? 2772 sudo = (geteuid() == 0); // we are root?
2758 2773
2759 // If lower priorities (-2..-1) are wanted, we need to lift the main 2774 // If lower priorities (-2..-1) are wanted, we need to lift the main
2760 // thread to SCHED_RR and 50 (medium) level. Otherwise, we're always below 2775 // thread to SCHED_RR and 50 (medium) level. Otherwise, we're always below
2761 // the launched threads (even -2). 2776 // the launched threads (even -2).
2762 // 2777 //
2763#ifdef LINUX_SCHED_RR 2778#ifdef LINUX_SCHED_RR
2764 if (sudo) { 2779 if( sudo)
2765 struct sched_param sp= {0}; sp.sched_priority= _PRIO_0; 2780 {
2766 PT_CALL( pthread_setschedparam( pthread_self(), SCHED_RR, &sp) ); 2781 struct sched_param sp;
2782 sp.sched_priority = _PRIO_0;
2783 PT_CALL( pthread_setschedparam( pthread_self(), SCHED_RR, &sp));
2767 } 2784 }
2768#endif // LINUX_SCHED_RR 2785#endif // LINUX_SCHED_RR
2769#endif // PLATFORM_LINUX 2786#endif // PLATFORM_LINUX