Coda File System

Next Previous Contents

12. The Preemption Package

The preemption package provides a mechanism by which control can pass between light-weight processes without the need for explicit calls to LWP_DispatchProcess. This effect is achieved by periodically interrupting the normal flow of control to check if other (higher priority) procesess are ready to run.

The package makes use of the interval timer facilities provided by 4.2BSD, and so will cause programs that make their own use of these facilities to malfunction. In particular, use of alarm (3) or explicit handling of SIGALRM is disallowed. Also, calls to sleep (3) may return prematurely.

Care should be taken that routines are re-entrant where necessary. In particular, note that stdio (3) is not re-entrant in general, and hence light-weight processes performing I/O on the same FILE structure may function incorrectly.

12.1 Key Design Choices

12.2 A Simple Example


#include
<
sys/time.h
>
#include "preempt.h"

        ...

        struct timeval tv;

        LWP_Init (LWP_VERSION, ... );
        tv.tv_sec = 10;
        tv.tv_usec = 0;
        PRE_InitPreempt (
&
tv);
        PRE_PreemptMe ();

        ...

        PRE_BeginCritical ();

        ...

        PRE_EndCritical ();

        ...

        PRE_EndPreempt ();

12.3 Preemption Primitives

PRE_InitPreempt -- Initialize the preemption package,

Call:

int PRE_InitPreempt( @w < in struct timeval *slice > )

Parameters:

slice

The period of the implicit scheduler calls. Use NULL to obtain a useful default.

Completion Codes:

LWP_SUCCESS

All went well

LWP_EINIT

LWP_Init was not called

LWP_ESYSTEM

A system call failed

Description:

This routine must be called to initialize the package (after the call to LWP_Init).

PRE_EndPreempt -- Finalize the preemption package,

Call:

int PRE_EndPreempt( )

Parameters:

None

Completion Codes:

LWP_SUCCESS

All went well,

LWP_EINIT

LWP_Init was not called,

LWP_ESYSTEM

A system call failed

Description:

This routine finalizes use of the preemption package. No further preemptions will be made. Note that is not necessary to make this call before exit - it is provided only for those applications that wish to continue after turning off preemption. )

PRE_PreemptMe -- Mark a process as a candidate for preemption,

Call:

PRE_PreemptMe( )

Parameters:

Completion Codes:

Description:

Text=`This is a macro that marks the current process as a candidate for preemption. It is erroneous to invoke PRE_PreemptMe () if LWP_Init has not been called. )

PRE_BeginCritical -- Enter a critical section

Call:

PRE_BeginCritical( )

Parameters:

Completion Codes:

Description:

This routine places the current LWP in a Critical Section . Upon return, involunatry preemptions of this process will no longer occur. Note that this is a macro and that LWP_Init must have been

PRE_EndCritical -- Leave a critcal section,

Call:

PRE_EndCritical( , )

Parameters:

Completion Codes:

Description:

This routine leaves a critical section previously entered with PRE_BeginCritical (). If involuntary preemptions were possible before the matching PRE_BeginCritical (), they are once again possible. Note that this is a macro and that LWP_Init must have been previously invoked. )


Next Previous Contents