delay a few things on startup, such as setting the visibility mode, which ensures...
[personal-kdebase.git] / runtime / nepomuk / services / strigi / priority.cpp
blob1ac28b10c862e7644a9332b2a3e668d99cc87b0e
1 /* This file is part of the KDE Project
2 Copyright (c) 2008 Sebastian Trueg <trueg@kde.org>
4 Parts of this file are based on code from Strigi
5 Copyright (C) 2006-2007 Jos van den Oever <jos@vandenoever.info>
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License version 2 as published by the Free Software Foundation.
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
22 #include "priority.h"
24 #ifndef _GNU_SOURCE
25 #define _GNU_SOURCE
26 #endif
28 #include <QtCore/QDebug>
30 #include <sys/time.h>
31 #include <sys/resource.h>
33 #include <unistd.h>
34 #include <sys/syscall.h>
35 #include <errno.h>
37 #include <sched.h>
40 #ifdef SYS_ioprio_set
41 namespace {
42 #ifndef IOPRIO_CLASS_IDLE
43 enum {
44 IOPRIO_CLASS_NONE,
45 IOPRIO_CLASS_RT,
46 IOPRIO_CLASS_BE,
47 IOPRIO_CLASS_IDLE
49 #endif
51 #ifndef IOPRIO_WHO_PROCESS
52 enum {
53 IOPRIO_WHO_PROCESS = 1,
54 IOPRIO_WHO_PGRP,
55 IOPRIO_WHO_USER
57 #endif
59 #ifndef IOPRIO_CLASS_SHIFT
60 const int IOPRIO_CLASS_SHIFT = 13;
61 #endif
63 #endif
66 bool lowerIOPriority()
68 #ifdef SYS_ioprio_set
69 if ( syscall( SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, IOPRIO_CLASS_IDLE<<IOPRIO_CLASS_SHIFT ) < 0 ) {
70 qDebug( "cannot set io scheduling to idle (%s). Trying best effort.\n", strerror( errno ));
71 if ( syscall( SYS_ioprio_set, IOPRIO_WHO_PROCESS, 0, 7|IOPRIO_CLASS_BE<<IOPRIO_CLASS_SHIFT ) < 0 ) {
72 qDebug( "cannot set io scheduling to best effort.\n");
73 return false;
76 return true;
77 #else
78 return false;
79 #endif
83 bool lowerPriority()
85 return !setpriority( PRIO_PROCESS, 0, 19 );
89 // FIXME: is this really useful? Should we better use SCHED_IDLE?
90 bool lowerSchedulingPriority()
92 #ifdef SCHED_BATCH
93 struct sched_param param;
94 memset( &param, 0, sizeof(param) );
95 param.sched_priority = 0;
96 return !sched_setscheduler( 0, SCHED_BATCH, &param );
97 #else
98 return false;
99 #endif