summaryrefslogtreecommitdiff
path: root/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
diff options
context:
space:
mode:
authorraveit65 <[email protected]>2020-11-20 16:14:42 +0100
committerGitHub <[email protected]>2020-11-20 16:14:42 +0100
commit3dd33d455f60ccb07ca57b2ea083563efa51a252 (patch)
tree8580a55e0f9c70dbe67efb6a35af58c14b10d5c0 /cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
parent882de1f0e1237dac2512e4ecf205b21d073c98c5 (diff)
downloadmate-applets-3dd33d455f60ccb07ca57b2ea083563efa51a252.tar.bz2
mate-applets-3dd33d455f60ccb07ca57b2ea083563efa51a252.tar.xz
Cpufreq code style
- tabs to spaces - 4 spaces at the beginning of a line
Diffstat (limited to 'cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c')
-rw-r--r--cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c237
1 files changed, 120 insertions, 117 deletions
diff --git a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
index 36ab100f..7167eb55 100644
--- a/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
+++ b/cpufreq/src/cpufreq-selector/cpufreq-selector-libcpufreq.c
@@ -31,12 +31,15 @@
#include "cpufreq-selector-libcpufreq.h"
-static gboolean cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error);
-static gboolean cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error);
+static gboolean
+cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
+ guint frequency,
+ GError **error);
+
+static gboolean
+cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
+ const gchar *governor,
+ GError **error);
G_DEFINE_TYPE (CPUFreqSelectorLibcpufreq, cpufreq_selector_libcpufreq, CPUFREQ_TYPE_SELECTOR)
@@ -59,148 +62,148 @@ cpufreq_selector_libcpufreq_init (CPUFreqSelectorLibcpufreq *selector)
static void
cpufreq_selector_libcpufreq_class_init (CPUFreqSelectorLibcpufreqClass *klass)
{
- CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
+ CPUFreqSelectorClass *selector_class = CPUFREQ_SELECTOR_CLASS (klass);
- selector_class->set_frequency = cpufreq_selector_libcpufreq_set_frequency;
- selector_class->set_governor = cpufreq_selector_libcpufreq_set_governor;
+ selector_class->set_frequency = cpufreq_selector_libcpufreq_set_frequency;
+ selector_class->set_governor = cpufreq_selector_libcpufreq_set_governor;
}
CPUFreqSelector *
cpufreq_selector_libcpufreq_new (guint cpu)
{
- CPUFreqSelector *selector;
+ CPUFreqSelector *selector;
- selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ,
- "cpu", cpu,
- NULL));
+ selector = CPUFREQ_SELECTOR (g_object_new (CPUFREQ_TYPE_SELECTOR_LIBCPUFREQ,
+ "cpu", cpu,
+ NULL));
- return selector;
+ return selector;
}
-static guint
+static guint
cpufreq_selector_libcpufreq_get_valid_frequency (CPUFreqSelectorLibcpufreq *selector,
- guint frequency)
+ guint frequency)
{
- guint cpu;
- gint dist = G_MAXINT;
- guint retval = 0;
- CPUFreqFrequencyList *freqs, *freq;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- freqs = cpufreq_get_available_frequencies (cpu);
- if (!freqs)
- return 0;
-
- for (freq = freqs; freq; freq = freq->next) {
- guint current_dist;
-
- if (freq->frequency == frequency) {
- cpufreq_put_available_frequencies (freqs);
-
- return frequency;
- }
-
- current_dist = abs ((int)freq->frequency - (int)frequency);
- if (current_dist < dist) {
- dist = current_dist;
- retval = freq->frequency;
- }
- }
-
- return retval;
+ guint cpu;
+ gint dist = G_MAXINT;
+ guint retval = 0;
+ CPUFreqFrequencyList *freqs, *freq;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ freqs = cpufreq_get_available_frequencies (cpu);
+ if (!freqs)
+ return 0;
+
+ for (freq = freqs; freq; freq = freq->next) {
+ guint current_dist;
+
+ if (freq->frequency == frequency) {
+ cpufreq_put_available_frequencies (freqs);
+
+ return frequency;
+ }
+
+ current_dist = abs ((int)freq->frequency - (int)frequency);
+ if (current_dist < dist) {
+ dist = current_dist;
+ retval = freq->frequency;
+ }
+ }
+
+ return retval;
}
static gboolean
cpufreq_selector_libcpufreq_set_frequency (CPUFreqSelector *selector,
- guint frequency,
- GError **error)
+ guint frequency,
+ GError **error)
{
- guint freq;
- guint cpu;
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- freq = cpufreq_selector_libcpufreq_get_valid_frequency (CPUFREQ_SELECTOR_LIBCPUFREQ (selector),
- frequency);
- if (cpufreq_set_frequency (cpu, freq) != 0) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_SET_FREQUENCY,
- "Cannot set frequency '%d'",
- frequency);
-
- return FALSE;
- }
-
- return TRUE;
+ guint freq;
+ guint cpu;
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ freq = cpufreq_selector_libcpufreq_get_valid_frequency (CPUFREQ_SELECTOR_LIBCPUFREQ (selector),
+ frequency);
+ if (cpufreq_set_frequency (cpu, freq) != 0) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_SET_FREQUENCY,
+ "Cannot set frequency '%d'",
+ frequency);
+
+ return FALSE;
+ }
+
+ return TRUE;
}
static gboolean
cpufreq_selector_libcpufreq_validate_governor (CPUFreqSelectorLibcpufreq *selector,
- const gchar *governor)
+ const gchar *governor)
{
- guint cpu;
- CPUFreqGovernorList *govs, *gov;
+ guint cpu;
+ CPUFreqGovernorList *govs, *gov;
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
- govs = cpufreq_get_available_governors (cpu);
- if (!govs)
- return FALSE;
+ govs = cpufreq_get_available_governors (cpu);
+ if (!govs)
+ return FALSE;
- for (gov = govs; gov; gov = gov->next) {
- if (g_ascii_strcasecmp (gov->governor, governor) == 0) {
- cpufreq_put_available_governors (govs);
+ for (gov = govs; gov; gov = gov->next) {
+ if (g_ascii_strcasecmp (gov->governor, governor) == 0) {
+ cpufreq_put_available_governors (govs);
- return TRUE;
- }
- }
+ return TRUE;
+ }
+ }
- cpufreq_put_available_governors (govs);
+ cpufreq_put_available_governors (govs);
- return FALSE;
+ return FALSE;
}
static gboolean
cpufreq_selector_libcpufreq_set_governor (CPUFreqSelector *selector,
- const gchar *governor,
- GError **error)
+ const gchar *governor,
+ GError **error)
{
- CPUFreqSelectorLibcpufreq *selector_libcpufreq;
- guint cpu;
-
- selector_libcpufreq = CPUFREQ_SELECTOR_LIBCPUFREQ (selector);
-
- if (!cpufreq_selector_libcpufreq_validate_governor (selector_libcpufreq, governor)) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- "Invalid governor '%s'",
- governor);
-
- return FALSE;
- }
-
- g_object_get (G_OBJECT (selector),
- "cpu", &cpu,
- NULL);
-
- if (cpufreq_modify_policy_governor (cpu, (gchar *)governor) != 0) {
- g_set_error (error,
- CPUFREQ_SELECTOR_ERROR,
- SELECTOR_ERROR_INVALID_GOVERNOR,
- "Invalid governor '%s'",
- governor);
-
- return FALSE;
- }
-
- return TRUE;
+ CPUFreqSelectorLibcpufreq *selector_libcpufreq;
+ guint cpu;
+
+ selector_libcpufreq = CPUFREQ_SELECTOR_LIBCPUFREQ (selector);
+
+ if (!cpufreq_selector_libcpufreq_validate_governor (selector_libcpufreq, governor)) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ "Invalid governor '%s'",
+ governor);
+
+ return FALSE;
+ }
+
+ g_object_get (G_OBJECT (selector),
+ "cpu", &cpu,
+ NULL);
+
+ if (cpufreq_modify_policy_governor (cpu, (gchar *)governor) != 0) {
+ g_set_error (error,
+ CPUFREQ_SELECTOR_ERROR,
+ SELECTOR_ERROR_INVALID_GOVERNOR,
+ "Invalid governor '%s'",
+ governor);
+
+ return FALSE;
+ }
+
+ return TRUE;
}