Skip to content

Commit

Permalink
Switched to libuv mutexes
Browse files Browse the repository at this point in the history
refs #137 (comment)

- we don't actually need to depend on Boost for mutexes, even though it
  was gated behind `NODE_SQLITE3_BOOST_THREADING` anyway, which I can't
  find documented anywhere
- this simplifies the threading.h file and keeps the different systems
  more aligned in their dependency use
  • Loading branch information
daniellockyer committed Apr 30, 2022
1 parent f924bbb commit fcac520
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 48 deletions.
5 changes: 0 additions & 5 deletions src/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

#include "threading.h"

#if defined(NODE_SQLITE3_BOOST_THREADING)
#include <boost/thread/mutex.hpp>
#endif


// Generic uv_async handler.
template <class Item, class Parent> class Async {
typedef void (*Callback)(Parent* parent, Item* item);
Expand Down
48 changes: 5 additions & 43 deletions src/threading.h
Original file line number Diff line number Diff line change
@@ -1,48 +1,10 @@
#ifndef NODE_SQLITE3_SRC_THREADING_H
#define NODE_SQLITE3_SRC_THREADING_H


#ifdef _WIN32

#include <windows.h>

#define NODE_SQLITE3_MUTEX_t HANDLE mutex;

#define NODE_SQLITE3_MUTEX_INIT mutex = CreateMutex(NULL, FALSE, NULL);

#define NODE_SQLITE3_MUTEX_LOCK(m) WaitForSingleObject(*m, INFINITE);

#define NODE_SQLITE3_MUTEX_UNLOCK(m) ReleaseMutex(*m);

#define NODE_SQLITE3_MUTEX_DESTROY CloseHandle(mutex);

#elif defined(NODE_SQLITE3_BOOST_THREADING)

#include <boost/thread/mutex.hpp>

#define NODE_SQLITE3_MUTEX_t boost::mutex mutex;

#define NODE_SQLITE3_MUTEX_INIT

#define NODE_SQLITE3_MUTEX_LOCK(m) (*m).lock();

#define NODE_SQLITE3_MUTEX_UNLOCK(m) (*m).unlock();

#define NODE_SQLITE3_MUTEX_DESTROY mutex.unlock();

#else

#define NODE_SQLITE3_MUTEX_t pthread_mutex_t mutex;

#define NODE_SQLITE3_MUTEX_INIT pthread_mutex_init(&mutex,NULL);

#define NODE_SQLITE3_MUTEX_LOCK(m) pthread_mutex_lock(m);

#define NODE_SQLITE3_MUTEX_UNLOCK(m) pthread_mutex_unlock(m);

#define NODE_SQLITE3_MUTEX_DESTROY pthread_mutex_destroy(&mutex);

#endif

#define NODE_SQLITE3_MUTEX_t uv_mutex_t mutex;
#define NODE_SQLITE3_MUTEX_INIT uv_mutex_init(&mutex);
#define NODE_SQLITE3_MUTEX_LOCK(m) uv_mutex_lock(m);
#define NODE_SQLITE3_MUTEX_UNLOCK(m) uv_mutex_unlock(m);
#define NODE_SQLITE3_MUTEX_DESTROY uv_mutex_destroy(&mutex);

#endif // NODE_SQLITE3_SRC_THREADING_H

0 comments on commit fcac520

Please sign in to comment.