Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

cpu_switchto(9) [netbsd man page]

CPU_SWITCHTO(9) 					   BSD Kernel Developer's Manual					   CPU_SWITCHTO(9)

NAME
cpu_switchto -- machine-dependent LWP context switching interface SYNOPSIS
#include <sys/cpu.h> lwp_t * cpu_switchto(lwp_t *oldlwp, lwp_t *newlwp, bool returning); DESCRIPTION
The cpu_switchto() function saves the context of the LWP which is currently running on the processor, and restores the context of the LWP specified by newlwp. Remarks: 1. cpu_switchto() does not switch address spaces. 2. cpu_switchto() sets curlwp(9) to newlwp. If the architecture does non-interlocked adaptive mutex release, cpu_switchto() does an equivalent of membar_producer(3), before and after the modification of curlwp(9). 3. cpu_switchto() should be called at IPL_SCHED. When the function returns, the caller should lower the priority level as soon as possible. 4. cpu_switchto() might be called with spin mutexes held. The function takes the following arguments. oldlwp Specify the LWP from which the switch is going to be made, i.e., the calling LWP. If it was NULL, the context of the LWP currently running on this processor is not saved. newlwp Specify the LWP to which to switch. It must not be NULL. returning Only meaningful if the architecture implements fast software interrupts. If true, it indicates that oldlwp is a soft interrupt LWP that is blocking. It is a good indication that any kind of address space or user activity can be completely ignored. For example: ras_lookup(9), cache flushes, TLB wirings, adjusting lazy FPU state. All that is required is to restore the register state and stack, and return to the interrupted LWP. RETURN VALUES
The cpu_switchto() function does not return until another LWP calls cpu_switchto(). It returns the oldlwp argument of the cpu_switchto() which is called to switch back to our LWP. It is either a LWP which called cpu_switchto() to switch to us or NULL in case the LWP was exit- ing. SEE ALSO
membar_producer(3), swapcontext(3), intro(9), mutex(9), spl(9) BSD
June 2, 2011 BSD

Check Out this Related Man Page

_lwp_mutex_lock(2)						   System Calls 						_lwp_mutex_lock(2)

NAME
_lwp_mutex_lock, _lwp_mutex_unlock, _lwp_mutex_trylock - mutual exclusion SYNOPSIS
#include <sys/lwp.h> int _lwp_mutex_lock(lwp_mutex_t *mp); int _lwp_mutex_trylock(lwp_mutex_t *mp); int _lwp_mutex_unlock(lwp_mutex_t *mp); DESCRIPTION
These functions serialize the execution of lightweight processes. They are useful for ensuring that only one lightweight process can exe- cute a critical section of code at any one time (mutual exclusion). LWP mutexes must be initialized to 0 before use. The _lwp_mutex_lock() function locks the LWP mutex pointed to by mp. If the mutex is already locked, the calling LWP blocks until the mutex becomes available. When _lwp_mutex_lock() returns, the mutex is locked and the calling LWP is the "owner". The _lwp_mutex_trylock() function attempts to lock the mutex. If the mutex is already locked it returns with an error. If the mutex is unlocked, it is locked and _lwp_mutex_trylock() returns. The _lwp_mutex_unlock() function unlocks a locked mutex. The mutex must be locked and the calling LWP must be the one that last locked the mutex (the owner). If any other LWPs are waiting for the mutex to become available, one of them is unblocked. RETURN VALUES
Upon successful completion, 0 is returned. A non-zero value indicates an error. ERRORS
If any of the following conditions are detected, _lwp_mutex_lock(), _lwp_mutex_trylock(), and _lwp_mutex_unlock() fail and return the cor- responding value: EINVAL The mp argument points to an invalid LWP mutex. EFAULT The mp argument points to an illegal address. If any of the following conditions occur, _lwp_mutex_trylock() fails and returns the corresponding value: EBUSY The mp argument points to a locked mutex. SEE ALSO
intro(2), _lwp_cond_wait(2) SunOS 5.10 30 Jul 1992 _lwp_mutex_lock(2)
Man Page