Skip to content

Commit

Permalink
Merge ConcurrencyKit up to commit b87563b.
Browse files Browse the repository at this point in the history
Fix busybox compilation (gh#148) by merging the upstream fix.
  • Loading branch information
akopytov committed Jun 21, 2017
1 parent 5edb487 commit 1788acb
Show file tree
Hide file tree
Showing 20 changed files with 736 additions and 113 deletions.
1 change: 1 addition & 0 deletions third_party/concurrency_kit/ck/build/ck.build.s390x
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CFLAGS+=-O2 -D__s390x__
27 changes: 19 additions & 8 deletions third_party/concurrency_kit/ck/configure
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ WANT_PIC=yes

P_PWD=`pwd`
MAINTAINER='[email protected]'
VERSION=${VERSION:-'0.6.0'}
VERSION=${VERSION:-'1.0.0'}
VERSION_MAJOR='0'
BUILD="$PWD/build/ck.build"
PREFIX=${PREFIX:-"/usr/local"}
Expand Down Expand Up @@ -169,7 +169,8 @@ generate_stdout()
for option; do
case "$option" in
*=?*)
value=`expr -- "$option" : '[^=]*=\(.*\)'`
optname=`echo $option|cut -c 3-`
value=`expr "$optname" : '[^=]*=\(.*\)'`
;;
*=)
value=
Expand Down Expand Up @@ -294,7 +295,8 @@ for option; do
fi
;;
*=*)
NAME=`expr -- "$option" : '\([^=]*\)='`
optname=`echo $option|cut -c 3-`
NAME=`expr "$optname" : '\([^=]*\)='`
eval "$NAME='$value'"
export $NAME
;;
Expand Down Expand Up @@ -347,7 +349,7 @@ case "$SYSTEM" in
DCORES=`sysctl -n hw.ncpu`
SYSTEM=darwin
;;
MINGW32*)
MINGW32*|MSYS_NT*)
SYSTEM=mingw32
LDFLAGS="-mthreads $LDFLAGS"
;;
Expand Down Expand Up @@ -482,6 +484,13 @@ case $PLATFORM in
PLATFORM=aarch64
ENVIRONMENT=64
;;
"s390x")
RTM_ENABLE="CK_MD_RTM_DISABLE"
LSE_ENABLE="CK_MD_LSE_DISABLE"
MM="${MM:-"CK_MD_RMO"}"
PLATFORM=s390x
ENVIRONMENT=64
;;
*)
RTM_ENABLE="CK_MD_RTM_DISABLE"
LSE_ENABLE="CK_MD_LSE_DISABLE"
Expand Down Expand Up @@ -561,9 +570,11 @@ else
fi

printf "Finding suitable compiler........"
CC=`pathsearch "${CC:-cc}"`
if test -z "$CC" -o ! -x "$CC"; then
CC=`pathsearch "${CC:-gcc}"`
if test ! -x "${CC}"; then
CC=`pathsearch "${CC:-cc}"`
if test -z "$CC" -o ! -x "$CC"; then
CC=`pathsearch "${CC:-gcc}"`
fi
fi
assert "$CC" "not found"

