* cygwin.din: Export getpriority and setpriority.

* fork.cc (fork_parent): Copy parent's nice value into child.
	* spawn.cc (spawn_guts): Ditto.
	* miscfuncs.cc (winprio_to_nice): New function.
	(nice_to_winprio): Ditto.
	* pinfo.cc (pinfo_init): If parent is not a Cygwin process, set
	default nice value according to current Win32 priority class.
	* pinfo.h (class _pinfo): Add nice member.
	* syscalls.cc (setpriority): New function, only implementing
	PRIO_PROCESS for now.
	(getpriority): Ditto.
	(nice): Just call setpriority.
	* wincap.h (wincaps::has_extended_priority_class): New element.
	* wincap.cc: Implement above element throughout.
	* winsup.h: Add prototypes for winprio_to_nice and nice_to_winprio.
	* include/limits.h (NZERO): New define.
	* include/cygwin/types.h (id_t): New datatype.
	* include/cygwin/version.h: Bump API minor version.
	* include/sys/resource.h: Add PRIO_XXX defines and prototypes for
	getpriority and setpriority.
This commit is contained in:
Corinna Vinschen
2005-01-25 22:45:11 +00:00
parent 17923424c4
commit 72c1491bba
15 changed files with 190 additions and 46 deletions

View File

@@ -2443,48 +2443,43 @@ memccpy (_PTR out, const _PTR in, int c, size_t len)
}
extern "C" int
nice (int incr)
setpriority (int which, id_t who, int value)
{
DWORD priority[] =
/* TODO: Support PRIO_PGRP and PRIO_USER. */
if (which != PRIO_PROCESS || (who != 0 && (pid_t) who != myself->pid))
{
IDLE_PRIORITY_CLASS,
IDLE_PRIORITY_CLASS,
NORMAL_PRIORITY_CLASS,
HIGH_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS,
REALTIME_PRIORITY_CLASS
};
int curr = 2;
switch (GetPriorityClass (hMainProc))
{
case IDLE_PRIORITY_CLASS:
curr = 1;
break;
case NORMAL_PRIORITY_CLASS:
curr = 2;
break;
case HIGH_PRIORITY_CLASS:
curr = 3;
break;
case REALTIME_PRIORITY_CLASS:
curr = 4;
break;
set_errno (EINVAL);
return -1;
}
if (incr > 0)
incr = -1;
else if (incr < 0)
incr = 1;
if (SetPriorityClass (hMainProc, priority[curr + incr]) == FALSE)
DWORD prio = nice_to_winprio (value);
if (SetPriorityClass (hMainProc, prio) == FALSE)
{
__seterrno ();
return -1;
}
myself->nice = value;
debug_printf ("Set nice to %d", myself->nice);
return 0;
}
extern "C" int
getpriority (int which, id_t who)
{
/* TODO: Support PRIO_PGRP and PRIO_USER. */
if (which != PRIO_PROCESS || (who != 0 && (pid_t) who != myself->pid))
{
set_errno (EINVAL);
return -1;
}
return myself->nice;
}
extern "C" int
nice (int incr)
{
return setpriority (PRIO_PROCESS, myself->pid, myself->nice + incr);
}
/*
* Find the first bit set in I.
*/
@@ -2588,7 +2583,7 @@ endutent ()
}
extern "C" void
utmpname (_CONST char *file)
utmpname (const char *file)
{
if (check_null_empty_str (file))
{