¿Dónde puedo encontrar el código de la función "__swtch_pri"?

where can I find the realization code of the function __swtch_pri ?

void
__spin_lock_solid (spin_lock_t *lock)
{
  while (__spin_lock_locked (lock) || ! __spin_try_lock (lock))
    /* Yield to another thread (system call).  */
    __swtch_pri (0);
}

Only find declaration in glibc, see below.

/* Attempt to context switch the current thread off the processor.  Lower
the thread's priority as much as possible.  The thread's priority will
be restored when it runs again.  PRIORITY is currently unused.  Return
true if there are other threads that can be run and false if not.  */

extern boolean_t swtch_pri (int priority);

extern boolean_t __swtch_pri (int priority);

preguntado el 25 de agosto de 12 a las 07:08

Searches across various *X kernel sources (including references made by glibc) could be simplified using fxr.watson.org. En este caso fxr.watson.org/fxr/trackident?i=swtch_pri ayudaría. -

Thanks alk. This web site is great!!! -

2 Respuestas

It's in the Mach kernel. Specifically, see /hurd/gnumach/kern/syscall_subr.c. The GNU C library supports a great many operating system kernels other than just Linux and you've probably found this in one of the OS-specific source files.

Respondido 25 ago 12, 07:08

A quick Google search suggests that it is a Mach system trap (system call). Thus, the function implementation is likely to be a short assembly stub that just traps into the kernel; the real implementation would be in the kernel code.

De http://www.gnu.org/software/hurd/gnumach-doc/Hand_002dOff-Scheduling.html:

— Function: boolean_t swtch ()

The system trap swtch attempts to switch the current thread off the processor. The return value indicates if more than the current thread is running in the processor set. This is useful for lock management routines.

The call returns FALSE if the thread is justified in becoming a resource hog by continuing to spin because there's nothing else useful that the processor could do. TRUE is returned if the thread should make one more check on the lock and then be a good citizen and really suspend.

— Function: boolean_t swtch_pri (int priority)

The system trap swtch_pri attempts to switch the current thread off the processor as swtch does, but depressing the priority of the thread to the minimum possible value during the time. priority is not used currently.

The return value is as for swtch.

Respondido el 20 de junio de 20 a las 10:06

I didn't find __swtch_pri or swtch_pri with grep in linux-2.6.32.12-0.7. where is the actual code? - Daniel

It's not in Linux; it's in the Mach operating system. The code you're looking at above is probably specific to Mach (is it mach/spin-solid.c?) - neonneo

Thanks nneonneo. You are right. I have to check mack kernel instead. Thanks a lot. - Daniel

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.