From 0ddccfdc7a99d84be9278244090d31f115d21a9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 12 Dec 2004 20:49:51 +0000 Subject: [PATCH] We now have atomic_test_and_set() and atomic_set() in the kernel directly. Removed Metrowerks support. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10403 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Lock.h | 4 +- src/add-ons/kernel/file_systems/bfs/Utility.h | 108 ++---------------- 2 files changed, 10 insertions(+), 102 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Lock.h b/src/add-ons/kernel/file_systems/bfs/Lock.h index b3b8595a6d..2dda801fd4 100644 --- a/src/add-ons/kernel/file_systems/bfs/Lock.h +++ b/src/add-ons/kernel/file_systems/bfs/Lock.h @@ -475,7 +475,7 @@ class SimpleLock { current = fHolder; fHolder = thisThread; }*/ - current = _atomic_test_and_set(&fHolder, thisThread, -1); + current = atomic_test_and_set(&fHolder, thisThread, -1); if (current == -1) break; if (current == thisThread) @@ -493,7 +493,7 @@ class SimpleLock { void Unlock() { if (atomic_add(&fCount, -1) == 1) - _atomic_set(&fHolder, -1); + atomic_set(&fHolder, -1); } bool IsLocked() const diff --git a/src/add-ons/kernel/file_systems/bfs/Utility.h b/src/add-ons/kernel/file_systems/bfs/Utility.h index 5304a28b0e..edf0c25f37 100644 --- a/src/add-ons/kernel/file_systems/bfs/Utility.h +++ b/src/add-ons/kernel/file_systems/bfs/Utility.h @@ -1,10 +1,10 @@ +/* Utility - some helper classes + * + * Copyright 2001-2004, Axel Dörfler, axeld@pinc-software.de. + * This file may be used under the terms of the MIT License. + */ #ifndef UTILITY_H #define UTILITY_H -/* Utility - some helper classes -** -** Initial version by Axel Dörfler, axeld@pinc-software.de -** This file may be used under the terms of the OpenBeOS License. -*/ #include @@ -16,12 +16,7 @@ struct sorted_array { public: off_t count; - - #if __MWERKS__ - off_t values[1]; - #else - off_t values[0]; - #endif + off_t values[0]; inline int32 Find(off_t value) const; void Insert(off_t value); @@ -72,7 +67,7 @@ class BlockArray { // Doubly linked list template struct node { - Node *next,*prev; + Node *next, *prev; void Remove() @@ -92,7 +87,7 @@ template struct node { }; template struct list { - Node *head,*tail,*last; + Node *head, *tail, *last; list() { @@ -111,91 +106,4 @@ template struct list { } }; - -// Some atomic operations that are somehow missing in BeOS: -// -// _atomic_test_and_set(value, newValue, testAgainst) -// sets "value" to "newValue", if "value" is equal to "testAgainst" -// _atomic_set(value, newValue) -// sets "value" to "newValue" - -#if _NO_INLINE_ASM - // Note that these atomic versions *don't* work as expected! - // They are only used for single processor user space tests - // (and don't even work correctly there) - inline int32 - _atomic_test_and_set(volatile int32 *value, int32 newValue, int32 testAgainst) - { - int32 oldValue = *value; - if (oldValue == testAgainst) - *value = newValue; - - return oldValue; - } - - inline void - _atomic_set(volatile int32 *value, int32 newValue) - { - *value = newValue; - } -#elif __INTEL__ - inline int32 - _atomic_test_and_set(volatile int32 *value, int32 newValue, int32 testAgainst) - { - int32 oldValue; - asm volatile("lock; cmpxchg %%ecx, (%%edx)" - : "=a" (oldValue) : "a" (testAgainst), "c" (newValue), "d" (value)); - return oldValue; - } - - inline void - _atomic_set(volatile int32 *value, int32 newValue) - { - asm volatile("lock; xchg %%eax, (%%edx)" - : : "a" (newValue), "d" (value)); - } -#elif __POWERPC__ && __MWERKS__ /* GCC has different assembler syntax */ -inline asm int32 - _atomic_set(volatile int32 *value, int32) - { - loop: - dcbf r0, r3; - lwarx r0, 0, r3; - stwcx. r4, 0, r3; - bc 5, 2, loop - mr r3,r5; - isync; - blr; - } - -inline asm int32 - _atomic_test_and_set(volatile int32 *value, int32 newValue, int32 testAgainst) - { - loop: - dcbf r0, r3; - lwarx r0, 0, r3; - cmpw r5, r0; - bne no_dice; - stwcx. r4, 0, r3; - bc 5, 2, loop - - mr r3,r0; - isync; - blr; - - no_dice: - stwcx. r0, 0, r3; - mr r3,r0; - isync; - blr; - } - -#else -# error The macros _atomic_set(), and _atomic_test_and_set() are not defined for the target processor -#endif - - -extern "C" size_t strlcpy(char *dest, char const *source, size_t length); - - #endif /* UTILITY_H */