#define PIPE_ATOMIC "GCC x86 assembly"
-struct pipe_atomic {
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
+p_atomic_dec_zero(int32_t *v)
{
unsigned char c;
- __asm__ __volatile__("lock; decl %0; sete %1":"+m"(v->count), "=qm"(c)
+ __asm__ __volatile__("lock; decl %0; sete %1":"+m"(*v), "=qm"(c)
::"memory");
return c != 0;
}
static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
+p_atomic_inc(int32_t *v)
{
- __asm__ __volatile__("lock; incl %0":"+m"(v->count));
+ __asm__ __volatile__("lock; incl %0":"+m"(*v));
}
static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
+p_atomic_dec(int32_t *v)
{
- __asm__ __volatile__("lock; decl %0":"+m"(v->count));
+ __asm__ __volatile__("lock; decl %0":"+m"(*v));
}
static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
{
- return __sync_val_compare_and_swap(&v->count, old, _new);
+ return __sync_val_compare_and_swap(v, old, _new);
}
#endif
#define PIPE_ATOMIC "GCC Sync Intrinsics"
-struct pipe_atomic {
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
+p_atomic_dec_zero(int32_t *v)
{
- return (__sync_sub_and_fetch(&v->count, 1) == 0);
+ return (__sync_sub_and_fetch(v, 1) == 0);
}
static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
+p_atomic_inc(int32_t *v)
{
- (void) __sync_add_and_fetch(&v->count, 1);
+ (void) __sync_add_and_fetch(v, 1);
}
static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
+p_atomic_dec(int32_t *v)
{
- (void) __sync_sub_and_fetch(&v->count, 1);
+ (void) __sync_sub_and_fetch(v, 1);
}
static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
{
- return __sync_val_compare_and_swap(&v->count, old, _new);
+ return __sync_val_compare_and_swap(v, old, _new);
}
#endif
#define PIPE_ATOMIC "Unlocked"
-struct pipe_atomic
-{
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
-#define p_atomic_dec_zero(_v) ((boolean) --(_v)->count)
-#define p_atomic_inc(_v) ((void) (_v)->count++)
-#define p_atomic_dec(_v) ((void) (_v)->count--)
-#define p_atomic_cmpxchg(_v, old, _new) ((_v)->count == old ? (_v)->count = (_new) : (_v)->count)
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
+#define p_atomic_dec_zero(_v) ((boolean) --(*(_v)))
+#define p_atomic_inc(_v) ((void) (*(_v))++)
+#define p_atomic_dec(_v) ((void) (*(_v))--)
+#define p_atomic_cmpxchg(_v, old, _new) (*(_v) == old ? *(_v) = (_new) : *(_v))
#endif
#define PIPE_ATOMIC "MSVC x86 assembly"
-struct pipe_atomic
-{
- int32_t count;
-};
-
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
+p_atomic_dec_zero(int32_t *v)
{
- int32_t *pcount = &v->count;
unsigned char c;
__asm {
- mov eax, [pcount]
+ mov eax, [v]
lock dec dword ptr [eax]
sete byte ptr [c]
}
}
static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
+p_atomic_inc(int32_t *v)
{
- int32_t *pcount = &v->count;
-
__asm {
- mov eax, [pcount]
+ mov eax, [v]
lock inc dword ptr [eax]
}
}
static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
+p_atomic_dec(int32_t *v)
{
- int32_t *pcount = &v->count;
-
__asm {
- mov eax, [pcount]
+ mov eax, [v]
lock dec dword ptr [eax]
}
}
static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
{
- int32_t *pcount = &v->count;
int32_t orig;
__asm {
- mov ecx, [pcount]
+ mov ecx, [v]
mov eax, [old]
mov edx, [_new]
lock cmpxchg [ecx], edx
#define PIPE_ATOMIC "MSVC Intrinsics"
-struct pipe_atomic
-{
- int32_t count;
-};
-
#include <intrin.h>
#pragma intrinsic(_InterlockedIncrement)
#pragma intrinsic(_InterlockedDecrement)
#pragma intrinsic(_InterlockedCompareExchange)
-#define p_atomic_set(_v, _i) ((_v)->count = (_i))
-#define p_atomic_read(_v) ((_v)->count)
+#define p_atomic_set(_v, _i) (*(_v) = (_i))
+#define p_atomic_read(_v) (*(_v))
static INLINE boolean
-p_atomic_dec_zero(struct pipe_atomic *v)
+p_atomic_dec_zero(int32_t *v)
{
- return _InterlockedDecrement(&v->count) == 0;
+ return _InterlockedDecrement(v) == 0;
}
static INLINE void
-p_atomic_inc(struct pipe_atomic *v)
+p_atomic_inc(int32_t *v)
{
- _InterlockedIncrement(&v->count);
+ _InterlockedIncrement(v);
}
static INLINE void
-p_atomic_dec(struct pipe_atomic *v)
+p_atomic_dec(int32_t *v)
{
- _InterlockedDecrement(&v->count);
+ _InterlockedDecrement(v);
}
static INLINE int32_t
-p_atomic_cmpxchg(struct pipe_atomic *v, int32_t old, int32_t _new)
+p_atomic_cmpxchg(int32_t *v, int32_t old, int32_t _new)
{
- return _InterlockedCompareExchange(&v->count, _new, old);
+ return _InterlockedCompareExchange(v, _new, old);
}
#endif
+++ /dev/null
-/**************************************************************************
- *
- * Copyright 2009 VMware, Inc.
- * All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
- * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- **************************************************************************/
-
-#ifndef P_REFCNT_H
-#define P_REFCNT_H
-
-
-#include "p_defines.h"
-#include "p_atomic.h"
-#include "util/u_debug.h" /* FIXME: remove this */
-
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-struct pipe_reference
-{
- struct pipe_atomic count;
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* P_REFCNT_H */