From 5f1515a4c7aa6c69522676dbcf28e1d928654597 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Fri, 8 Apr 2011 11:28:39 +0200 Subject: [PATCH] added locking routines --- src/bithacks.h | 2 +- src/locking_x86.h | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/bithacks.h b/src/bithacks.h index 6586a3de..d4543dd1 100644 --- a/src/bithacks.h +++ b/src/bithacks.h @@ -50,7 +50,7 @@ static inline float fabs2(float x) */ static inline int cmp(int x, int y) { - return !!((x > y) - (x < y)); + return (x > y) - (x < y); } /* diff --git a/src/locking_x86.h b/src/locking_x86.h index 2b2dedd0..d12a448d 100644 --- a/src/locking_x86.h +++ b/src/locking_x86.h @@ -5,15 +5,59 @@ * Nao-Team HTWK, * Faculty of Computer Science, Mathematics and Natural Sciences, * Leipzig University of Applied Sciences (HTWK Leipzig) - * - * Mostly compiler related stuff. - * Much code taken from the Linux kernel. For such code, the option - * to redistribute under later versions of GPL might not be available. */ #ifndef LOCKING_X86_H #define LOCKING_X86_H -/* TODO */ +#include + +struct nao_spin_lock { + pthread_spinlock_t lock; +}; + +struct nao_mutex_lock { + pthread_mutex_t lock; +}; + +static inline int nao_spin_lock_init(struct nao_spin_lock *l) +{ + return -pthread_spin_init(&l->lock, 0); +} + +static inline void nao_spin_lock_destroy(struct nao_spin_lock *l) +{ + pthread_spin_destroy(&l->lock); +} + +static inline void nao_spin_lock_lock(struct nao_spin_lock *l) +{ + pthread_spin_lock(&l->lock); +} + +static inline void nao_spin_lock_unlock(struct nao_spin_lock *l) +{ + pthread_spin_unlock(&l->lock); +} + +static inline int nao_mutex_lock_init(struct nao_mutex_lock *l) +{ + return -pthread_mutex_init(&l->lock, 0); +} + +static inline void nao_mutex_lock_destroy(struct nao_mutex_lock *l) +{ + pthread_mutex_destroy(&l->lock); +} + +static inline void nao_mutex_lock_lock(struct nao_mutex_lock *l) +{ + pthread_mutex_lock(&l->lock); +} + +static inline void nao_mutex_lock_unlock(struct nao_mutex_lock *l) +{ + pthread_mutex_unlock(&l->lock); +} #endif /* LOCKING_X86_H */ -- 2.11.4.GIT