diff --git a/src/libbitcoind.cc b/src/libbitcoind.cc index da64bef6..ae21910c 100644 --- a/src/libbitcoind.cc +++ b/src/libbitcoind.cc @@ -90,7 +90,6 @@ init(Handle); * Private Global Variables * Used only by bitcoindjs functions. */ -static uv_mutex_t txmon_mutex; static std::vector txmon_messages; static uv_async_t txmon_async; static Eternal txmon_callback; @@ -235,29 +234,31 @@ txmon(uv_async_t *handle) { Isolate* isolate = Isolate::GetCurrent(); HandleScope scope(isolate); - uv_mutex_lock(&txmon_mutex); + { - Local results = Array::New(isolate); - int arrayIndex = 0; + LOCK(cs_main); + + Local results = Array::New(isolate); + int arrayIndex = 0; + + BOOST_FOREACH(const std::string& message, txmon_messages) { + results->Set(arrayIndex, NanNew(message)); + arrayIndex++; + } + + const unsigned argc = 1; + Local argv[argc] = { + Local::New(isolate, results) + }; + + Local cb = txmon_callback.Get(isolate); + + cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); + + txmon_messages.clear(); - BOOST_FOREACH(const std::string& message, txmon_messages) { - results->Set(arrayIndex, NanNew(message)); - arrayIndex++; } - const unsigned argc = 1; - Local argv[argc] = { - Local::New(isolate, results) - }; - - Local cb = txmon_callback.Get(isolate); - - cb->Call(isolate->GetCurrentContext()->Global(), argc, argv); - - txmon_messages.clear(); - - uv_mutex_unlock(&txmon_mutex); - } static bool @@ -316,10 +317,11 @@ process_messages(CNode* pfrom) { string txHash = tx.GetHash().GetHex(); - uv_mutex_lock(&txmon_mutex); - txmon_messages.push_back(txHash); - uv_mutex_unlock(&txmon_mutex); - uv_async_send(&txmon_async); + { + LOCK(cs_main); + txmon_messages.push_back(txHash); + uv_async_send(&txmon_async); + } }