ck_pring
Abel Mathew 13 years ago
commit b9c6532b2a

@ -66,7 +66,6 @@ distribution: clean
rm -f include/ck_md.h rm -f include/ck_md.h
rm -f build/regressions.build rm -f build/regressions.build
rm -f build/ck.build rm -f build/ck.build
rm -f build/ck.spec
rm -f build/ck.pc rm -f build/ck.pc
rm -f Makefile rm -f Makefile
rm -f doc/Makefile rm -f doc/Makefile

@ -53,12 +53,12 @@ rm -rf $RPM_BUILD_ROOT
%files %files
%defattr(-,root,root,-) %defattr(-,root,root,-)
%{_libdir}/libck.so
%{_libdir}/libck.so.@VERSION@ %{_libdir}/libck.so.@VERSION@
%{_libdir}/libck.so.@VERSION_MAJOR@ %{_libdir}/libck.so.@VERSION_MAJOR@
%files devel %files devel
%defattr(-,root,root) %defattr(-,root,root)
%{_libdir}/libck.so
%{_includedir}/%{name}/*.h %{_includedir}/%{name}/*.h
%{_includedir}/%{name}/*/*.h %{_includedir}/%{name}/*/*.h
%{_includedir}/%{name}/*/*/*.h %{_includedir}/%{name}/*/*/*.h

2
configure vendored

@ -32,7 +32,7 @@ EXIT_SUCCESS=0
EXIT_FAILURE=1 EXIT_FAILURE=1
MAINTAINER='sbahra@repnop.org' MAINTAINER='sbahra@repnop.org'
VERSION='0.2.5' VERSION='0.2.6'
VERSION_MAJOR='0' VERSION_MAJOR='0'
BUILD="$PWD/build/ck.build" BUILD="$PWD/build/ck.build"
PREFIX=${PREFIX:-"/usr/local"} PREFIX=${PREFIX:-"/usr/local"}

@ -34,15 +34,17 @@ Concurrency Kit (libck, \-lck)
.Sh SYNOPSIS .Sh SYNOPSIS
.In ck_ht.h .In ck_ht.h
.Ft void .Ft void
.Fn ck_ht_entry_set "ck_ht_entry_t *entry" "uintptr_t key" "uintptr_t value" .Fn ck_ht_entry_set_direct "ck_ht_entry_t *entry" "ck_ht_hash_t h" "uintptr_t key" "uintptr_t value"
.Sh DESCRIPTION .Sh DESCRIPTION
The The
.Fn ck_ht_entry_set .Fn ck_ht_entry_set
function will initialize the object pointed to by function will initialize the object pointed to by
.Fa entry .Fa entry
with the key value specified in the with the hash value specified by the
.Fa h
argument, the key value specified in the
.Fa key .Fa key
argument and a value specified by the argument and the value specified by the
.Fa value .Fa value
argument. argument.
.Pp .Pp

@ -45,4 +45,8 @@
#define CK_CC_PAD(x) union { char pad[x]; } #define CK_CC_PAD(x) union { char pad[x]; }
#ifndef CK_CC_ALIASED
#define CK_CC_ALIASED
#endif
#endif /* _CK_CC_H */ #endif /* _CK_CC_H */

