CURLWP_BIND(9)

NAME
curlwp_bind, curlwp_bindx - temporarily bind the current thread to the running CPU

SYNOPSIS
#include <sys/lwp.h>
int
curlwp_bind(void);
void
curlwp_bindx(int bound);

DESCRIPTION
curlwp_bind() temporarily binds the current thread to the running CPU and returns a cookie bound which must be passed to curlwp_bindx() when done.

During this time, the thread may sleep and may be preempted, but it will never migrate to another CPU until curlwp_bindx(). If the CPU is offlined, the thread will not run again until the CPU is onlined again.

Calls to curlwp_bind() and curlwp_bindx() may be nested as long as the matching cookie is passed.

EXAMPLES
For temporary access to resources protected by psref(9) from an arbitrary thread:

    struct psref psref;
    int bound, s;
    bound = curlwp_bind();
    s = pserialize_read_enter();
    IFADDR_READER_FOREACH(ifa, ifp) {
            ifa_acquire(ifa, &psref);
            pserialize_read_exit(s);
            /*
             * ifa is now stable, even if caller is preempted
             * or sleeps
             */
            s = pserialize_read_enter();
            ifa_release(ifa, &psref);
    }
    pserialize_read_exit(s);
    curlwp_bindx(bound);

CODE REFERENCES
sys/sys/lwp.h

SEE ALSO
localcount(9), pserialize(9), psref(9), spl(9)

HISTORY
The curlwp_bind function first appeared in NetBSD 8.0 to support psref(9).