Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 211238da6d926d1ca4390483bb29f586 > files > 49

coda-doc-5.2.0-4mdk.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> RPC2 User Guide and Reference Manual: The Preemption Package </TITLE>
 <LINK HREF="rpc2_manual-13.html" REL=next>
 <LINK HREF="rpc2_manual-11.html" REL=previous>
 <LINK HREF="rpc2_manual.html#toc12" REL=contents>
</HEAD>
<BODY>
<A HREF="rpc2_manual-13.html">Next</A>
<A HREF="rpc2_manual-11.html">Previous</A>
<A HREF="rpc2_manual.html#toc12">Contents</A>
<HR>
<H2><A NAME="s12">12. The Preemption Package </A></H2>

<P>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.
<P>The package makes use of the <EM>interval timer</EM> facilities provided
by 4.2BSD, and so will cause programs that make their own use of
these facilities to malfunction.
In particular, use of <EM>alarm (3)</EM> or explicit handling of <EM>SIGALRM</EM>
is disallowed.
Also, calls to <EM>sleep (3)</EM> may return prematurely.
<P>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.
<P>
<H2><A NAME="ss12.1">12.1 Key Design Choices</A>
</H2>

<P>
<UL>
<LI>The package should not affect the nonpreemptive scheduling behaviour
of processes which do not use it;

It must be simple and @u[fast], with a minimum of extra system overhead;

It must support nested critical regions;

Processes using the package are assumed to be <EM>co-operating</EM>.</LI>
</UL>
<P>
<P>
<H2><A NAME="ss12.2">12.2 A Simple Example</A>
</H2>

<P>
<BLOCKQUOTE><CODE>
<PRE>
#include &lt;sys/time.h&gt;
#include "preempt.h"

        ...

        struct timeval tv;

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

        ...

        PRE_BeginCritical ();

        ...

        PRE_EndCritical ();

        ...

        PRE_EndPreempt ();
</PRE>
</CODE></BLOCKQUOTE>
<P>
<P>
<H2><A NAME="ss12.3">12.3 Preemption Primitives</A>
</H2>

<P>
<P>
<H3>PRE_InitPreempt -- Initialize the preemption package, </H3>

<P>
<H3>Call:</H3>

<P><EM> int  PRE_InitPreempt(</EM> @w&lt;<B>in</B> struct timeval *slice&gt; <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<DT><B>slice</B><DD><P>The period of the implicit scheduler calls.  Use NULL to
obtain a useful default.
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_SUCCESS</B><DD><P>All went well
<DT><B>LWP_EINIT</B><DD><P>LWP_Init was not
called
<DT><B>LWP_ESYSTEM</B><DD><P>A system call failed
</DL>
<H3>Description:</H3>

<P>This routine must be called to initialize the package
(after the call to LWP_Init).
<P>
<H3>PRE_EndPreempt -- Finalize the preemption package, </H3>

<P>
<H3>Call:</H3>

<P><EM> int  PRE_EndPreempt(</EM>  <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<P><EM> None </EM>
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<DT><B>LWP_SUCCESS</B><DD><P>All went well,
<DT><B>LWP_EINIT</B><DD><P>LWP_Init was not
called,
<DT><B>LWP_ESYSTEM</B><DD><P>A system call failed
</DL>
<H3>Description:</H3>

<P>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.
)
<P>
<H3>PRE_PreemptMe -- Mark a process as a candidate for preemption, </H3>

<P>
<H3>Call:</H3>

<P><EM>  PRE_PreemptMe(</EM>  <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<P>
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<P>
</DL>
<H3>Description:</H3>

<P>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.
)
<P>
<H3>PRE_BeginCritical -- Enter a critical section </H3>

<P>
<H3>Call:</H3>

<P><EM>  PRE_BeginCritical(</EM>  <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<P>
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<P>
</DL>
<H3>Description:</H3>

<P>This routine places the current LWP in a <EM>Critical
Section</EM>.  Upon return, involunatry preemptions of this
process will no longer occur.  Note that this is a macro
and that LWP_Init must have been
<P>
<H3>PRE_EndCritical -- Leave a critcal section, </H3>

<P>
<H3>Call:</H3>

<P><EM>  PRE_EndCritical(</EM> , <EM>)</EM>
<H3>Parameters:</H3>

<P>
<DL>
<P>
</DL>
<H3>Completion Codes:</H3>

<P>
<DL>
<P>
</DL>
<H3>Description:</H3>

<P>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.
)
<P>
<P>
<P>
<HR>
<A HREF="rpc2_manual-13.html">Next</A>
<A HREF="rpc2_manual-11.html">Previous</A>
<A HREF="rpc2_manual.html#toc12">Contents</A>
</BODY>
</HTML>