It is a normal test-and-set operation.
It checks if the lock is busy or not.
If the lock was busy, it fails.
If the lock wasn't busy, it sets the lock and succeeds.
As you can see, it performs an exchange operation where it copies the
value SEMPAPHORE_C_SET to the lock, while retrieving the previous value.
If the previous value was SEMAPHORE_C_SET, the lock stays set and this
task fails.
If the previous value wasn't SEMAPHORE_C_SET, the lock will not be set and
this task has ok to perform operations on whatever critical resources the
lock is used to protect.
Most OS have functions with this or similar functionality.
/Per W
On Mon, 1 Dec 2003, Smitha V. Babu wrote:
> hi to all..
> Does anyone knows what this piece of code means...
>
> #define sys_test_and_set(lock) \
> ({ \
> volatile long temp = SEMAPHORE_C_SET; \
> __asm__("xchgl %0,(%2)" \
> :"=s" (temp) \
> :"0" (temp),"r" (lock)); \
> temp; \
> })
>
>
> thanking in advance
> regards
> smitha
> *********************************************************************
> Disclaimer: The information in this e-mail and any attachments is
> confidential / privileged. It is intended solely for the addressee or
> addressees. If you are not the addressee indicated in this message, you may
> not copy or deliver this message to anyone. In such case, you should destroy
> this message and kindly notify the sender by reply email. Please advise
> immediately if you or your employer does not consent to Internet email for
> messages of this kind.
> *********************************************************************
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: SF.net Giveback Program.
> Does SourceForge.net help you be more productive? Does it
> help you create better code? SHARE THE LOVE, and help us help
> YOU! Click Here: http://sourceforge.net/donate/
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>
|