Examples from Linux of Critical Segments
/*
* Wake up a process. Put it on the run-queue if it's not
* already there. The "current" process is always on the
* run-queue (except when the actual re-schedule is in
* progress), and as such you're allowed to do the simpler
* "current->state = TASK_RUNNING" to mark yourself runnable
* without the overhead of this.
*/
inline void wake_up_process(struct task_struct * p)
{
unsigned long flags;
save_flags(flags);
cli();
p->state = TASK_RUNNING;
if (!p->next_run)
add_to_runqueue(p);
restore_flags(flags);
}
/*
* sys_stime() can be implemented in user-level using
* sys_settimeofday(). Is this for backwards compatibility? If so,
* why not move it into the appropriate arch directory (for those
* architectures that need it).
*/
asmlinkage int sys_stime(int * tptr)
{
int error, value;
if (!suser())
return -EPERM;
error = verify_area(VERIFY_READ, tptr, sizeof(*tptr));
if (error)
return error;
value = get_user(tptr);
cli();
xtime.tv_sec = value;
xtime.tv_usec = 0;
time_state = TIME_ERROR;
time_maxerror = MAXPHASE;
time_esterror = MAXPHASE;
sti();
return 0;
}
/*
* This function is called by a protocol handler that wants to
* advertise its address family, and have it linked into the
* SOCKET module.
*/
int sock_register(int family, struct proto_ops *ops)
{
int i;
cli();
for(i = 0; i < NPROTO; i++)
{
if (pops[i] != NULL)
continue;
pops[i] = ops;
pops[i]->family = family;
sti();
return(i);
}
sti();
return(-ENOMEM);
}