|
|
#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 );
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) |
Bit test/set functions return the result of the test.
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 |
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 |
Bit test/set locks
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.
``Atomic locks'' in HDK Technical Reference
qincl(&my_arg); qdecb(&my_arg2);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:qaddl(&my_arg, 3); qandb(&my_arg2, 0x40);
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 1int 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 */ }