tracker-0.16.2/src/libtracker-common/tracker-sched.c

No issues found

 1 /*
 2  * Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
 3  *
 4  * This library is free software; you can redistribute it and/or
 5  * modify it under the terms of the GNU Lesser General Public
 6  * License as published by the Free Software Foundation; either
 7  * version 2.1 of the License, or (at your option) any later version.
 8  *
 9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA  02110-1301, USA.
18  */
19 
20 #include "config.h"
21 
22 #ifdef __linux__
23 
24 #ifndef _GNU_SOURCE
25 #define _GNU_SOURCE
26 #endif
27 
28 #include <errno.h>
29 #include <sched.h>
30 
31 #include <glib.h>
32 
33 #include "tracker-sched.h"
34 
35 gboolean
36 tracker_sched_idle (void)
37 {
38 	struct sched_param sp;
39 
40 	/* Set process scheduling parameters:
41 	 * This is used so we don't steal scheduling priority from
42 	 * the most important applications - like the phone
43 	 * application which has a real time requirement here. This
44 	 * is detailed in Nokia bug #95573
45 	 */
46 	g_message ("Setting scheduler policy to SCHED_IDLE");
47 
48 	if (sched_getparam (0, &sp) == 0) {
49 		if (sched_setscheduler (0, SCHED_IDLE, &sp) != 0) {
50 //LCOV_EXCL_START
51 			const gchar *str = g_strerror (errno);
52 
53 			g_warning ("Could not set scheduler policy, %s",
54 			           str ? str : "no error given");
55 
56 			return FALSE;
57 		}
58 	} else {
59 		const gchar *str = g_strerror (errno);
60 
61 		g_warning ("Could not get scheduler policy, %s",
62 		           str ? str : "no error given");
63 
64 		return FALSE;
65 	}
66 //LCOV_EXCL_END
67 
68 	return TRUE;
69 }
70 
71 #else /* __linux__ */
72 
73 #include <glib.h>
74 
75 #include "tracker-sched.h"
76 
77 gboolean
78 tracker_sched_idle (void)
79 {
80 	return TRUE;
81 }
82 
83 #endif /* __linux__ */