@ -249,8 +249,9 @@ ck_fifo_mpmc_enqueue(struct ck_fifo_mpmc *fifo,
for (;;) { for (;;) {
tail.generation = ck_pr_load_ptr(&fifo->tail.generation); tail.generation = ck_pr_load_ptr(&fifo->tail.generation);
ck_pr_fence_load();
tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer); tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer);
ck_pr_fence_load_depends();
next.generation = ck_pr_load_ptr(&tail.pointer->next.generation); next.generation = ck_pr_load_ptr(&tail.pointer->next.generation);
next.pointer = ck_pr_load_ptr(&tail.pointer->next.pointer); next.pointer = ck_pr_load_ptr(&tail.pointer->next.pointer);
@ -299,8 +300,9 @@ ck_fifo_mpmc_tryenqueue(struct ck_fifo_mpmc *fifo,
ck_pr_fence_store(); ck_pr_fence_store();
tail.generation = ck_pr_load_ptr(&fifo->tail.generation); tail.generation = ck_pr_load_ptr(&fifo->tail.generation);
ck_pr_fence_load();
tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer); tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer);
ck_pr_fence_load_depends();
next.generation = ck_pr_load_ptr(&tail.pointer->next.generation); next.generation = ck_pr_load_ptr(&tail.pointer->next.generation);
next.pointer = ck_pr_load_ptr(&tail.pointer->next.pointer); next.pointer = ck_pr_load_ptr(&tail.pointer->next.pointer);
@ -344,9 +346,10 @@ ck_fifo_mpmc_dequeue(struct ck_fifo_mpmc *fifo,
for (;;) { for (;;) {
head.generation = ck_pr_load_ptr(&fifo->head.generation); head.generation = ck_pr_load_ptr(&fifo->head.generation);
ck_pr_fence_load();
head.pointer = ck_pr_load_ptr(&fifo->head.pointer); head.pointer = ck_pr_load_ptr(&fifo->head.pointer);
tail.generation = ck_pr_load_ptr(&fifo->tail.generation); tail.generation = ck_pr_load_ptr(&fifo->tail.generation);
ck_pr_fence_load();
tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer); tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer);
next.generation = ck_pr_load_ptr(&head.pointer->next.generation); next.generation = ck_pr_load_ptr(&head.pointer->next.generation);
@ -388,9 +391,11 @@ ck_fifo_mpmc_trydequeue(struct ck_fifo_mpmc *fifo,
struct ck_fifo_mpmc_pointer head, tail, next, update; struct ck_fifo_mpmc_pointer head, tail, next, update;
head.generation = ck_pr_load_ptr(&fifo->head.generation); head.generation = ck_pr_load_ptr(&fifo->head.generation);
ck_pr_fence_load();
head.pointer = ck_pr_load_ptr(&fifo->head.pointer); head.pointer = ck_pr_load_ptr(&fifo->head.pointer);
tail.generation = ck_pr_load_ptr(&fifo->tail.generation); tail.generation = ck_pr_load_ptr(&fifo->tail.generation);
ck_pr_fence_load();
tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer); tail.pointer = ck_pr_load_ptr(&fifo->tail.pointer);
next.generation = ck_pr_load_ptr(&head.pointer->next.generation); next.generation = ck_pr_load_ptr(&head.pointer->next.generation);

@ -134,9 +134,9 @@ ck_hp_fifo_dequeue_mpmc(ck_hp_record_t *record,
struct ck_hp_fifo_entry *head, *tail, *next; struct ck_hp_fifo_entry *head, *tail, *next;
for (;;) { for (;;) {
tail = ck_pr_load_ptr(&fifo->tail);
head = ck_pr_load_ptr(&fifo->head); head = ck_pr_load_ptr(&fifo->head);
ck_pr_fence_load();
tail = ck_pr_load_ptr(&fifo->tail);
ck_hp_set(record, 0, head); ck_hp_set(record, 0, head);
ck_pr_fence_memory(); ck_pr_fence_memory();
if (head != ck_pr_load_ptr(&fifo->head)) if (head != ck_pr_load_ptr(&fifo->head))
@ -169,8 +169,9 @@ ck_hp_fifo_trydequeue_mpmc(ck_hp_record_t *record,
{ {
struct ck_hp_fifo_entry *head, *tail, *next; struct ck_hp_fifo_entry *head, *tail, *next;
tail = ck_pr_load_ptr(&fifo->tail);
head = ck_pr_load_ptr(&fifo->head); head = ck_pr_load_ptr(&fifo->head);
ck_pr_fence_load();
tail = ck_pr_load_ptr(&fifo->tail);
ck_hp_set(record, 0, head); ck_hp_set(record, 0, head);
ck_pr_fence_memory(); ck_pr_fence_memory();
if (head != ck_pr_load_ptr(&fifo->head)) if (head != ck_pr_load_ptr(&fifo->head))

@ -188,12 +188,19 @@ ck_ht_entry_set(struct ck_ht_entry *entry,
CK_CC_INLINE static void CK_CC_INLINE static void
ck_ht_entry_set_direct(struct ck_ht_entry *entry, ck_ht_entry_set_direct(struct ck_ht_entry *entry,
ck_ht_hash_t h,
uintptr_t key, uintptr_t key,
uintptr_t value) uintptr_t value)
{ {
entry->key = key; entry->key = key;
entry->value = value; entry->value = value;
#ifndef CK_HT_PP
entry->hash = h.value;
#else
(void)h;
#endif
return; return;
} }
@ -219,7 +226,6 @@ bool ck_ht_next(ck_ht_t *, ck_ht_iterator_t *, ck_ht_entry_t **entry);
void ck_ht_hash(ck_ht_hash_t *, ck_ht_t *, const void *, uint16_t); void ck_ht_hash(ck_ht_hash_t *, ck_ht_t *, const void *, uint16_t);
void ck_ht_hash_direct(ck_ht_hash_t *, ck_ht_t *, uintptr_t); void ck_ht_hash_direct(ck_ht_hash_t *, ck_ht_t *, uintptr_t);
bool ck_ht_allocator_set(struct ck_malloc *);
bool ck_ht_init(ck_ht_t *, enum ck_ht_mode, ck_ht_hash_cb_t *, struct ck_malloc *, uint64_t, uint64_t); bool ck_ht_init(ck_ht_t *, enum ck_ht_mode, ck_ht_hash_cb_t *, struct ck_malloc *, uint64_t, uint64_t);
void ck_ht_destroy(ck_ht_t *); void ck_ht_destroy(ck_ht_t *);
bool ck_ht_set_spmc(ck_ht_t *, ck_ht_hash_t, ck_ht_entry_t *); bool ck_ht_set_spmc(ck_ht_t *, ck_ht_hash_t, ck_ht_entry_t *);

@ -40,7 +40,7 @@ typedef struct ck_stack_entry ck_stack_entry_t;
struct ck_stack { struct ck_stack {
struct ck_stack_entry *head; struct ck_stack_entry *head;
char *generation CK_CC_PACKED; char *generation CK_CC_PACKED;
}; } CK_CC_ALIASED;
typedef struct ck_stack ck_stack_t; typedef struct ck_stack ck_stack_t;
#define CK_STACK_INITIALIZER { NULL, NULL } #define CK_STACK_INITIALIZER { NULL, NULL }

@ -75,4 +75,11 @@
#pragma GCC poison malloc free #pragma GCC poison malloc free
#endif #endif
/*
* Some compilers are overly strict regarding aliasing semantics.
* Unfortunately, in many cases it makes more sense to pay aliasing
* cost rather than overly expensive register spillage.
*/
#define CK_CC_ALIASED __attribute__((__may_alias__))
#endif /* _CK_GCC_CC_H */ #endif /* _CK_GCC_CC_H */

@ -162,7 +162,7 @@ table_replace(uintptr_t value)
ck_ht_hash_t h; ck_ht_hash_t h;
ck_ht_hash_direct(&h, &ht, value); ck_ht_hash_direct(&h, &ht, value);
ck_ht_entry_set_direct(&entry, value, 6605241); ck_ht_entry_set_direct(&entry, h, value, 6605241);
return ck_ht_set_spmc(&ht, h, &entry); return ck_ht_set_spmc(&ht, h, &entry);
} }
@ -187,7 +187,7 @@ table_insert(uintptr_t value)
ck_ht_hash_t h; ck_ht_hash_t h;
ck_ht_hash_direct(&h, &ht, value); ck_ht_hash_direct(&h, &ht, value);
ck_ht_entry_set_direct(&entry, value, value); ck_ht_entry_set_direct(&entry, h, value, value);
return ck_ht_put_spmc(&ht, h, &entry); return ck_ht_put_spmc(&ht, h, &entry);
} }

@ -254,7 +254,7 @@ main(void)
l = 0; l = 0;
for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) { for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
ck_ht_hash_direct(&h, &ht, direct[i]); ck_ht_hash_direct(&h, &ht, direct[i]);
ck_ht_entry_set_direct(&entry, direct[i], (uintptr_t)test[i]); ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)test[i]);
l += ck_ht_put_spmc(&ht, h, &entry) == false; l += ck_ht_put_spmc(&ht, h, &entry) == false;
} }
@ -265,7 +265,7 @@ main(void)
for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) { for (i = 0; i < sizeof(direct) / sizeof(*direct); i++) {
ck_ht_hash_direct(&h, &ht, direct[i]); ck_ht_hash_direct(&h, &ht, direct[i]);
ck_ht_entry_set_direct(&entry, direct[i], (uintptr_t)"REPLACED"); ck_ht_entry_set_direct(&entry, h, direct[i], (uintptr_t)"REPLACED");
l += ck_ht_set_spmc(&ht, h, &entry) == false; l += ck_ht_set_spmc(&ht, h, &entry) == false;
} }

@ -404,9 +404,17 @@ restart:
key = ck_ht_entry_key(previous); key = ck_ht_entry_key(previous);
key_length = ck_ht_entry_key_length(previous); key_length = ck_ht_entry_key_length(previous);
#ifndef CK_HT_PP
h.value = previous->hash;
#else
table->h(&h, key, key_length, table->seed); table->h(&h, key, key_length, table->seed);
#endif
} else { } else {
#ifndef CK_HT_PP
h.value = previous->hash;
#else
table->h(&h, &previous->key, sizeof(previous->key), table->seed); table->h(&h, &previous->key, sizeof(previous->key), table->seed);
#endif
} }
offset = h.value & update->mask; offset = h.value & update->mask;

Loading…
Cancel
Save