Expand Down Expand Up @@ -596,7 +607,7 @@ int main(void) {
EOF

$CC -o .1 .1.c
COMPILER=`./.1`
COMPILER=`./.1 2> /dev/null`
r=$?
rm -f .1.c .1

Expand Down
95 changes: 84 additions & 11 deletions third_party/concurrency_kit/ck/include/ck_epoch.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ struct ck_epoch_ref {
};

struct ck_epoch_record {
ck_stack_entry_t record_next;
struct ck_epoch *global;
unsigned int state;
unsigned int epoch;
Expand All @@ -92,25 +93,31 @@ struct ck_epoch_record {
} local CK_CC_CACHELINE;
unsigned int n_pending;
unsigned int n_peak;
unsigned long n_dispatch;
unsigned int n_dispatch;
void *ct;
ck_stack_t pending[CK_EPOCH_LENGTH];
ck_stack_entry_t record_next;
} CK_CC_CACHELINE;
typedef struct ck_epoch_record ck_epoch_record_t;

struct ck_epoch {
unsigned int epoch;
char pad[CK_MD_CACHELINE - sizeof(unsigned int)];
ck_stack_t records;
unsigned int n_free;
ck_stack_t records;
};
typedef struct ck_epoch ck_epoch_t;

/*
* Internal functions.
*/
void _ck_epoch_addref(ck_epoch_record_t *, ck_epoch_section_t *);
void _ck_epoch_delref(ck_epoch_record_t *, ck_epoch_section_t *);
bool _ck_epoch_delref(ck_epoch_record_t *, ck_epoch_section_t *);

CK_CC_FORCE_INLINE static void *
ck_epoch_record_ct(const ck_epoch_record_t *record)
{

return ck_pr_load_ptr(&record->ct);
}

/*
* Marks the beginning of an epoch-protected section.
Expand Down Expand Up @@ -160,25 +167,30 @@ ck_epoch_begin(ck_epoch_record_t *record, ck_epoch_section_t *section)
}

/*
* Marks the end of an epoch-protected section.
* Marks the end of an epoch-protected section. Returns true if no more
* sections exist for the caller.
*/
CK_CC_FORCE_INLINE static void
CK_CC_FORCE_INLINE static bool
ck_epoch_end(ck_epoch_record_t *record, ck_epoch_section_t *section)
{

ck_pr_fence_release();
ck_pr_store_uint(&record->active, record->active - 1);

if (section != NULL)
_ck_epoch_delref(record, section);
return _ck_epoch_delref(record, section);

return;
return record->active == 0;
}

/*
* Defers the execution of the function pointed to by the "cb"
* argument until an epoch counter loop. This allows for a
* non-blocking deferral.
*
* We can get away without a fence here due to the monotonic nature
* of the epoch counter. Worst case, this will result in some delays
* before object destruction.
*/
CK_CC_FORCE_INLINE static void
ck_epoch_call(ck_epoch_record_t *record,
Expand All @@ -195,13 +207,74 @@ ck_epoch_call(ck_epoch_record_t *record,
return;
}

/*
* Same as ck_epoch_call, but allows for records to be shared and is reentrant.
*/
CK_CC_FORCE_INLINE static void
ck_epoch_call_strict(ck_epoch_record_t *record,
ck_epoch_entry_t *entry,
ck_epoch_cb_t *function)
{
struct ck_epoch *epoch = record->global;
unsigned int e = ck_pr_load_uint(&epoch->epoch);
unsigned int offset = e & (CK_EPOCH_LENGTH - 1);

ck_pr_inc_uint(&record->n_pending);
entry->function = function;

/* Store fence is implied by push operation. */
ck_stack_push_upmc(&record->pending[offset], &entry->stack_entry);
return;
}

/*
* This callback is used for synchronize_wait to allow for custom blocking
* behavior.
*/
typedef void ck_epoch_wait_cb_t(ck_epoch_t *, ck_epoch_record_t *,
void *);

/*
* Return latest epoch value. This operation provides load ordering.
*/
CK_CC_FORCE_INLINE static unsigned int
ck_epoch_value(const ck_epoch_t *ep)
{

ck_pr_fence_load();
return ck_pr_load_uint(&ep->epoch);
}

void ck_epoch_init(ck_epoch_t *);
ck_epoch_record_t *ck_epoch_recycle(ck_epoch_t *);
void ck_epoch_register(ck_epoch_t *, ck_epoch_record_t *);

/*
* Attempts to recycle an unused epoch record. If one is successfully
* allocated, the record context pointer is also updated.
*/
ck_epoch_record_t *ck_epoch_recycle(ck_epoch_t *, void *);

/*
* Registers an epoch record. An optional context pointer may be passed that
* is retrievable with ck_epoch_record_ct.
*/
void ck_epoch_register(ck_epoch_t *, ck_epoch_record_t *, void *);

/*
* Marks a record as available for re-use by a subsequent recycle operation.
* Note that the record cannot be physically destroyed.
*/
void ck_epoch_unregister(ck_epoch_record_t *);

bool ck_epoch_poll(ck_epoch_record_t *);
void ck_epoch_synchronize(ck_epoch_record_t *);
void ck_epoch_synchronize_wait(ck_epoch_t *, ck_epoch_wait_cb_t *, void *);
void ck_epoch_barrier(ck_epoch_record_t *);
void ck_epoch_barrier_wait(ck_epoch_record_t *, ck_epoch_wait_cb_t *, void *);

/*
* Reclaim entries associated with a record. This is safe to call only on
* the caller's record or records that are using call_strict.
*/
void ck_epoch_reclaim(ck_epoch_record_t *);

#endif /* CK_EPOCH_H */
2 changes: 2 additions & 0 deletions third_party/concurrency_kit/ck/include/ck_pr.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "gcc/sparcv9/ck_pr.h"
#elif defined(__ppc64__)
#include "gcc/ppc64/ck_pr.h"
#elif defined(__s390x__)
#include "gcc/s390x/ck_pr.h"
#elif defined(__ppc__)
#include "gcc/ppc/ck_pr.h"
#elif defined(__arm__)
Expand Down
97 changes: 97 additions & 0 deletions third_party/concurrency_kit/ck/include/gcc/s390x/ck_f_pr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* DO NOT EDIT. This is auto-generated from feature.sh */
#define CK_F_PR_ADD_32
#define CK_F_PR_ADD_64
#define CK_F_PR_ADD_INT
#define CK_F_PR_ADD_PTR
#define CK_F_PR_ADD_UINT
#define CK_F_PR_AND_32
#define CK_F_PR_AND_64
#define CK_F_PR_AND_INT
#define CK_F_PR_AND_PTR
#define CK_F_PR_AND_UINT
#define CK_F_PR_CAS_32
#define CK_F_PR_CAS_32_VALUE
#define CK_F_PR_CAS_64
#define CK_F_PR_CAS_64_VALUE
#define CK_F_PR_CAS_INT
#define CK_F_PR_CAS_INT_VALUE
#define CK_F_PR_CAS_PTR
#define CK_F_PR_CAS_PTR_VALUE
#define CK_F_PR_CAS_UINT
#define CK_F_PR_CAS_UINT_VALUE
#define CK_F_PR_DEC_32
#define CK_F_PR_DEC_64
#define CK_F_PR_DEC_INT
#define CK_F_PR_DEC_PTR
#define CK_F_PR_DEC_UINT
#define CK_F_PR_FAA_32
#define CK_F_PR_FAA_64
#define CK_F_PR_FAA_INT
#define CK_F_PR_FAA_PTR
#define CK_F_PR_FAA_UINT
#define CK_F_PR_FAS_32
#define CK_F_PR_FAS_64
#define CK_F_PR_FAS_INT
#define CK_F_PR_FAS_PTR
#define CK_F_PR_FAS_UINT
#define CK_F_PR_FAS_DOUBLE
#define CK_F_PR_FENCE_LOAD
#define CK_F_PR_FENCE_LOAD_DEPENDS
#define CK_F_PR_FENCE_MEMORY
#define CK_F_PR_FENCE_STORE
#define CK_F_PR_FENCE_STRICT_LOAD
#define CK_F_PR_FENCE_STRICT_LOAD_DEPENDS
#define CK_F_PR_FENCE_STRICT_MEMORY
#define CK_F_PR_FENCE_STRICT_STORE
#define CK_F_PR_INC_32
#define CK_F_PR_INC_64
#define CK_F_PR_INC_INT
#define CK_F_PR_INC_PTR
#define CK_F_PR_INC_UINT
#define CK_F_PR_LOAD_16
#define CK_F_PR_LOAD_32
#define CK_F_PR_LOAD_64
#define CK_F_PR_LOAD_8
#define CK_F_PR_LOAD_CHAR
#define CK_F_PR_LOAD_DOUBLE
#define CK_F_PR_LOAD_INT
#define CK_F_PR_LOAD_PTR
#define CK_F_PR_LOAD_SHORT
#define CK_F_PR_LOAD_UINT
#define CK_F_PR_NEG_32
#define CK_F_PR_NEG_64
#define CK_F_PR_NEG_INT
#define CK_F_PR_NEG_PTR
#define CK_F_PR_NEG_UINT
#define CK_F_PR_NOT_32
#define CK_F_PR_NOT_64
#define CK_F_PR_NOT_INT
#define CK_F_PR_NOT_PTR
#define CK_F_PR_NOT_UINT
#define CK_F_PR_OR_32
#define CK_F_PR_OR_64
#define CK_F_PR_OR_INT
#define CK_F_PR_OR_PTR
#define CK_F_PR_OR_UINT
#define CK_F_PR_STALL
#define CK_F_PR_STORE_16
#define CK_F_PR_STORE_32
#define CK_F_PR_STORE_64
#define CK_F_PR_STORE_8
#define CK_F_PR_STORE_CHAR
#define CK_F_PR_STORE_DOUBLE
#define CK_F_PR_STORE_INT
#define CK_F_PR_STORE_PTR
#define CK_F_PR_STORE_SHORT
#define CK_F_PR_STORE_UINT
#define CK_F_PR_SUB_32
#define CK_F_PR_SUB_64
#define CK_F_PR_SUB_INT
#define CK_F_PR_SUB_PTR
#define CK_F_PR_SUB_UINT
#define CK_F_PR_XOR_32
#define CK_F_PR_XOR_64
#define CK_F_PR_XOR_INT
#define CK_F_PR_XOR_PTR
#define CK_F_PR_XOR_UINT

Loading

0 comments on commit 1788acb

Please sign in to comment.