os/ossrv/genericopenlibs/openenvcore/libc/src/nice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // Name        : nice.cpp
    15 // Part of     : LIBC
    16 // Contains the source for fchdir
    17 // Version     : 1.0
    18 //
    19 
    20 
    21 
    22 #include <sys/time.h>
    23 #include <sys/resource.h>
    24 #include <errno.h>
    25 #include <e32std.h>
    26 #include <e32const.h>
    27 #include <unistd.h>
    28 
    29 extern "C" {
    30 
    31 /*
    32 The function nice() increases or decreases the priority value by
    33 adding the value 'incr' to the current priority.
    34 It internally uses getpriority and setpriority to set the priority 
    35 to new value.
    36 It returns the new value of the priority, which shall be in the range 
    37 of -15 to 19. -1 is a legitimate return value, so the user has to check 
    38 the errno to be sure of failure.
    39 */
    40 EXPORT_C int nice(int incr)
    41 	{
    42 	
    43 	int retGetPri = -1;
    44 	int retSetPri = -1;
    45 	int retVal 	  = -1;
    46 	
    47 	if(((retGetPri = getpriority(PRIO_PROCESS, 0)) == -1) && (errno))
    48 		{
    49 		errno = ENOSYS;
    50 		}
    51 	else
    52 		{
    53 		retSetPri = setpriority(PRIO_PROCESS, 0, retGetPri + incr);
    54 		if(!retSetPri)
    55 			{
    56 			retVal = 0;
    57 			}
    58 		}
    59 	return retVal;
    60 	}
    61 
    62 } //extern "C"