diff options
author | Keith Packard <keithp@keithp.com> | 2013-11-20 08:25:44 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2013-11-20 13:57:13 -0800 |
commit | b394d499eeb6abb0f23a629f22f6634f137d279e (patch) | |
tree | 348e7fcb0ca89cbf9023df9f26df033e364ee28d | |
parent | d6fe39b4c3ec6ca75fb935b88a14916c730a6c26 (diff) |
Change fence memory type from 'int32_t' to 'struct shmfence'
This will allow other implementations to use alternate
representations, as well as providing additional typechecking.
Signed-off-by: Keith Packard <keithp@keithp.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
-rw-r--r-- | src/xshmfence.c | 36 | ||||
-rw-r--r-- | src/xshmfence.h | 16 | ||||
-rw-r--r-- | src/xshmfenceint.h | 1 |
3 files changed, 30 insertions, 23 deletions
diff --git a/src/xshmfence.c b/src/xshmfence.c index 521d3ad..83049de 100644 --- a/src/xshmfence.c +++ b/src/xshmfence.c @@ -22,6 +22,10 @@ #include "xshmfenceint.h" +struct xshmfence { + int32_t v; +}; + /** * xshmfence_trigger: * @f: An X fence @@ -32,11 +36,11 @@ * will be set as appropriate). **/ int -xshmfence_trigger(int32_t *f) +xshmfence_trigger(struct xshmfence *f) { - if (__sync_val_compare_and_swap(f, 0, 1) == -1) { - atomic_store(f, 1); - if (futex_wake(f) < 0) + if (__sync_val_compare_and_swap(&f->v, 0, 1) == -1) { + atomic_store(&f->v, 1); + if (futex_wake(&f->v) < 0) return -1; } return 0; @@ -53,10 +57,10 @@ xshmfence_trigger(int32_t *f) * will be set as appropriate). **/ int -xshmfence_await(int32_t *f) +xshmfence_await(struct xshmfence *f) { - while (__sync_val_compare_and_swap(f, 0, -1) != 1) { - if (futex_wait(f, -1)) { + while (__sync_val_compare_and_swap(&f->v, 0, -1) != 1) { + if (futex_wait(&f->v, -1)) { if (errno != EWOULDBLOCK) return -1; } @@ -71,9 +75,9 @@ xshmfence_await(int32_t *f) * Return value: 1 if @f is triggered, else returns 0. **/ int -xshmfence_query(int32_t *f) +xshmfence_query(struct xshmfence *f) { - return atomic_fetch(f) == 1; + return atomic_fetch(&f->v) == 1; } /** @@ -84,9 +88,9 @@ xshmfence_query(int32_t *f) * this function has no effect. **/ void -xshmfence_reset(int32_t *f) +xshmfence_reset(struct xshmfence *f) { - __sync_bool_compare_and_swap(f, 1, 0); + __sync_bool_compare_and_swap(&f->v, 1, 0); } @@ -120,11 +124,11 @@ xshmfence_alloc_shm(void) * Return value: the fence or NULL (in which case, errno will be set * as appropriate). **/ -int32_t * +struct xshmfence * xshmfence_map_shm(int fd) { - void *addr; - addr = mmap (NULL, sizeof (int32_t) , PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + struct xshmfence *addr; + addr = mmap (NULL, sizeof (struct xshmfence) , PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); if (addr == MAP_FAILED) { close (fd); return 0; @@ -138,7 +142,7 @@ xshmfence_map_shm(int fd) * Unap a shared memory fence @f. **/ void -xshmfence_unmap_shm(int32_t *f) +xshmfence_unmap_shm(struct xshmfence *f) { - munmap(f, sizeof (int32_t)); + munmap(f, sizeof (struct xshmfence)); } diff --git a/src/xshmfence.h b/src/xshmfence.h index f3cbad9..bbdbb53 100644 --- a/src/xshmfence.h +++ b/src/xshmfence.h @@ -23,27 +23,29 @@ #ifndef _XSHMFENCE_H_ #define _XSHMFENCE_H_ -#include <stdint.h> +#define HAVE_STRUCT_XSHMFENCE 1 + +struct xshmfence; int -xshmfence_trigger(int32_t *f); +xshmfence_trigger(struct xshmfence *f); int -xshmfence_await(int32_t *f); +xshmfence_await(struct xshmfence *f); int -xshmfence_query(int32_t *f); +xshmfence_query(struct xshmfence *f); void -xshmfence_reset(int32_t *f); +xshmfence_reset(struct xshmfence *f); int xshmfence_alloc_shm(void); -int32_t * +struct xshmfence * xshmfence_map_shm(int fd); void -xshmfence_unmap_shm(int32_t *f); +xshmfence_unmap_shm(struct xshmfence *f); #endif /* _XSHMFENCE_H_ */ diff --git a/src/xshmfenceint.h b/src/xshmfenceint.h index 3f5c561..e7b8b2a 100644 --- a/src/xshmfenceint.h +++ b/src/xshmfenceint.h @@ -34,6 +34,7 @@ #include <sys/mman.h> #include <errno.h> #include <values.h> +#include "xshmfence.h" static inline long sys_futex(void *addr1, int op, int val1, struct timespec *timeout, void *addr2, int val3) { |