List:Commits« Previous MessageNext Message »
From:Magnus Blåudd Date:November 5 2011 10:01am
Subject:bzr push into mysql-5.5-cluster branch (magnus.blaudd:3625 to 3626)
View as plain text  
 3626 Magnus Blåudd	2011-11-05
      ndbcluster
       - move the logic for "have_lock" out of 'ndbcluster_get_share'

    modified:
      sql/ha_ndbcluster.cc
 3625 Magnus Blåudd	2011-11-03
      ndb schema dist
       - remove unused "sz" variable only used for DBUG_ASSERT

    modified:
      sql/ha_ndbcluster_binlog.cc
=== modified file 'sql/ha_ndbcluster.cc'
--- a/sql/ha_ndbcluster.cc	2011-11-02 09:28:48 +0000
+++ b/sql/ha_ndbcluster.cc	2011-11-05 09:10:46 +0000
@@ -13713,32 +13713,17 @@ NDB_SHARE *ndbcluster_get_share(NDB_SHAR
 }
 
 
-/*
-  Get a share object for key
-
-  Returns share for key, and increases the refcount on the share.
-
-  create_if_not_exists == TRUE:
-    creates share if it does not alreade exist
-    returns 0 only due to out of memory, and then sets my_error
-
-  create_if_not_exists == FALSE:
-    returns 0 if share does not exist
-
-  have_lock == TRUE, pthread_mutex_lock(&ndbcluster_mutex) already taken
-*/
-
+static inline
 NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
-                                bool create_if_not_exists,
-                                bool have_lock)
+                                bool create_if_not_exists)
 {
   NDB_SHARE *share;
   uint length= (uint) strlen(key);
   DBUG_ENTER("ndbcluster_get_share");
   DBUG_PRINT("enter", ("key: '%s'", key));
 
-  if (!have_lock)
-    pthread_mutex_lock(&ndbcluster_mutex);
+  safe_mutex_assert_owner(&ndbcluster_mutex);
+
   if (!(share= (NDB_SHARE*) my_hash_search(&ndbcluster_open_tables,
                                            (const uchar*) key,
                                            length)))
@@ -13746,8 +13731,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
     if (!create_if_not_exists)
     {
       DBUG_PRINT("error", ("get_share: %s does not exist", key));
-      if (!have_lock)
-        pthread_mutex_unlock(&ndbcluster_mutex);
       DBUG_RETURN(0);
     }
     if ((share= (NDB_SHARE*) my_malloc(sizeof(*share),
@@ -13769,8 +13752,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
         free_root(&share->mem_root, MYF(0));
         my_free((uchar*) share, 0);
         *root_ptr= old_root;
-        if (!have_lock)
-          pthread_mutex_unlock(&ndbcluster_mutex);
         DBUG_RETURN(0);
       }
       thr_lock_init(&share->lock);
@@ -13786,8 +13767,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
         DBUG_PRINT("error", ("get_share: %s could not init share", key));
         ndbcluster_real_free_share(&share);
         *root_ptr= old_root;
-        if (!have_lock)
-          pthread_mutex_unlock(&ndbcluster_mutex);
         DBUG_RETURN(0);
       }
       *root_ptr= old_root;
@@ -13795,8 +13774,6 @@ NDB_SHARE *ndbcluster_get_share(const ch
     else
     {
       DBUG_PRINT("error", ("get_share: failed to alloc share"));
-      if (!have_lock)
-        pthread_mutex_unlock(&ndbcluster_mutex);
       my_error(ER_OUTOFMEMORY, MYF(0), static_cast<int>(sizeof(*share)));
       DBUG_RETURN(0);
     }
@@ -13807,8 +13784,36 @@ NDB_SHARE *ndbcluster_get_share(const ch
 
   dbug_print_open_tables();
   dbug_print_share("ndbcluster_get_share:", share);
+  DBUG_RETURN(share);
+}
+
+
+/**
+  Get NDB_SHARE for key
+
+  Returns share for key, and increases the refcount on the share.
+
+  @param create_if_not_exists, creates share if it does not already exist
+  @param have_lock, ndbcluster_mutex already locked
+*/
+
+NDB_SHARE *ndbcluster_get_share(const char *key, TABLE *table,
+                                bool create_if_not_exists,
+                                bool have_lock)
+{
+  NDB_SHARE *share;
+  DBUG_ENTER("ndbcluster_get_share");
+  DBUG_PRINT("enter", ("key: '%s', create_if_not_exists: %d, have_lock: %d",
+                       key, create_if_not_exists, have_lock));
+
+  if (!have_lock)
+    pthread_mutex_lock(&ndbcluster_mutex);
+
+  share= ndbcluster_get_share(key, table, create_if_not_exists);
+
   if (!have_lock)
     pthread_mutex_unlock(&ndbcluster_mutex);
+
   DBUG_RETURN(share);
 }
 

No bundle (reason: useless for push emails).
Thread
bzr push into mysql-5.5-cluster branch (magnus.blaudd:3625 to 3626) Magnus Blåudd7 Nov