diff options
Diffstat (limited to 'src/universe.cpp')
-rw-r--r-- | src/universe.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/src/universe.cpp b/src/universe.cpp index 66da147..4c53987 100644 --- a/src/universe.cpp +++ b/src/universe.cpp | |||
@@ -43,6 +43,35 @@ static constexpr UniqueKey UNIVERSE_LIGHT_REGKEY{ 0x3663C07C742CEB81ull }; | |||
43 | 43 | ||
44 | // ################################################################################################ | 44 | // ################################################################################################ |
45 | 45 | ||
46 | Universe::Universe() | ||
47 | { | ||
48 | //--- | ||
49 | // Linux needs SCHED_RR to change thread priorities, and that is only | ||
50 | // allowed for sudo'ers. SCHED_OTHER (default) has no priorities. | ||
51 | // SCHED_OTHER threads are always lower priority than SCHED_RR. | ||
52 | // | ||
53 | // ^-- those apply to 2.6 kernel. IF **wishful thinking** these | ||
54 | // constraints will change in the future, non-sudo priorities can | ||
55 | // be enabled also for Linux. | ||
56 | // | ||
57 | #ifdef PLATFORM_LINUX | ||
58 | // If lower priorities (-2..-1) are wanted, we need to lift the main | ||
59 | // thread to SCHED_RR and 50 (medium) level. Otherwise, we're always below | ||
60 | // the launched threads (even -2). | ||
61 | // | ||
62 | #ifdef LINUX_SCHED_RR | ||
63 | if (m_sudo) | ||
64 | { | ||
65 | struct sched_param sp; | ||
66 | sp.sched_priority = _PRIO_0; | ||
67 | PT_CALL(pthread_setschedparam(pthread_self(), SCHED_RR, &sp)); | ||
68 | } | ||
69 | #endif // LINUX_SCHED_RR | ||
70 | #endif // PLATFORM_LINUX | ||
71 | } | ||
72 | |||
73 | // ################################################################################################ | ||
74 | |||
46 | // only called from the master state | 75 | // only called from the master state |
47 | Universe* universe_create(lua_State* L) | 76 | Universe* universe_create(lua_State* L) |
48 | { | 77 | { |
@@ -51,7 +80,7 @@ Universe* universe_create(lua_State* L) | |||
51 | U->Universe::Universe(); | 80 | U->Universe::Universe(); |
52 | STACK_CHECK_START_REL(L, 1); | 81 | STACK_CHECK_START_REL(L, 1); |
53 | UNIVERSE_FULL_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); | 82 | UNIVERSE_FULL_REGKEY.setValue(L, [](lua_State* L) { lua_pushvalue(L, -2); }); |
54 | UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { lua_pushlightuserdata( L, U); }); | 83 | UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { lua_pushlightuserdata(L, U); }); |
55 | STACK_CHECK(L, 1); | 84 | STACK_CHECK(L, 1); |
56 | return U; | 85 | return U; |
57 | } | 86 | } |
@@ -62,8 +91,8 @@ void universe_store(lua_State* L, Universe* U) | |||
62 | { | 91 | { |
63 | ASSERT_L(!U || universe_get(L) == nullptr); | 92 | ASSERT_L(!U || universe_get(L) == nullptr); |
64 | STACK_CHECK_START_REL(L, 0); | 93 | STACK_CHECK_START_REL(L, 0); |
65 | UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata( L, U) : lua_pushnil( L); }); | 94 | UNIVERSE_LIGHT_REGKEY.setValue(L, [U](lua_State* L) { U ? lua_pushlightuserdata(L, U) : lua_pushnil(L); }); |
66 | STACK_CHECK( L, 0); | 95 | STACK_CHECK(L, 0); |
67 | } | 96 | } |
68 | 97 | ||
69 | // ################################################################################################ | 98 | // ################################################################################################ |
@@ -72,6 +101,6 @@ Universe* universe_get(lua_State* L) | |||
72 | { | 101 | { |
73 | STACK_CHECK_START_REL(L, 0); | 102 | STACK_CHECK_START_REL(L, 0); |
74 | Universe* const universe{ UNIVERSE_LIGHT_REGKEY.readLightUserDataValue<Universe>(L) }; | 103 | Universe* const universe{ UNIVERSE_LIGHT_REGKEY.readLightUserDataValue<Universe>(L) }; |
75 | STACK_CHECK( L, 0); | 104 | STACK_CHECK(L, 0); |
76 | return universe; | 105 | return universe; |
77 | } | 106 | } |