On 08/24/2012 11:34 AM, Jiří Zárevúcky wrote: > On 23 August 2012 00:45, Jakub Jermar <[email protected]> wrote: >> - non x86 platforms are missing atomic_cas_* implementations (the >> first step would be to make all platforms at least build using just >> dummy implementations, the next step would be to provide >> functional, but perhaps still limited implementations for these); >> for example, armv4 does not have atomic instructions, so all one >> can do is disable interrupts and then do a non-atomic cas > > What about GCC builtins? I'd imagine these are implemented in the best > possible way on all supported platforms. > There is GCC-specific code all around the system anyway, Clang mirrors > its features well, and I don't see the need (or sense) to target any > other compiler.
Among others, GCC provides: TYPE __sync_fetch_and_add (TYPE *ptr, TYPE value, ...); TYPE __sync_add_and_fetch (TYPE *ptr, TYPE value, ...); TYPE __sync_val_compare_and_swap (TYPE *ptr, TYPE oldval TYPE newval, ...); TYPE __sync_lock_test_and_set (TYPE *ptr, TYPE value, ...); void __sync_lock_release (TYPE *ptr, ...); These are basically those needed by HelenOS; compare_and_swap() is newly required by CHT. I can see some potential problems though, for example, the gcc infodoc says: Not all operations are supported by all target processors. If a particular operation cannot be implemented on the target processor, a warning will be generated and a call an external function will be generated. Which suggests that we could end up implementing some of the above anyway. Another problem is that some of the builtins above have slightly different semantics wrt. memory barriers than the primitives already used in HelenOS so that switching over may require some refactoring. It is not clear whether it wouldn't be easier to implement the missing functionality instead. An interesting option would be to use __sync_val_compare_and_swap to implement only compare_and_swap and keep the already existing implementations for others. Jakub _______________________________________________ HelenOS-devel mailing list [email protected] http://lists.modry.cz/cgi-bin/listinfo/helenos-devel
