On 01-Feb-01 Matthew Emmerton wrote:
>> 1) You need to look in -current.
>
> I only recently moved to 4-stable, so I'm not going to jump to -current
> quite yet :)
>
>> 2) atomic_set_int(&my_int, 4); sets bit _2_ in the integer variable
> my_int.
>> Make sense? You can't address individual bits on a machine. :-P
>>
>> > I presume that I could wrap the char operations with something that
> takes
>> > 0x01 and bit-shifts it appropriately so that atomic_set/clear could be
> used.
>>
>> Hmm, so you mean the API is atomic_set(&foo, x) implies foo |= 1 << x?
>> That means you can't set more than 1 bit atomically, which is a bit
>> limiting.
>
> Yes, but it's the API used by some code I recently inherited. (Recall that
> this API is Linux's asm/bitops.h) I realize that the existing
> atomic_xxx_xxx functions are much more flexible than bit-based ones, but
> wouldn't it make sense to have the full complement of functions available?
If you don't want to patch the code, then you can use a local wrapper in your
code in the form of a suitable macro. We already have one atomic API, we don't
need to maintain 2. :)
>> > However, certain other primitives are missing, such as an atomic
>> > test-and-set operation. Under the current scheme this would have to be
> done
>> > by two independent operations, which is not useful when atomicitiy is
>> > required.
>>
>> do {
>> x = my_int;
>> while (atomic_cmpset_int(&my_int, x, x | foo) == 0);
>> if (x & foo)
>> foo_was_already_set;
>> else
>> foo_was_not_already_set;
>
> I had based my assumptions on what I saw in 4-stable, which doesn't have
> atomic_cmpset. I'll have to take a peek at 4-current or wait until some
> features trickle down to 4-stable.
This stuff likely won't be backported as it is part of the rather largish
SMPng work going on in -current. In 4.x, you can use spl()'s in the kernel to
protect data structures against being written to via interrupts. You don't
have to worry about SMP protection as the kernel spin lock will protect you
against that.
> Thanks,
>
> --
> Matt Emmerton
--
John Baldwin <[EMAIL PROTECTED]> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!" - http://www.FreeBSD.org/
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message