Skip to content

Commit 2014073

Browse files
committed
Add nice/ioprio to MythSystem
Allows a MythSystem user to specify nice and io priority values that a task should run at. These will be set after the fork, so they will not disrupt instances of a shared thread that would otherwise not allow the current mechanism of niceing the thread prior to running MythSystem.
1 parent 6071157 commit 2014073

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

mythtv/libs/libmythbase/mythsystem.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
void MythSystem::initializePrivate(void)
3838
{
39+
m_nice = 0;
40+
m_ioprio = 0;
3941
#if CONFIG_CYGWIN || defined(_WIN32)
4042
d = new MythSystemWindows(this);
4143
#else
@@ -131,6 +133,24 @@ void MythSystem::SetDirectory(const QString &directory)
131133
m_directory = QString(directory);
132134
}
133135

136+
bool MythSystem::SetNice(int nice)
137+
{
138+
if( !d || (GetStatus() != GENERIC_EXIT_START) )
139+
return false;
140+
141+
m_nice = nice;
142+
return true;
143+
}
144+
145+
bool MythSystem::SetIOPrio(int prio)
146+
{
147+
if( !d || (GetStatus() != GENERIC_EXIT_START) )
148+
return false;
149+
150+
m_ioprio = prio;
151+
return true;
152+
}
153+
134154
/** \fn MythSystem::Run()
135155
* \brief Runs a command inside the /bin/sh shell. Returns immediately
136156
*/

mythtv/libs/libmythbase/mythsystem.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class MBASE_PUBLIC MythSystem : public QObject
5050
void SetCommand(const QString &, uint);
5151
void SetCommand(const QString &, const QStringList &, uint);
5252
void SetDirectory(const QString &);
53+
bool SetNice(int nice);
54+
bool SetIOPrio(int prio);
5355

5456
void Run(time_t timeout = 0);
5557
uint Wait(time_t timeout = 0);
@@ -91,6 +93,9 @@ class MBASE_PUBLIC MythSystem : public QObject
9193
QStringList &GetArgs() { return m_args; };
9294
void SetArgs(QStringList &args) { m_args = args; };
9395

96+
int GetNice() { return m_nice; };
97+
int GetIOPrio() { return m_ioprio; };
98+
9499
QBuffer *GetBuffer(int index) { return &m_stdbuff[index]; };
95100

96101
void Unlock() { m_semReady.release(1); };
@@ -118,6 +123,9 @@ class MBASE_PUBLIC MythSystem : public QObject
118123
QStringList m_args;
119124
QString m_directory;
120125

126+
int m_nice;
127+
int m_ioprio;
128+
121129
Setting_t m_settings;
122130
QBuffer m_stdbuff[3];
123131
};

mythtv/libs/libmythbase/mythversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// Update this whenever the plug-in API changes.
1313
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
1414
/// libmythui class methods used by plug-ins.
15-
#define MYTH_BINARY_VERSION "0.25.20110910-2"
15+
#define MYTH_BINARY_VERSION "0.25.20110920-1"
1616

1717
/** \brief Increment this whenever the MythTV network protocol changes.
1818
*

mythtv/libs/libmythbase/system-unix.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Own header
33
#include "mythsystem.h"
44
#include "system-unix.h"
5+
#include "util.h"
56

67
// compat header
78
#include "compat.h"
@@ -676,6 +677,9 @@ void MythSystemUnix::Fork(time_t timeout)
676677
// check before fork to avoid QString use in child
677678
bool setpgidsetting = GetSetting("SetPGID");
678679

680+
int niceval = m_parent->GetNice();
681+
int ioprioval = m_parent->GetIOPrio();
682+
679683
/* Do this before forking in case the child miserably fails */
680684
m_timeout = timeout;
681685
if( timeout )
@@ -801,6 +805,12 @@ void MythSystemUnix::Fork(time_t timeout)
801805
<< strerror(errno) << endl;
802806
}
803807

808+
/* Set nice and ioprio values if non-default */
809+
if (niceval)
810+
myth_nice(niceval);
811+
if (ioprioval)
812+
myth_ioprio(ioprioval);
813+
804814
/* run command */
805815
if( execv(command, cmdargs) < 0 )
806816
{

0 commit comments

Comments
 (0)