Repository: lucy-clownfish Updated Branches: refs/heads/master 8232c397f -> 0adb5d68c
Change LockFreeRegistry from Clownfish to pure C. Remove the Clownfish object underpinnings from LockFreeRegistry, so that it becomes an ordinary C object. Remove most bindings, so that it is only visible to the C core. The disabled Perl test remains in place, awaiting porting to C. Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/09ab2796 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/09ab2796 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/09ab2796 Branch: refs/heads/master Commit: 09ab2796242c19409a74964f4ae8630dbb09ec2b Parents: dbb1394 Author: Marvin Humphrey <[email protected]> Authored: Wed May 6 20:05:42 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Wed May 6 20:08:34 2015 -0700 ---------------------------------------------------------------------- runtime/c/src/Clownfish/Obj.c | 14 ------ runtime/core/Clownfish/Class.c | 2 +- runtime/core/Clownfish/Class.cfh | 1 - runtime/core/Clownfish/LockFreeRegistry.c | 20 +++++--- runtime/core/Clownfish/LockFreeRegistry.cfh | 42 ----------------- runtime/core/Clownfish/LockFreeRegistry.h | 49 ++++++++++++++++++++ .../core/Clownfish/Test/TestLockFreeRegistry.c | 2 +- runtime/go/clownfish/clownfish.go | 1 - runtime/go/ext/clownfish.c | 26 ----------- .../perl/buildlib/Clownfish/Build/Binding.pm | 9 ---- runtime/perl/lib/Clownfish.pm | 9 ---- runtime/perl/lib/Clownfish/LockFreeRegistry.pm | 25 ---------- runtime/perl/xs/XSBind.c | 18 +------ 13 files changed, 65 insertions(+), 153 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/c/src/Clownfish/Obj.c ---------------------------------------------------------------------- diff --git a/runtime/c/src/Clownfish/Obj.c b/runtime/c/src/Clownfish/Obj.c index f0bad24..cb9af10 100644 --- a/runtime/c/src/Clownfish/Obj.c +++ b/runtime/c/src/Clownfish/Obj.c @@ -44,14 +44,6 @@ SI_is_string_type(cfish_Class *klass) { return false; } -static CFISH_INLINE bool -SI_threadsafe_but_not_immortal(cfish_Class *klass) { - if (klass == CFISH_LOCKFREEREGISTRY) { - return true; - } - return false; -} - uint32_t cfish_get_refcount(void *vself) { cfish_Obj *self = (cfish_Obj*)vself; @@ -77,9 +69,6 @@ cfish_inc_refcount(void *vself) { else if (SI_immortal(klass)) { return self; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } self->refcount++; @@ -94,9 +83,6 @@ cfish_dec_refcount(void *vself) { if (SI_immortal(klass)) { return self->refcount; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } uint32_t modified_refcount = INT32_MAX; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/Class.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Class.c b/runtime/core/Clownfish/Class.c index d691253..40129f5 100644 --- a/runtime/core/Clownfish/Class.c +++ b/runtime/core/Clownfish/Class.c @@ -50,6 +50,7 @@ S_find_method(Class *self, const char *meth_name); static int32_t S_claim_parcel_id(void); +#define Class_registry cfish_Class_registry LockFreeRegistry *Class_registry = NULL; void @@ -102,7 +103,6 @@ Class_bootstrap(const ClassSpec *specs, size_t num_specs) || spec->klass == &BOOLNUM || spec->klass == &STRING || spec->klass == &STACKSTRING - || spec->klass == &LOCKFREEREGISTRY ) { klass->flags |= CFISH_fREFCOUNTSPECIAL; } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/Class.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Class.cfh b/runtime/core/Clownfish/Class.cfh index 4b95fda..e333ebe 100644 --- a/runtime/core/Clownfish/Class.cfh +++ b/runtime/core/Clownfish/Class.cfh @@ -35,7 +35,6 @@ class Clownfish::Class inherits Clownfish::Obj { Method **methods; cfish_method_t[1] vtable; /* flexible array */ - inert LockFreeRegistry *registry; inert size_t offset_of_parent; inert void http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/LockFreeRegistry.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/LockFreeRegistry.c b/runtime/core/Clownfish/LockFreeRegistry.c index 59e4608..5ab28fb 100644 --- a/runtime/core/Clownfish/LockFreeRegistry.c +++ b/runtime/core/Clownfish/LockFreeRegistry.c @@ -14,9 +14,9 @@ * limitations under the License. */ -#define C_CFISH_LOCKFREEREGISTRY #define CFISH_USE_SHORT_NAMES +#include "Clownfish/Obj.h" #include "Clownfish/LockFreeRegistry.h" #include "Clownfish/Err.h" #include "Clownfish/Class.h" @@ -24,6 +24,12 @@ #include "Clownfish/Util/Atomic.h" #include "Clownfish/Util/Memory.h" +struct cfish_LockFreeRegistry { + CFISH_OBJ_HEAD; + size_t capacity; + void *entries; +}; + typedef struct cfish_LFRegEntry { String *key; Obj *value; @@ -34,8 +40,8 @@ typedef struct cfish_LFRegEntry { LockFreeRegistry* LFReg_new(size_t capacity) { - LockFreeRegistry *self - = (LockFreeRegistry*)Class_Make_Obj(LOCKFREEREGISTRY); + LockFreeRegistry *self = CALLOCATE(1, sizeof(LockFreeRegistry)); + Class_Init_Obj(OBJ, self); return LFReg_init(self, capacity); } @@ -47,7 +53,7 @@ LFReg_init(LockFreeRegistry *self, size_t capacity) { } bool -LFReg_Register_IMP(LockFreeRegistry *self, String *key, Obj *value) { +LFReg_Register(LockFreeRegistry *self, String *key, Obj *value) { LFRegEntry *new_entry = NULL; int32_t hash_sum = Str_Hash_Sum(key); size_t bucket = (uint32_t)hash_sum % self->capacity; @@ -89,7 +95,7 @@ FIND_END_OF_LINKED_LIST: } Obj* -LFReg_Fetch_IMP(LockFreeRegistry *self, String *key) { +LFReg_Fetch(LockFreeRegistry *self, String *key) { int32_t hash_sum = Str_Hash_Sum(key); size_t bucket = (uint32_t)hash_sum % self->capacity; LFRegEntry **entries = (LFRegEntry**)self->entries; @@ -108,7 +114,7 @@ LFReg_Fetch_IMP(LockFreeRegistry *self, String *key) { } void -LFReg_Destroy_IMP(LockFreeRegistry *self) { +LFReg_Destroy(LockFreeRegistry *self) { LFRegEntry **entries = (LFRegEntry**)self->entries; for (size_t i = 0; i < self->capacity; i++) { @@ -123,7 +129,7 @@ LFReg_Destroy_IMP(LockFreeRegistry *self) { } FREEMEM(self->entries); - SUPER_DESTROY(self, LOCKFREEREGISTRY); + Obj_Destroy_IMP((Obj*)self); } http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/LockFreeRegistry.cfh ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/LockFreeRegistry.cfh b/runtime/core/Clownfish/LockFreeRegistry.cfh deleted file mode 100644 index cb6ddeb..0000000 --- a/runtime/core/Clownfish/LockFreeRegistry.cfh +++ /dev/null @@ -1,42 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -parcel Clownfish; - -/** Specialized lock free hash table for storing Classes. - */ -class Clownfish::LockFreeRegistry nickname LFReg inherits Clownfish::Obj { - - size_t capacity; - void *entries; - - inert incremented LockFreeRegistry* - new(size_t capacity); - - inert LockFreeRegistry* - init(LockFreeRegistry *self, size_t capacity); - - public void - Destroy(LockFreeRegistry *self); - - bool - Register(LockFreeRegistry *self, String *key, Obj *value); - - nullable Obj* - Fetch(LockFreeRegistry *self, String *key); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/LockFreeRegistry.h ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/LockFreeRegistry.h b/runtime/core/Clownfish/LockFreeRegistry.h new file mode 100644 index 0000000..e02910f --- /dev/null +++ b/runtime/core/Clownfish/LockFreeRegistry.h @@ -0,0 +1,49 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** Specialized lock free hash table for storing Classes. + */ + +struct cfish_Obj; +struct cfish_String; + +typedef struct cfish_LockFreeRegistry cfish_LockFreeRegistry; + +cfish_LockFreeRegistry* +cfish_LFReg_new(size_t capacity); + +cfish_LockFreeRegistry* +cfish_LFReg_init(cfish_LockFreeRegistry *self, size_t capacity); + +void +CFISH_LFReg_Destroy(cfish_LockFreeRegistry *self); + +bool +CFISH_LFReg_Register(cfish_LockFreeRegistry *self, struct cfish_String *key, + struct cfish_Obj *value); + +struct cfish_Obj* +CFISH_LFReg_Fetch(cfish_LockFreeRegistry *self, struct cfish_String *key); + +#ifdef CFISH_USE_SHORT_NAMES + #define LockFreeRegistry cfish_LockFreeRegistry + #define LFReg_new cfish_LFReg_new + #define LFReg_init cfish_LFReg_init + #define LFReg_Destroy CFISH_LFReg_Destroy + #define LFReg_Register CFISH_LFReg_Register + #define LFReg_Fetch CFISH_LFReg_Fetch +#endif + http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/core/Clownfish/Test/TestLockFreeRegistry.c ---------------------------------------------------------------------- diff --git a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c index 5bc4d30..335d8c6 100644 --- a/runtime/core/Clownfish/Test/TestLockFreeRegistry.c +++ b/runtime/core/Clownfish/Test/TestLockFreeRegistry.c @@ -73,7 +73,7 @@ test_all(TestBatchRunner *runner) { DECREF(baz); DECREF(bar); DECREF(foo); - DECREF(registry); + LFReg_Destroy(registry); } void http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/go/clownfish/clownfish.go ---------------------------------------------------------------------- diff --git a/runtime/go/clownfish/clownfish.go b/runtime/go/clownfish/clownfish.go index d7d3926..143c7c6 100644 --- a/runtime/go/clownfish/clownfish.go +++ b/runtime/go/clownfish/clownfish.go @@ -28,7 +28,6 @@ package clownfish #include "Clownfish/Vector.h" #include "Clownfish/String.h" #include "Clownfish/Util/Memory.h" -#include "Clownfish/LockFreeRegistry.h" #include "Clownfish/Method.h" extern void http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/go/ext/clownfish.c ---------------------------------------------------------------------- diff --git a/runtime/go/ext/clownfish.c b/runtime/go/ext/clownfish.c index bd33c56..e350689 100644 --- a/runtime/go/ext/clownfish.c +++ b/runtime/go/ext/clownfish.c @@ -19,7 +19,6 @@ #define C_CFISH_CLASS #define C_CFISH_METHOD #define C_CFISH_ERR -#define C_CFISH_LOCKFREEREGISTRY #include <stdio.h> #include <stdlib.h> @@ -33,7 +32,6 @@ #include "Clownfish/Util/Memory.h" #include "Clownfish/String.h" #include "Clownfish/Vector.h" -#include "Clownfish/LockFreeRegistry.h" /* These symbols must be assigned real values during Go initialization, * which we'll confirm in Err_init(). */ @@ -61,14 +59,6 @@ SI_is_string_type(cfish_Class *klass) { return false; } -static CFISH_INLINE bool -SI_threadsafe_but_not_immortal(cfish_Class *klass) { - if (klass == CFISH_LOCKFREEREGISTRY) { - return true; - } - return false; -} - uint32_t cfish_get_refcount(void *vself) { cfish_Obj *self = (cfish_Obj*)vself; @@ -94,9 +84,6 @@ cfish_inc_refcount(void *vself) { else if (SI_immortal(klass)) { return self; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } self->refcount++; @@ -111,9 +98,6 @@ cfish_dec_refcount(void *vself) { if (SI_immortal(klass)) { return self->refcount; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } uint32_t modified_refcount = INT32_MAX; @@ -260,13 +244,3 @@ Err_trap(Err_Attempt_t routine, void *context) { return GoCfish_TrapErr(routine, context); } -/************************** LockFreeRegistry *******************************/ - -void* -LFReg_To_Host_IMP(LockFreeRegistry *self) { - UNUSED_VAR(self); - THROW(ERR, "TODO"); - UNREACHABLE_RETURN(void*); -} - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/perl/buildlib/Clownfish/Build/Binding.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/buildlib/Clownfish/Build/Binding.pm b/runtime/perl/buildlib/Clownfish/Build/Binding.pm index c70d528..4e0ef0b 100644 --- a/runtime/perl/buildlib/Clownfish/Build/Binding.pm +++ b/runtime/perl/buildlib/Clownfish/Build/Binding.pm @@ -583,15 +583,6 @@ sub bind_class { MODULE = Clownfish PACKAGE = Clownfish::Class SV* -_get_registry() -CODE: - if (cfish_Class_registry == NULL) { - cfish_Class_init_registry(); - } - RETVAL = (SV*)CFISH_Obj_To_Host((cfish_Obj*)cfish_Class_registry); -OUTPUT: RETVAL - -SV* fetch_class(unused_sv, class_name_sv) SV *unused_sv; SV *class_name_sv; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/perl/lib/Clownfish.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/lib/Clownfish.pm b/runtime/perl/lib/Clownfish.pm index bfcc23a..78bda7f 100644 --- a/runtime/perl/lib/Clownfish.pm +++ b/runtime/perl/lib/Clownfish.pm @@ -64,15 +64,6 @@ sub error {$Clownfish::Err::error} } { - package Clownfish::LockFreeRegistry; - our $VERSION = '0.004000'; - $VERSION = eval $VERSION; - no warnings 'redefine'; - sub CLONE_SKIP { 0; } - sub DESTROY { } # leak all -} - -{ package Clownfish::Obj; our $VERSION = '0.004000'; $VERSION = eval $VERSION; http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/perl/lib/Clownfish/LockFreeRegistry.pm ---------------------------------------------------------------------- diff --git a/runtime/perl/lib/Clownfish/LockFreeRegistry.pm b/runtime/perl/lib/Clownfish/LockFreeRegistry.pm deleted file mode 100644 index 95f2a91..0000000 --- a/runtime/perl/lib/Clownfish/LockFreeRegistry.pm +++ /dev/null @@ -1,25 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -package Clownfish::LockFreeRegistry; -use Clownfish; -our $VERSION = '0.004000'; -$VERSION = eval $VERSION; - -1; - -__END__ - - http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/09ab2796/runtime/perl/xs/XSBind.c ---------------------------------------------------------------------- diff --git a/runtime/perl/xs/XSBind.c b/runtime/perl/xs/XSBind.c index fd5fd09..f96cecd 100644 --- a/runtime/perl/xs/XSBind.c +++ b/runtime/perl/xs/XSBind.c @@ -18,13 +18,11 @@ #define C_CFISH_OBJ #define C_CFISH_CLASS -#define C_CFISH_LOCKFREEREGISTRY #define NEED_newRV_noinc #include "charmony.h" #include "XSBind.h" #include "Clownfish/CharBuf.h" #include "Clownfish/HashIterator.h" -#include "Clownfish/LockFreeRegistry.h" #include "Clownfish/Method.h" #include "Clownfish/Test/TestThreads.h" #include "Clownfish/TestHarness/TestBatchRunner.h" @@ -624,14 +622,6 @@ SI_is_string_type(cfish_Class *klass) { return false; } -static CFISH_INLINE bool -SI_threadsafe_but_not_immortal(cfish_Class *klass) { - if (klass == CFISH_LOCKFREEREGISTRY) { - return true; - } - return false; -} - static void S_lazy_init_host_obj(pTHX_ cfish_Obj *self) { SV *inner_obj = newSV(0); @@ -659,7 +649,7 @@ S_lazy_init_host_obj(pTHX_ cfish_Obj *self) { // Overwrite refcount with host object. cfish_Class *klass = self->klass; - if (SI_immortal(klass) || SI_threadsafe_but_not_immortal(klass)) { + if (SI_immortal(klass)) { SvSHARE(inner_obj); if (!cfish_Atomic_cas_ptr((void**)&self->ref, old_ref.host_obj, inner_obj)) { // Another thread beat us to it. Now we have a Perl object to defuse. @@ -706,9 +696,6 @@ cfish_inc_refcount(void *vself) { else if (SI_immortal(klass)) { return self; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } if (self->ref.count & XSBIND_REFCOUNT_FLAG) { @@ -732,9 +719,6 @@ cfish_dec_refcount(void *vself) { if (SI_immortal(klass)) { return 1; } - else if (SI_threadsafe_but_not_immortal(klass)) { - // TODO: use atomic operation - } } uint32_t modified_refcount = I32_MAX;
