hadoop-zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maha...@apache.org
Subject svn commit: r750718 - in /hadoop/zookeeper/trunk: CHANGES.txt src/c/src/zk_hashtable.c src/c/src/zk_hashtable.h
Date Fri, 06 Mar 2009 00:44:48 GMT
Author: mahadev
Date: Fri Mar  6 00:44:48 2009
New Revision: 750718

URL: http://svn.apache.org/viewvc?rev=750718&view=rev
Log:
ZOOKEEPER-318. remove locking in zk_hashtable.c or add locking in collect_keys() (chris darroch
via mahadev)

Modified:
    hadoop/zookeeper/trunk/CHANGES.txt
    hadoop/zookeeper/trunk/src/c/src/zk_hashtable.c
    hadoop/zookeeper/trunk/src/c/src/zk_hashtable.h

Modified: hadoop/zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/CHANGES.txt?rev=750718&r1=750717&r2=750718&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/CHANGES.txt (original)
+++ hadoop/zookeeper/trunk/CHANGES.txt Fri Mar  6 00:44:48 2009
@@ -22,6 +22,9 @@
   (flavio and mahadev) 
 
   ZOOKEEPER-281. autoreconf fails for /zookeeper-3.0.1/src/c/ (phunt)
+
+  ZOOKEEPER-318. remove locking in zk_hashtable.c or add locking in
+collect_keys() (chris darroch via mahadev)
  
 IMPROVEMENTS:
   ZOOKEEPER-308. improve the atomic broadcast performance 3x.

Modified: hadoop/zookeeper/trunk/src/c/src/zk_hashtable.c
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/zk_hashtable.c?rev=750718&r1=750717&r2=750718&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/zk_hashtable.c (original)
+++ hadoop/zookeeper/trunk/src/c/src/zk_hashtable.c Fri Mar  6 00:44:48 2009
@@ -24,25 +24,28 @@
 #include <stdlib.h>
 #include <assert.h>
 
-#ifdef THREADED
-#include <pthread.h>
-#endif
+typedef struct _watcher_object {
+    watcher_fn watcher;
+    void* context;
+    struct _watcher_object* next;
+} watcher_object_t;
+
 
 struct _zk_hashtable {
     struct hashtable* ht;
-#ifdef THREADED
-    pthread_mutex_t lock;
-#endif
 };
 
-hashtable_impl* getImpl(zk_hashtable* ht){
-    return ht->ht;
-}
-
 struct watcher_object_list {
     watcher_object_t* head;
 };
 
+/* the following functions are for testing only */
+typedef struct hashtable hashtable_impl;
+
+hashtable_impl* getImpl(zk_hashtable* ht){
+    return ht->ht;
+}
+
 watcher_object_t* getFirstWatcher(zk_hashtable* ht,const char* path)
 {
     watcher_object_list_t* wl=hashtable_search(ht->ht,(void*)path);
@@ -50,6 +53,7 @@
         return wl->head;
     return 0;
 }
+/* end of testing functions */
 
 watcher_object_t* clone_watcher_object(watcher_object_t* wo)
 {
@@ -76,7 +80,7 @@
     return strcmp((const char*)key1,(const char*)key2)==0;
 }
 
-watcher_object_t* create_watcher_object(watcher_fn watcher,void* ctx)
+static watcher_object_t* create_watcher_object(watcher_fn watcher,void* ctx)
 {
     watcher_object_t* wo=calloc(1,sizeof(watcher_object_t));
     assert(wo);
@@ -110,9 +114,6 @@
 {
     struct _zk_hashtable *ht=calloc(1,sizeof(struct _zk_hashtable));
     assert(ht);
-#ifdef THREADED
-    pthread_mutex_init(&ht->lock, 0);
-#endif
     ht->ht=create_hashtable(32,string_hash_djb2,string_equal);
     return ht;
 }
@@ -132,25 +133,11 @@
     free(it);
 }
 
-void clean_zk_hashtable(zk_hashtable* ht)
-{
-#ifdef THREADED
-    pthread_mutex_lock(&ht->lock);
-#endif
-    do_clean_hashtable(ht);    
-#ifdef THREADED
-    pthread_mutex_unlock(&ht->lock);
-#endif    
-}
-
 void destroy_zk_hashtable(zk_hashtable* ht)
 {
     if(ht!=0){
         do_clean_hashtable(ht);
         hashtable_destroy(ht->ht,0);
-#ifdef THREADED
-        pthread_mutex_destroy(&ht->lock);
-#endif
         free(ht);
     }
 }
@@ -169,7 +156,8 @@
     return 0;
 }
 
-int add_to_list(watcher_object_list_t **wl, watcher_object_t *wo, int clone)
+static int add_to_list(watcher_object_list_t **wl, watcher_object_t *wo,
+                       int clone)
 {
     if (search_watcher(wl, wo)==0) {
         watcher_object_t* cloned=wo;
@@ -223,16 +211,11 @@
     return list;
 }
 
-int insert_watcher_object(zk_hashtable *ht, const char *path, watcher_object_t* wo)
+static int insert_watcher_object(zk_hashtable *ht, const char *path,
+                                 watcher_object_t* wo)
 {
     int res;
-#ifdef THREADED
-    pthread_mutex_lock(&ht->lock);
-#endif
     res=do_insert_watcher_object(ht,path,wo);
-#ifdef THREADED
-    pthread_mutex_unlock(&ht->lock);
-#endif
     return res;
 }
 
@@ -260,29 +243,17 @@
     free(it);
 }
 
