DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SCO OpenServer

atomic(D3oddi)


atomic -- quick atomic locks

Synopsis

#include <??>

void qadd<size> (void *, int; void qsub<size> (void *, int; void qand<size> (void *, int; void qxchg<size> (void *, int; void qor<size> (void *, int; void qbts<size> (void *, int; void qinc<size>(void *); void qdec<size>(void *); void qzero<size>(void *);

Description

Arguments

Quick locks provide atomic arithmetic and bit operations for variables on multiprocessor systems. The name of each routine indicates the operation and size of its arguments. The last character(s) represents the argument type as follows:

l long ul unsigned long
i int ui unsigned int
w word (short) uw unsigned word (unsigned short)
b byte (char) ub unsigned byte (unsigned char)

 l   long                        ul   unsigned long
 i   int                         ui   unsigned int
 w   word (short)                uw   unsigned word (unsigned short)
 b   byte (char)                 ub   unsigned byte (unsigned char)

Return values

None for addition, subtraction, and, exchange, or, increment, and zero.

Bit test/set functions return the result of the test.

Usage

The following tables show the full set of quick lock functions:

Quick locks with two parameters -- qaddl(void*,long)

Operation long ulong int uint short ushort char uchar
addition qaddl qaddul qaddi qaddui qaddw qadduw qaddb qaddub
subtraction qsubl qsubul qsubi qsubui qsubw qsubuw qsubb qsubub
and qandl qandul qandi qandui qandw qanduw qandb qandub
exchange qxchgl qxchgul qxchgi qxchgui qxchgw qxchguw qxchgb qxchgub
or qorl qorul qori qorui qorw qoruw qorb qorub

 Operation   | long     ulong     int      uint      short    ushort    char     uchar
 addition    | qaddl    qaddul    qaddi    qaddui    qaddw    qadduw    qaddb    qaddub
 subtraction | qsubl    qsubul    qsubi    qsubui    qsubw    qsubuw    qsubb    qsubub
 and         | qandl    qandul    qandi    qandui    qandw    qanduw    qandb    qandub
 exchange    | qxchgl   qxchgul   qxchgi   qxchgui   qxchgw   qxchguw   qxchgb   qxchgub
 or          | qorl     qorul     qori     qorui     qorw     qoruw     qorb     qorub

Quick locks with one parameter --qincl(void*)

Operation long ulong int uint short ushort char uchar
increment qincl qincul qinci qincui qincw qincuw qincb qincub
decrement qdecl qdecul qdeci qdecui qdecw qdecuw qdecb qdecub
zero qzerol qzeroul qzeroi qzeroui qzerow qzerouw qzerob qzeroub

 Operation | long     ulong     int      uint      short    ushort    char     uchar
 increment | qincl    qincul    qinci    qincui    qincw    qincuw    qincb    qincub
 decrement | qdecl    qdecul    qdeci    qdecui    qdecw    qdecuw    qdecb    qdecub
 zero      | qzerol   qzeroul   qzeroi   qzeroui   qzerow   qzerouw   qzerob   qzeroub

Bit test/set locks

Operation long ulong int uint short ushort char uchar
bit test/set qbtsl qbtsul qbtsi qbtsui -- -- -- --

 Operation    | long    ulong    int     uint     short   ushort   char   uchar
 bit test/set | qbtsl   qbtsul   qbtsi   qbtsui

These routines use the 80*86 lock prefix instruction to lock the bus during the execution of the instruction. They should be used whenever a simple atomic action is all that is required such as incrementing a counter. They have less impact on performance than other locks.

The qbts family of functions do an atomic test and set of a bit in a field of bits. This is useful for semaphores and similar operations. If more than one bit is specified in the second parameter, the qbts function will test and set the least bit requested and silently ignore any others. Use the qorl family if multiple bits need to be set.

These operations cannot be split by an interrupt because they are executed as a single assembler instruction.

Context and synchronization

All contexts.

Hardware applicability

All

Version applicability

oddi: 3, 3mp, 4, 4mp, 5, 5mp, 6, 6mp

SVR5 DDI compatibility

These functions are not supported for DDI drivers. DDI drivers support atomic locks with a different set of functions. See ``Atomic locks'' in HDK Technical Reference.

References

clockb(D3oddi), lockb(D3oddi), ilockb(D3oddi)

``Atomic locks'' in HDK Technical Reference

Examples

The following calls illustrate the use of the qinc, qdec, qadd and qand functions:
   qincl(&my_arg);
   qdecb(&my_arg2);
   

qaddl(&my_arg, 3); qandb(&my_arg2, 0x40);

Because a quick lock cannot be split up by an interrupt, the following two code fragments provide equivalent functionality, although the fragment on the right that uses qinc is more efficient:
   s=spl7();				qincl(&i);
   	i++;
   splx(s);
The following example illustrates the use of the qbts functions. This code references a buffer whose header has a bit that indicates whether the buffer is in use. The qbtsl function tests the bit, unconditionally sets it to mark that the buffer is busy, and returns the result of the test. On return, the bit is definitely set; the return value indicates whether this process "owns" the buffer or if someone else had it first.
   #define IN_USE 1
   

int control_word; if (qbtsl(&control_word, IN_USE) ) { /* buffer was in_use, we cannot use it */ } else { /* buffer was free, now marked busy, we can use it */ }


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 5 HDK - June 2005