diff --git a/headers/private/kernel/util/atomic.h b/headers/private/kernel/util/atomic.h new file mode 100644 index 0000000000..f769acdc77 --- /dev/null +++ b/headers/private/kernel/util/atomic.h @@ -0,0 +1,31 @@ +/* + * Copyright 2008, Axel Dörfler, axeld@pinc-software.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _KERNEL_UTIL_ATOMIC_H +#define _KERNEL_UTIL_ATOMIC_H + + +#include + +#include + + +#ifdef __cplusplus + +template PointerType* +atomic_pointer_test_and_set(PointerType** _pointer, PointerType* set, + PointerType* test) +{ +#if LONG_MAX == INT_MAX + return (PointerType*)atomic_test_and_set((vint32*)_pointer, (int32)set, + (int32)test); +#else + return (PointerType*)atomic_test_and_set64((vint64*)_pointer, (int64)set, + (int64)test); +#endif +} + +#endif // __cplusplus + +#endif /* _KERNEL_UTIL_ATOMIC_H */ diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 6172dc2935..5080a81e54 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -27,27 +27,26 @@ #include #include -#include - #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include #include #include #include #include +#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "fifo.h" @@ -1144,8 +1143,8 @@ create_advisory_locking(struct vnode *vnode) // We need to set the locking structure atomically - someone // else might set one at the same time do { - if (atomic_test_and_set((vint32 *)&vnode->advisory_locking, - (addr_t)locking, (addr_t)NULL) == (addr_t)NULL) + if (atomic_pointer_test_and_set(&vnode->advisory_locking, locking, + (advisory_locking*)NULL) == NULL) return B_OK; } while (get_advisory_locking(vnode) == NULL); @@ -5309,8 +5308,8 @@ common_lock_node(int fd, bool kernel) // We need to set the locking atomically - someone // else might set one at the same time - if (atomic_test_and_set((vint32 *)&vnode->mandatory_locked_by, - (addr_t)descriptor, (addr_t)NULL) != (addr_t)NULL) + if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by, descriptor, + (file_descriptor*)NULL) != NULL) status = B_BUSY; put_fd(descriptor); @@ -5332,8 +5331,8 @@ common_unlock_node(int fd, bool kernel) // We need to set the locking atomically - someone // else might set one at the same time - if (atomic_test_and_set((vint32 *)&vnode->mandatory_locked_by, - (addr_t)NULL, (addr_t)descriptor) != (int32)descriptor) + if (atomic_pointer_test_and_set(&vnode->mandatory_locked_by, + (file_descriptor*)NULL, descriptor) != descriptor) status = B_BAD_VALUE; put_fd(descriptor);