2008-04-30 01:05:05 +04:00
|
|
|
/*
|
|
|
|
* 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 <limits.h>
|
|
|
|
|
|
|
|
#include <SupportDefs.h>
|
|
|
|
|
2013-12-06 01:47:30 +04:00
|
|
|
#include <debug.h>
|
|
|
|
|
2008-04-30 01:05:05 +04:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
|
|
|
|
template<typename PointerType> PointerType*
|
2008-04-30 02:03:03 +04:00
|
|
|
atomic_pointer_test_and_set(PointerType** _pointer, const PointerType* set,
|
|
|
|
const PointerType* test)
|
2008-04-30 01:05:05 +04:00
|
|
|
{
|
|
|
|
#if LONG_MAX == INT_MAX
|
2013-11-06 01:32:59 +04:00
|
|
|
return (PointerType*)atomic_test_and_set((int32*)_pointer, (int32)set,
|
2008-04-30 01:05:05 +04:00
|
|
|
(int32)test);
|
|
|
|
#else
|
2013-11-06 01:32:59 +04:00
|
|
|
return (PointerType*)atomic_test_and_set64((int64*)_pointer, (int64)set,
|
2008-04-30 01:05:05 +04:00
|
|
|
(int64)test);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-04-30 02:03:03 +04:00
|
|
|
|
|
|
|
template<typename PointerType> PointerType*
|
2013-11-06 01:32:59 +04:00
|
|
|
atomic_pointer_get_and_set(PointerType** _pointer, const PointerType* set)
|
|
|
|
{
|
|
|
|
#if LONG_MAX == INT_MAX
|
|
|
|
return (PointerType*)atomic_get_and_set((int32*)_pointer, (int32)set);
|
|
|
|
#else
|
|
|
|
return (PointerType*)atomic_get_and_set64((int64*)_pointer, (int64)set);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<typename PointerType> void
|
2008-04-30 02:03:03 +04:00
|
|
|
atomic_pointer_set(PointerType** _pointer, const PointerType* set)
|
|
|
|
{
|
2013-11-06 01:32:59 +04:00
|
|
|
ASSERT((addr_t(_pointer) & (sizeof(PointerType*) - 1)) == 0);
|
2008-04-30 02:03:03 +04:00
|
|
|
#if LONG_MAX == INT_MAX
|
2013-11-06 01:32:59 +04:00
|
|
|
atomic_set((int32*)_pointer, (int32)set);
|
2008-04-30 02:03:03 +04:00
|
|
|
#else
|
2013-11-06 01:32:59 +04:00
|
|
|
atomic_set64((int64*)_pointer, (int64)set);
|
2008-04-30 02:03:03 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-05-06 07:30:25 +04:00
|
|
|
|
|
|
|
template<typename PointerType> PointerType*
|
2022-02-07 22:35:23 +03:00
|
|
|
atomic_pointer_get(PointerType* const* _pointer)
|
2008-05-06 07:30:25 +04:00
|
|
|
{
|
2013-11-06 01:32:59 +04:00
|
|
|
ASSERT((addr_t(_pointer) & (sizeof(PointerType*) - 1)) == 0);
|
2008-05-06 07:30:25 +04:00
|
|
|
#if LONG_MAX == INT_MAX
|
2013-11-06 01:32:59 +04:00
|
|
|
return (PointerType*)atomic_get((int32*)_pointer);
|
2008-05-06 07:30:25 +04:00
|
|
|
#else
|
2013-11-06 01:32:59 +04:00
|
|
|
return (PointerType*)atomic_get64((int64*)_pointer);
|
2008-05-06 07:30:25 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-04-30 01:05:05 +04:00
|
|
|
#endif // __cplusplus
|
|
|
|
|
|
|
|
#endif /* _KERNEL_UTIL_ATOMIC_H */
|