summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <tomas@poseidon.ndb.mysql.com>2004-10-25 15:21:49 +0000
committerunknown <tomas@poseidon.ndb.mysql.com>2004-10-25 15:21:49 +0000
commit7e39126de87538ab4d819f4a40b1f85eee4b73de (patch)
treecabb4bd8ca00a2a7a429a4d2e6547c9f8b11c09b
parent760f69c1cbc9eb24da3f0015294c3c46f4af46cd (diff)
downloadmariadb-git-7e39126de87538ab4d819f4a40b1f85eee4b73de.tar.gz
removed usage of NDB_MUTEX_INITIALIZER
-rw-r--r--ndb/include/portlib/NdbMutex.h2
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.cpp20
-rw-r--r--ndb/src/mgmsrv/MgmtSrvr.hpp1
-rw-r--r--ndb/src/ndbapi/Ndb.cpp7
-rw-r--r--ndb/src/ndbapi/NdbEventOperationImpl.cpp23
-rw-r--r--ndb/src/ndbapi/Ndbinit.cpp15
-rw-r--r--ndb/src/ndbapi/ndb_cluster_connection.cpp31
7 files changed, 50 insertions, 49 deletions
diff --git a/ndb/include/portlib/NdbMutex.h b/ndb/include/portlib/NdbMutex.h
index 28adaacb8c4..b0b985ecef5 100644
--- a/ndb/include/portlib/NdbMutex.h
+++ b/ndb/include/portlib/NdbMutex.h
@@ -31,13 +31,11 @@ extern "C" {
#if defined NDB_OSE || defined NDB_SOFTOSE
#include <ose.h>
typedef SEMAPHORE NdbMutex;
-#define NDB_MUTEX_INITIALIZER { 1, 0, 0 }
#elif defined NDB_WIN32
typedef CRITICAL_SECTION NdbMutex;
#else
#include <pthread.h>
typedef pthread_mutex_t NdbMutex;
-#define NDB_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#endif
/**
diff --git a/ndb/src/mgmsrv/MgmtSrvr.cpp b/ndb/src/mgmsrv/MgmtSrvr.cpp
index 83f349bd435..c93ca168f26 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.cpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.cpp
@@ -534,6 +534,12 @@ MgmtSrvr::MgmtSrvr(NodeId nodeId,
m_statisticsListner.m_logLevel = se.m_logLevel;
}
+ if ((m_node_id_mutex = NdbMutex_Create()) == 0)
+ {
+ ndbout << "mutex creation failed line = " << __LINE__ << endl;
+ exit(-1);
+ }
+
DBUG_VOID_RETURN;
}
@@ -627,7 +633,9 @@ MgmtSrvr::~MgmtSrvr()
stopEventLog();
- NdbCondition_Destroy(theMgmtWaitForResponseCondPtr); NdbMutex_Destroy(m_configMutex);
+ NdbMutex_Destroy(m_node_id_mutex);
+ NdbCondition_Destroy(theMgmtWaitForResponseCondPtr);
+ NdbMutex_Destroy(m_configMutex);
if(m_newConfig != NULL)
free(m_newConfig);
@@ -2084,12 +2092,6 @@ MgmtSrvr::getNodeType(NodeId nodeId) const
return nodeTypes[nodeId];
}
-#ifdef NDB_WIN32
-static NdbMutex & f_node_id_mutex = * NdbMutex_Create();
-#else
-static NdbMutex f_node_id_mutex = NDB_MUTEX_INITIALIZER;
-#endif
-
bool
MgmtSrvr::alloc_node_id(NodeId * nodeId,
enum ndb_mgm_node_type type,
@@ -2108,7 +2110,7 @@ MgmtSrvr::alloc_node_id(NodeId * nodeId,
}
DBUG_RETURN(true);
}
- Guard g(&f_node_id_mutex);
+ Guard g(m_node_id_mutex);
int no_mgm= 0;
NodeBitmask connected_nodes(m_reserved_nodes);
for(Uint32 i = 0; i < MAX_NODES; i++)
@@ -2525,7 +2527,7 @@ MgmtSrvr::Allocated_resources::Allocated_resources(MgmtSrvr &m)
MgmtSrvr::Allocated_resources::~Allocated_resources()
{
- Guard g(&f_node_id_mutex);
+ Guard g(m_mgmsrv.m_node_id_mutex);
if (!m_reserved_nodes.isclear()) {
// node has been reserved, force update signal to ndb nodes
global_flag_send_heartbeat_now= 1;
diff --git a/ndb/src/mgmsrv/MgmtSrvr.hpp b/ndb/src/mgmsrv/MgmtSrvr.hpp
index c6157db489a..87da145ec51 100644
--- a/ndb/src/mgmsrv/MgmtSrvr.hpp
+++ b/ndb/src/mgmsrv/MgmtSrvr.hpp
@@ -101,6 +101,7 @@ public:
MgmtSrvr &m_mgmsrv;
NodeBitmask m_reserved_nodes;
};
+ NdbMutex *m_node_id_mutex;
/**
* Start/initate the event log.
diff --git a/ndb/src/ndbapi/Ndb.cpp b/ndb/src/ndbapi/Ndb.cpp
index be0445bceb3..d7b8a695fe2 100644
--- a/ndb/src/ndbapi/Ndb.cpp
+++ b/ndb/src/ndbapi/Ndb.cpp
@@ -1365,7 +1365,8 @@ Ndb::pollEvents(int aMillisecondNumber)
#ifdef VM_TRACE
#include <NdbMutex.h>
-static NdbMutex print_state_mutex = NDB_MUTEX_INITIALIZER;
+extern NdbMutex *ndb_print_state_mutex;
+
static bool
checkdups(NdbConnection** list, unsigned no)
{
@@ -1383,7 +1384,7 @@ Ndb::printState(const char* fmt, ...)
va_start(ap, fmt);
vsprintf(buf, fmt, ap);
va_end(ap);
- NdbMutex_Lock(&print_state_mutex);
+ NdbMutex_Lock(ndb_print_state_mutex);
bool dups = false;
ndbout << buf << " ndb=" << hex << this << dec;
#ifndef NDB_WIN32
@@ -1421,7 +1422,7 @@ Ndb::printState(const char* fmt, ...)
}
for (unsigned i = 0; i < theNoOfCompletedTransactions; i++)
theCompletedTransactionsArray[i]->printState();
- NdbMutex_Unlock(&print_state_mutex);
+ NdbMutex_Unlock(ndb_print_state_mutex);
}
#endif
diff --git a/ndb/src/ndbapi/NdbEventOperationImpl.cpp b/ndb/src/ndbapi/NdbEventOperationImpl.cpp
index f5e683b1c29..b3fac64d1c4 100644
--- a/ndb/src/ndbapi/NdbEventOperationImpl.cpp
+++ b/ndb/src/ndbapi/NdbEventOperationImpl.cpp
@@ -573,12 +573,8 @@ int NdbEventOperationImpl::wait(void *p, int aMillisecondNumber)
*
*/
+extern NdbMutex * ndb_global_event_buffer_mutex;
static NdbGlobalEventBuffer *ndbGlobalEventBuffer=NULL;
-#ifdef NDB_WIN32
-static NdbMutex & ndbGlobalEventBufferMutex = * NdbMutex_Create();
-#else
-static NdbMutex ndbGlobalEventBufferMutex = NDB_MUTEX_INITIALIZER;
-#endif
/*
* Class NdbGlobalEventBufferHandle
@@ -607,18 +603,18 @@ NdbGlobalEventBufferHandle::NdbGlobalEventBufferHandle
exit(-1);
}
- NdbMutex_Lock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Lock(ndb_global_event_buffer_mutex);
if (ndbGlobalEventBuffer == NULL) {
if (ndbGlobalEventBuffer == NULL) {
ndbGlobalEventBuffer = new NdbGlobalEventBuffer();
if (!ndbGlobalEventBuffer) {
- NdbMutex_Unlock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Unlock(ndb_global_event_buffer_mutex);
ndbout_c("NdbGlobalEventBufferHandle:: failed to allocate ndbGlobalEventBuffer");
exit(-1);
}
}
}
- NdbMutex_Unlock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Unlock(ndb_global_event_buffer_mutex);
GUARD(real_init(this,MAX_NUMBER_ACTIVE_EVENTS));
}
@@ -631,12 +627,12 @@ NdbGlobalEventBufferHandle::~NdbGlobalEventBufferHandle()
ndbGlobalEventBuffer->real_remove(this);
ndbGlobalEventBuffer->unlock();
- NdbMutex_Lock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Lock(ndb_global_event_buffer_mutex);
if (ndbGlobalEventBuffer->m_handlers.size() == 0) {
delete ndbGlobalEventBuffer;
ndbGlobalEventBuffer = NULL;
}
- NdbMutex_Unlock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Unlock(ndb_global_event_buffer_mutex);
}
void
@@ -770,13 +766,13 @@ void
NdbGlobalEventBuffer::lock()
{
if (!m_group_lock_flag)
- NdbMutex_Lock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Lock(ndb_global_event_buffer_mutex);
}
void
NdbGlobalEventBuffer::unlock()
{
if (!m_group_lock_flag)
- NdbMutex_Unlock(&ndbGlobalEventBufferMutex);
+ NdbMutex_Unlock(ndb_global_event_buffer_mutex);
}
void
NdbGlobalEventBuffer::add_drop_lock()
@@ -1232,7 +1228,8 @@ NdbGlobalEventBuffer::real_wait(NdbGlobalEventBufferHandle *h,
n += hasData(h->m_bufferIds[i]);
if (n) return n;
- int r = NdbCondition_WaitTimeout(h->p_cond, &ndbGlobalEventBufferMutex, aMillisecondNumber);
+ int r = NdbCondition_WaitTimeout(h->p_cond, ndb_global_event_buffer_mutex,
+ aMillisecondNumber);
if (r > 0)
return -1;
diff --git a/ndb/src/ndbapi/Ndbinit.cpp b/ndb/src/ndbapi/Ndbinit.cpp
index b8927f2abba..698bbcde4c6 100644
--- a/ndb/src/ndbapi/Ndbinit.cpp
+++ b/ndb/src/ndbapi/Ndbinit.cpp
@@ -42,11 +42,6 @@ void NdbGlobalEventBuffer_drop(NdbGlobalEventBufferHandle *);
static char *ndbConnectString = 0;
static int theNoOfNdbObjects = 0;
static Ndb_cluster_connection *global_ndb_cluster_connection= 0;
-#if defined NDB_WIN32 || defined SCO
-static NdbMutex & createNdbMutex = * NdbMutex_Create();
-#else
-static NdbMutex createNdbMutex = NDB_MUTEX_INITIALIZER;
-#endif
/***************************************************************************
@@ -58,7 +53,6 @@ Remark: Connect to the database.
Ndb::Ndb( const char* aDataBase , const char* aSchema) {
DBUG_ENTER("Ndb::Ndb()");
DBUG_PRINT("enter",("(old)Ndb::Ndb this=0x%x", this));
- NdbMutex_Lock(&createNdbMutex);
if (theNoOfNdbObjects < 0)
abort(); // old and new Ndb constructor used mixed
theNoOfNdbObjects++;
@@ -66,7 +60,6 @@ Ndb::Ndb( const char* aDataBase , const char* aSchema) {
global_ndb_cluster_connection= new Ndb_cluster_connection(ndbConnectString);
global_ndb_cluster_connection->connect();
}
- NdbMutex_Unlock(&createNdbMutex);
setup(global_ndb_cluster_connection, aDataBase, aSchema);
DBUG_VOID_RETURN;
}
@@ -171,8 +164,6 @@ void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection,
prefixEnd = prefixName + (len < (int) sizeof(prefixName) ? len :
sizeof(prefixName) - 1);
- NdbMutex_Lock(&createNdbMutex);
-
theWaiter.m_mutex = TransporterFacade::instance()->theMutexPtr;
// Signal that the constructor has finished OK
@@ -191,8 +182,6 @@ void Ndb::setup(Ndb_cluster_connection *ndb_cluster_connection,
theGlobalEventBufferHandle = h;
}
- NdbMutex_Unlock(&createNdbMutex);
-
theDictionary = new NdbDictionaryImpl(*this);
if (theDictionary == NULL) {
ndbout_c("Ndb cailed to allocate dictionary");
@@ -232,8 +221,6 @@ Ndb::~Ndb()
TransporterFacade::instance()->close(theNdbBlockNumber, theFirstTransId);
}
- NdbMutex_Lock(&createNdbMutex);
-
if (global_ndb_cluster_connection != 0) {
theNoOfNdbObjects--;
if(theNoOfNdbObjects == 0){
@@ -242,8 +229,6 @@ Ndb::~Ndb()
}
}//if
- NdbMutex_Unlock(&createNdbMutex);
-
// if (theSchemaConToNdbList != NULL)
// closeSchemaTransaction(theSchemaConToNdbList);
while ( theConIdleList != NULL )
diff --git a/ndb/src/ndbapi/ndb_cluster_connection.cpp b/ndb/src/ndbapi/ndb_cluster_connection.cpp
index 358dfa74785..4c42fe1aeef 100644
--- a/ndb/src/ndbapi/ndb_cluster_connection.cpp
+++ b/ndb/src/ndbapi/ndb_cluster_connection.cpp
@@ -29,6 +29,12 @@
static int g_run_connect_thread= 0;
+#include <NdbMutex.h>
+NdbMutex *ndb_global_event_buffer_mutex= NULL;
+#ifdef VM_TRACE
+NdbMutex *ndb_print_state_mutex= NULL;
+#endif
+
Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
{
DBUG_ENTER("Ndb_cluster_connection");
@@ -42,6 +48,17 @@ Ndb_cluster_connection::Ndb_cluster_connection(const char *connect_string)
m_local_config= 0;
m_connect_thread= 0;
m_connect_callback= 0;
+
+ if (ndb_global_event_buffer_mutex == NULL)
+ {
+ ndb_global_event_buffer_mutex= NdbMutex_Create();
+ }
+#ifdef VM_TRACE
+ if (ndb_print_state_mutex == NULL)
+ {
+ ndb_print_state_mutex= NdbMutex_Create();
+ }
+#endif
DBUG_VOID_RETURN;
}
@@ -85,11 +102,10 @@ int Ndb_cluster_connection::start_connect_thread(int (*connect_callback)(void))
if ((r = connect(1)) == 1)
{
DBUG_PRINT("info",("starting thread"));
- m_connect_thread= NdbThread_Create(run_ndb_cluster_connection_connect_thread,
- (void**)this,
- 32768,
- "ndb_cluster_connection",
- NDB_THREAD_PRIO_LOW);
+ m_connect_thread=
+ NdbThread_Create(run_ndb_cluster_connection_connect_thread,
+ (void**)this, 32768, "ndb_cluster_connection",
+ NDB_THREAD_PRIO_LOW);
}
else if (r < 0)
{
@@ -112,13 +128,14 @@ int Ndb_cluster_connection::connect(int reconnect)
if (m_local_config == 0) {
m_local_config= new LocalConfig();
if (!m_local_config->init(m_connect_string,0)) {
- ndbout << "Configuration error: Unable to retrieve local config" << endl;
+ ndbout_c("Configuration error: Unable to retrieve local config");
m_local_config->printError();
m_local_config->printUsage();
DBUG_RETURN(-1);
}
}
- m_config_retriever= new ConfigRetriever(*m_local_config, NDB_VERSION, NODE_TYPE_API);
+ m_config_retriever=
+ new ConfigRetriever(*m_local_config, NDB_VERSION, NODE_TYPE_API);
}
else
if (reconnect == 0)