couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [6/8] git commit: Remove the ability to share khash's
Date Fri, 01 Aug 2014 09:06:19 GMT
Remove the ability to share khash's

I don't need this right now and it'll interfere with iterators.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-khash/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-khash/commit/4c046225
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-khash/tree/4c046225
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-khash/diff/4c046225

Branch: refs/heads/windsor-merge
Commit: 4c04622553d8d299fec8118920e756edcc399a6f
Parents: 9b44d23
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Sat May 11 14:49:02 2013 -0500
Committer: Robert Newson <rnewson@apache.org>
Committed: Wed Jul 30 17:16:33 2014 +0100

----------------------------------------------------------------------
 c_src/khash.c | 105 +++++------------------------------------------------
 src/khash.erl |   2 +-
 2 files changed, 11 insertions(+), 96 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/4c046225/c_src/khash.c
----------------------------------------------------------------------
diff --git a/c_src/khash.c b/c_src/khash.c
index 8107029..de70490 100644
--- a/c_src/khash.c
+++ b/c_src/khash.c
@@ -16,7 +16,6 @@ typedef struct
 {
     ERL_NIF_TERM atom_ok;
     ERL_NIF_TERM atom_error;
-    ERL_NIF_TERM atom_shared;
     ERL_NIF_TERM atom_value;
     ERL_NIF_TERM atom_not_found;
     ErlNifResourceType* res_hash;
@@ -36,7 +35,6 @@ typedef struct
     int version;
     hash_t* h;
     ErlNifPid p;
-    ErlNifMutex* l;
 } khash_t;
 
 
@@ -73,57 +71,11 @@ make_error(ErlNifEnv* env, khash_priv* priv, ERL_NIF_TERM reason)
 
 
 static inline int
-has_option(ErlNifEnv* env, ERL_NIF_TERM opts, ERL_NIF_TERM opt)
-{
-    ERL_NIF_TERM head;
-    ERL_NIF_TERM tail = opts;
-    const ERL_NIF_TERM* elems;
-    int arity;
-
-    if(!enif_is_list(env, opts)) {
-        return 0;
-    }
-
-    while(enif_get_list_cell(env, tail, &head, &tail)) {
-        if(enif_compare(head, opt) == 0) {
-            return 1;
-        }
-
-        if(!enif_is_tuple(env, head)) {
-            continue;
-        }
-
-        if(!enif_get_tuple(env, head, &arity, &elems)) {
-            continue;
-        }
-
-        if(arity == 0) {
-            continue;
-        }
-
-        if(enif_compare(elems[0], opt)) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
-
-static inline int
-lock_hash(ErlNifEnv* env, khash_t* khash)
+check_pid(ErlNifEnv* env, khash_t* khash)
 {
     ErlNifPid pid;
-
-    // shared hash
-    if(khash->l != NULL) {
-        enif_mutex_lock(khash->l);
-        return 1;
-    }
-
-    // Else check that we're being called from the pid
-    // that created the hash.
     enif_self(env, &pid);
+
     if(enif_compare(pid.pid, khash->p.pid) == 0) {
         return 1;
     }
@@ -132,15 +84,6 @@ lock_hash(ErlNifEnv* env, khash_t* khash)
 }
 
 
-static inline void
-unlock_hash(ErlNifEnv* env, khash_t* khash)
-{
-    if(khash->l != NULL) {
-        enif_mutex_unlock(khash->l);
-    }
-}
-
-
 hnode_t*
 khnode_alloc(void* ctx)
 {
@@ -214,12 +157,6 @@ khash_create_int(ErlNifEnv* env, khash_priv* priv, ERL_NIF_TERM opts)
     kl_hash_set_allocator(khash->h, khnode_alloc, khnode_free, NULL);
     enif_self(env, &(khash->p));
 
-    if(has_option(env, opts, priv->atom_shared)) {
-        khash->l = enif_mutex_create(NULL);
-    } else {
-        khash->l = NULL;
-    }
-
     return khash;
 }
 
@@ -257,10 +194,6 @@ khash_free(ErlNifEnv* env, void* obj)
         kl_hash_destroy(khash->h);
     }
 
-    if(khash->l != NULL) {
-        enif_mutex_destroy(khash->l);
-    }
-
     return;
 }
 
@@ -286,7 +219,7 @@ khash_to_list(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
@@ -300,8 +233,6 @@ khash_to_list(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         ret = enif_make_list_cell(env, tuple, ret);
     }
 
-    unlock_hash(env, khash);
-
     return ret;
 }
 
@@ -320,14 +251,12 @@ khash_clear(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
     kl_hash_free_nodes(khash->h);
 
-    unlock_hash(env, khash);
-
     return priv->atom_ok;
 }
 
@@ -359,7 +288,7 @@ khash_lookup(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
@@ -372,8 +301,6 @@ khash_lookup(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         ret = enif_make_tuple2(env, priv->atom_value, ret);
     }
 
-    unlock_hash(env, khash);
-
     return ret;
 }
 
@@ -395,7 +322,7 @@ khash_get(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
@@ -407,8 +334,6 @@ khash_get(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         ret = enif_make_copy(env, node->val);
     }
 
-    unlock_hash(env, khash);
-
     return ret;
 }
 
@@ -429,7 +354,7 @@ khash_put(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
@@ -447,8 +372,6 @@ khash_put(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         node->val = enif_make_copy(node->env, argv[2]);
     }
 
-    unlock_hash(env, khash);
-
     return priv->atom_ok;
 }
 
@@ -469,7 +392,7 @@ khash_del(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
@@ -481,8 +404,6 @@ khash_del(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         ret = priv->atom_ok;
     }
 
-    unlock_hash(env, khash);
-
     return ret;
 }
 
@@ -492,7 +413,6 @@ khash_size(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
 {
     khash_priv* priv = enif_priv_data(env);
     khash_t* khash;
-    ERL_NIF_TERM ret;
 
     if(argc != 1) {
         return enif_make_badarg(env);
@@ -502,15 +422,11 @@ khash_size(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
         return enif_make_badarg(env);
     }
 
-    if(!lock_hash(env, khash)) {
+    if(!check_pid(env, khash)) {
         return enif_make_badarg(env);
     }
 
-    ret = enif_make_uint64(env, kl_hash_count(khash->h));
-
-    unlock_hash(env, khash);
-
-    return ret;
+    return enif_make_uint64(env, kl_hash_count(khash->h));
 }
 
 
@@ -535,7 +451,6 @@ load(ErlNifEnv* env, void** priv, ERL_NIF_TERM info)
 
     new_priv->atom_ok = make_atom(env, "ok");
     new_priv->atom_error = make_atom(env, "error");
-    new_priv->atom_shared = make_atom(env, "shared");
     new_priv->atom_value = make_atom(env, "value");
     new_priv->atom_not_found = make_atom(env, "not_found");
 

http://git-wip-us.apache.org/repos/asf/couchdb-khash/blob/4c046225/src/khash.erl
----------------------------------------------------------------------
diff --git a/src/khash.erl b/src/khash.erl
index d3542bf..5156d39 100644
--- a/src/khash.erl
+++ b/src/khash.erl
@@ -27,7 +27,7 @@
 
 -type kv() :: {any(), any()}.
 -type hash() :: term().
--type option() :: [shared].
+-type option() :: [].
 
 
 -spec new() -> {ok, hash()}.


Mime
View raw message