The operation of fsflush() is a good illustration of how the callback protocol works:
#include <sys/callb.h>
In the initialization of the fsflush thread, before the main service loop is entered, it invokes the CALLB_CPR_INIT macro. This initializes a data structure and enters the thread in the callback table (see callb.c):
For example,
In the service loop of the kernel thread:
When the thread is at a point in its processing where it can safely be suspended, it calls the CALLB_CPR_SAFE_BEGIN macro. The best location for this call is when the thread has just finished doing some work and has yet to begin a new task.
For example,
For example,
For example,
Note: The macro definitions in callb.h contain some references to an obsolete flag. This will be cleaned up shortly. Also, comments will be added to thread.h and thread.c explaining the need to conform to the protocol described here.