ck_spinlock: Provide a default implementation.

Several users in the past have noted it was difficult for them
to decide what spinlock implementation to use. In light of this,
a light-weight greedy default is chosen (currently ck_spinlock_fas).
ck_pring
Samy Al Bahra 13 years ago
parent 50f6f6ee02
commit 1cefea7eb6

@ -29,11 +29,26 @@
#include <ck_backoff.h>
#include <ck_cc.h>
#include <ck_limits.h>
#include <ck_md.h>
#include <ck_pr.h>
#include <stdbool.h>
#include <stddef.h>
#include <ck_limits.h>
/*
* On tested x86, x86_64, PPC64 and SPARC64 targets,
* ck_spinlock_fas proved to have lowest latency
* in fast path testing or negligible degradation
* from faster but less robust implementations.
*/
#define CK_SPINLOCK_INITIALIZER CK_SPINLOCK_FAS_INITIALIZER
#define ck_spinlock_t ck_spinlock_fas_t
#define ck_spinlock_init(x) ck_spinlock_fas_init(x)
#define ck_spinlock_lock(x) ck_spinlock_fas_lock(x)
#define ck_spinlock_lock_eb(x) ck_spinlock_fas_lock_eb(x)
#define ck_spinlock_unlock(x) ck_spinlock_fas_unlock(x)
#define ck_spinlock_locked(x) ck_spinlock_fas_locked(x)
#define ck_spinlock_trylock(x) ck_spinlock_fas_trylock(x)
#ifndef CK_F_SPINLOCK_ANDERSON
#define CK_F_SPINLOCK_ANDERSON

@ -8,10 +8,17 @@ OBJECTS=ck_ticket.THROUGHPUT ck_ticket.LATENCY \
ck_clh.THROUGHPUT ck_clh.LATENCY \
linux_spinlock.THROUGHPUT linux_spinlock.LATENCY \
ck_ticket_pb.THROUGHPUT ck_ticket_pb.LATENCY \
ck_anderson.THROUGHPUT ck_anderson.LATENCY
ck_anderson.THROUGHPUT ck_anderson.LATENCY \
ck_spinlock.THROUGHPUT ck_spinlock.LATENCY
all: $(OBJECTS)
ck_spinlock.THROUGHPUT: ck_spinlock.c
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_spinlock.THROUGHPUT ck_spinlock.c
ck_spinlock.LATENCY: ck_spinlock.c
$(CC) -DLATENCY $(CFLAGS) -o ck_spinlock.LATENCY ck_spinlock.c
ck_ticket.THROUGHPUT: ck_ticket.c
$(CC) -DTHROUGHPUT $(CFLAGS) -o ck_ticket.THROUGHPUT ck_ticket.c

@ -0,0 +1,7 @@
#include "../ck_spinlock.h"
#ifdef THROUGHPUT
#include "throughput.h"
#elif defined(LATENCY)
#include "latency.h"
#endif

@ -0,0 +1,5 @@
#define LOCK_NAME "ck_spinlock"
#define LOCK_DEFINE static ck_spinlock_t CK_CC_CACHELINE lock = CK_SPINLOCK_INITIALIZER
#define LOCK ck_spinlock_lock_eb(&lock)
#define UNLOCK ck_spinlock_unlock(&lock)

@ -1,11 +1,14 @@
.PHONY: clean
all: ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock \
ck_ticket_pb ck_anderson
ck_ticket_pb ck_anderson ck_spinlock
linux_spinlock: linux_spinlock.c
$(CC) $(CFLAGS) -o linux_spinlock linux_spinlock.c
ck_spinlock: ck_spinlock.c
$(CC) $(CFLAGS) -o ck_spinlock ck_spinlock.c
ck_ticket_pb: ck_ticket_pb.c
$(CC) $(CFLAGS) -o ck_ticket_pb ck_ticket_pb.c
@ -32,7 +35,7 @@ ck_dec: ck_dec.c
clean:
rm -rf ck_ticket ck_mcs ck_dec ck_cas ck_fas ck_clh linux_spinlock ck_ticket_pb \
ck_anderson test_and_set *.dSYM
ck_anderson ck_spinlock *.dSYM
include ../../../build/regressions.build
CFLAGS+=$(PTHREAD_CFLAGS) -D_GNU_SOURCE -lm

@ -0,0 +1,2 @@
#include "../ck_spinlock.h"
#include "validate.h"
Loading…
Cancel
Save