-void collect_session_watchers(zhandle_t *zh, watcher_object_list_t **list)
+static void collect_session_watchers(zhandle_t *zh,
+                                     watcher_object_list_t **list)
 {
-#ifdef THREADED
-    pthread_mutex_lock(&zh->active_node_watchers->lock);
-    pthread_mutex_lock(&zh->active_exist_watchers->lock);
-    pthread_mutex_lock(&zh->active_child_watchers->lock);
-#endif
     copy_table(zh->active_node_watchers, *list);
     copy_table(zh->active_exist_watchers, *list);
     copy_table(zh->active_child_watchers, *list);
-#ifdef THREADED
-    pthread_mutex_unlock(&zh->active_node_watchers->lock);
-    pthread_mutex_unlock(&zh->active_exist_watchers->lock);
-    pthread_mutex_unlock(&zh->active_child_watchers->lock);
-#endif    
 }
 
 static void add_for_event(zk_hashtable *ht, char *path, watcher_object_list_t **list)
 {
     watcher_object_list_t* wl;
-#ifdef THREADED
-    pthread_mutex_lock(&ht->lock);
-#endif
     wl = (watcher_object_list_t*)hashtable_remove(ht->ht, path);
     if (wl) {
         copy_watchers(wl, *list, 0);
@@ -290,9 +261,6 @@
         // head pointer
         free(wl);
     }
-#ifdef THREADED
-    pthread_mutex_unlock(&ht->lock);
-#endif    
 }
 
 static void do_foreach_watcher(watcher_object_t* wo,zhandle_t* zh,
@@ -304,18 +272,9 @@
     }    
 }
 
-int countList(watcher_object_t *wo) {
-    int count = 0;
-    while(wo) {
-        count++;
-        wo = wo->next;
-    }
-    return count;
-}
 watcher_object_list_t *collectWatchers(zhandle_t *zh,int type, char *path)
 {
     struct watcher_object_list *list = create_watcher_object_list(0); 
-    int count = 0;
 
     if(type==ZOO_SESSION_EVENT){
         watcher_object_t defWatcher;
@@ -323,7 +282,6 @@
         defWatcher.context=zh->context;
         add_to_list(&list, &defWatcher, 1);
         collect_session_watchers(zh, &list);
-        count = countList(list->head);
         return list;
     }
     switch(type){
@@ -344,7 +302,6 @@
         add_for_event(zh->active_child_watchers,path,&list);
         break;
     }
-    count = countList(list->head);
     return list;
 }
 
@@ -360,7 +317,7 @@
 {
     if(reg){
         /* in multithreaded lib, this code is executed 
-         * by the completion thread */
+         * by the IO thread */
         zk_hashtable *ht = reg->checker(zh, rc);
         if(ht){
             insert_watcher_object(ht,reg->path,

Modified: hadoop/zookeeper/trunk/src/c/src/zk_hashtable.h
URL: http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/zk_hashtable.h?rev=750718&r1=750717&r2=750718&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/zk_hashtable.h (original)
+++ hadoop/zookeeper/trunk/src/c/src/zk_hashtable.h Fri Mar  6 00:44:48 2009
@@ -48,32 +48,10 @@
     const char* path;
 } watcher_registration_t;
 
-
-typedef struct _watcher_object {
-    watcher_fn watcher;
-    void* context;
-    struct _watcher_object* next;
-} watcher_object_t;
-
-watcher_object_t* create_watcher_object(watcher_fn watcher,void* ctx);
-watcher_object_t* clone_watcher_object(watcher_object_t* wo);
-
-    int add_to_list(watcher_object_list_t **list, watcher_object_t *obj, int clone);
-void free_list(watcher_object_t **list);
-
 zk_hashtable* create_zk_hashtable();
-void clean_zk_hashtable(zk_hashtable* ht);
 void destroy_zk_hashtable(zk_hashtable* ht);
 
-/**
- * The hashtable takes ownership of the watcher object instance.
- * 
- * \return 1 if the watcher object was succesfully inserted, 0 otherwise
- */
-int insert_watcher_object(zk_hashtable* ht, const char* path, watcher_object_t* wo);
-
-    void collect_session_watchers(zhandle_t *zh, struct watcher_object_list **list);
-    char **collect_keys(zk_hashtable *ht, int *count);
+char **collect_keys(zk_hashtable *ht, int *count);
 
 /**
  * check if the completion has a watcher object associated
@@ -84,11 +62,6 @@
     watcher_object_list_t *collectWatchers(zhandle_t *zh,int type, char *path);
     void deliverWatchers(zhandle_t *zh, int type, int state, char *path, struct watcher_object_list
**list);
 
-/* the following functions are for testing only */
-typedef struct hashtable hashtable_impl;
-hashtable_impl* getImpl(zk_hashtable* ht);
-watcher_object_t* getFirstWatcher(zk_hashtable* ht,const char* path);
-
 #ifdef __cplusplus
 }
 #endif



Mime
View raw message