aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/lib/eina_sched.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/lib/eina_sched.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/lib/eina_sched.c')
-rw-r--r--libraries/eina/src/lib/eina_sched.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/libraries/eina/src/lib/eina_sched.c b/libraries/eina/src/lib/eina_sched.c
new file mode 100644
index 0000000..8c7f7fe
--- /dev/null
+++ b/libraries/eina/src/lib/eina_sched.c
@@ -0,0 +1,94 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2010 ProFUSION embedded systems
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;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#ifdef EFL_HAVE_POSIX_THREADS
24# include <pthread.h>
25# ifdef __linux__
26# include <sched.h>
27# include <sys/time.h>
28# include <sys/resource.h>
29# include <errno.h>
30# endif
31#endif
32
33#ifdef EFL_HAVE_WIN32_THREADS
34# ifndef WIN32_LEAN_AND_MEAN
35# define WIN32_LEAN_AND_MEAN
36# endif
37# include <windows.h>
38# undef WIN32_LEAN_AND_MEAN
39#endif
40
41#include "eina_sched.h"
42#include "eina_log.h"
43
44#define RTNICENESS 5
45#define NICENESS 5
46
47EAPI void
48eina_sched_prio_drop(void)
49{
50#ifdef EFL_HAVE_POSIX_THREADS
51 struct sched_param param;
52 int pol, prio, ret;
53 pthread_t pthread_id;
54
55 pthread_id = pthread_self();
56 ret = pthread_getschedparam(pthread_id, &pol, &param);
57 if (ret)
58 {
59 EINA_LOG_ERR("Unable to query sched parameters");
60 return;
61 }
62
63 if (EINA_UNLIKELY(pol == SCHED_RR || pol == SCHED_FIFO))
64 {
65 prio = sched_get_priority_max(pol);
66 param.sched_priority += RTNICENESS;
67 if (prio > 0 && param.sched_priority > prio)
68 param.sched_priority = prio;
69
70 pthread_setschedparam(pthread_id, pol, &param);
71 }
72# ifdef __linux__
73 else
74 {
75 errno = 0;
76 prio = getpriority(PRIO_PROCESS, 0);
77 if (errno == 0)
78 {
79 prio += NICENESS;
80 if (prio > 19)
81 prio = 19;
82
83 setpriority(PRIO_PROCESS, 0, prio);
84 }
85 }
86# endif
87#elif defined EFL_HAVE_WIN32_THREADS
88 if (!SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL))
89 EINA_LOG_ERR("Can not set thread priority");
90#else
91 EINA_LOG_ERR("Eina does not have support for threads enabled"
92 "or it doesn't support setting scheduler priorities");
93#endif
94}