Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shared Memory (Semaphore and mutex)



On Oct 1, 2004, at 1:42 PM, Marc Colosimo wrote:

Let's take a simple case, I want to set a lock (based on the assembly in PowerPC book):

    __asm__ __volatile__
    (
    "\n"
    "_lock_1:\n"
    "   lwarx  %0,0,%1 \n"     // load lock and reserve
    "   addi   %0,0,1  \n"     // set lock (1 is locked)
    "   stwcx. %0,0,%1 \n"     // try to set lock
    "   bne-   _lock_1 \n"   // loop if lost reservation
    "   isync      \n"         // import barrier
    : "=&r" (_t)
    : "r"   (__count)
    : "cc", "memory"
    );

All you're doing there is an atomic increment! If you want to "take" a lock, first test the current lock value, then either spin or block if it's already locked. Are you in the kernel or user space? BTW, you can use addic. which also works with R0.
--
Shaun Wexler
MacFOH
http://www.macfoh.com


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Shared Memory (Semaphore and mutex) (From: Marc Colosimo <email@hidden>)
 >Re: Shared Memory (Semaphore and mutex) (From: Shaun Wexler <email@hidden>)
 >Re: Shared Memory (Semaphore and mutex) (From: Marc Colosimo <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.