[haiku-development] Re: Writing Device Drivers - CRAM - Ticket Locking

  • From: Rene Gollent <anevilyak@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Fri, 19 Aug 2011 23:17:54 -0400

On Fri, Aug 19, 2011 at 10:13 PM, Earl Pottinger
<earl_colby_pottinger@xxxxxxxxx> wrote:
>
> The last few times I posted questions I did not receive any replies because 
> everybody was getting busy preparing for the release of Alpha-3.  I hope 
> somebody has the time to help me with my questions at this time.

Please don't use rich text email on this list btw.

> After a lot of work insuring read/write/flush commands are executed in the 
> order they were called I seemed to have recreated Ticket-Locking, however 
> ticket-locking requires a counter that is incremented atomicly.
> The Atomic_Add() function documented in BeOS is only 32 bits in size.  
> However, a large drive (1TB or greater) could easily have more than 2^32 
> operations done to it between resets. To be safe I need a 64 bit counter.
> Is there a 64 bit Atomic_Add() function in Haiku?????

Yes, there are 64-bit variants of all of them on Haiku, c.f.
http://dev.haiku-os.org/browser/haiku/trunk/headers/os/support/SupportDefs.h#L194

> Should I be disabling interrupts only with spin-locks or will disabling 
> interrupts work with semaphores as well????

You should generally avoid disabling interrupts unless you absolutely
have to, and in any case, if you are in the situation where it's
unavoidable, spinlocks are about the only thing you'll be able to use,
since semaphores generally require being able to reschedule/preempt,
which isn't possible with ints disabled.

Regards,

Rene

Other related posts: