Merge in check (i.e. we are going to put a lock in it to make sure any concurrent...
authorBrian Aker <brian@tangent.org>
Wed, 17 Aug 2011 19:35:11 +0000 (12:35 -0700)
committerBrian Aker <brian@tangent.org>
Wed, 17 Aug 2011 19:35:11 +0000 (12:35 -0700)
libmemcached/sasl.cc
libtest/unittest.cc

index f1de41eaec4fe30f86416da7714f625e169c0ba6..3aefb701f9bfd93cb0fa343f3cf7feeff5752f4c 100644 (file)
@@ -98,12 +98,15 @@ static memcached_return_t resolve_names(memcached_server_st& server, char *laddr
   return MEMCACHED_SUCCESS;
 }
 
+extern "C" {
+
 static void sasl_shutdown_function()
 {
   sasl_done();
 }
 
-static int sasl_startup_state= SASL_OK;
+static volatile int sasl_startup_state= SASL_OK;
+pthread_mutex_t sasl_startup_state_LOCK= PTHREAD_MUTEX_INITIALIZER;
 static pthread_once_t sasl_startup_once= PTHREAD_ONCE_INIT;
 static void sasl_startup_function(void)
 {
@@ -115,6 +118,8 @@ static void sasl_startup_function(void)
   }
 }
 
+} // extern "C"
+
 memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *server)
 {
   if (LIBMEMCACHED_WITH_SASL_SUPPORT == 0)
@@ -182,12 +187,14 @@ memcached_return_t memcached_sasl_authenticate_connection(memcached_server_st *s
     return memcached_set_errno(*server, pthread_error, MEMCACHED_AT);
   }
 
+  (void)pthread_mutex_lock(&sasl_startup_state_LOCK);
   if (sasl_startup_state != SASL_OK)
   {
     const char *sasl_error_msg= sasl_errstring(sasl_startup_state, NULL, NULL);
     return memcached_set_error(*server, MEMCACHED_AUTH_PROBLEM, MEMCACHED_AT, 
                                memcached_string_make_from_cstr(sasl_error_msg));
   }
+  (void)pthread_mutex_unlock(&sasl_startup_state_LOCK);
 
   sasl_conn_t *conn;
   int ret;
index 93192a255b17d7ba82dbd560458dc4d96f404436..cee9b52ec1f5e24ea20e54343a301fcb86c69d13 100644 (file)
@@ -64,7 +64,9 @@ static test_return_t GDB_COMMAND_test(void *)
 static test_return_t test_success_equals_one_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, true);
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
   test_zero(MEMCACHED_SUCCESS);
+#endif
   return TEST_SUCCESS;
 }
 
@@ -206,7 +208,9 @@ static test_return_t _compare_test_return_t_test(void *)
 static test_return_t _compare_memcached_return_t_test(void *)
 {
   test_skip(HAVE_LIBMEMCACHED, true);
+#if defined(HAVE_LIBMEMCACHED) && HAVE_LIBMEMCACHED 
   test_compare(MEMCACHED_SUCCESS, MEMCACHED_SUCCESS);
+#endif
 
   return TEST_SUCCESS;
 }
@@ -214,6 +218,9 @@ static test_return_t _compare_memcached_return_t_test(void *)
 static test_return_t _compare_gearman_return_t_test(void *)
 {
   test_skip(HAVE_LIBGEARMAN, true);
+#if defined(HAVE_LIBGEARMAN) && HAVE_LIBGEARMAN
+    test_compare(GEARMAN_SUCCESS, GEARMAN_SUCCESS);
+#endif
 
   return TEST_SUCCESS;
 }