Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: replace rwlocks with simple mutexes #2723

Merged
merged 1 commit into from
Sep 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct ClearErrorOnReturn {
~ClearErrorOnReturn() { ERR_clear_error(); }
};

static uv_rwlock_t* locks;
static uv_mutex_t* locks;

const char* const root_certs[] = {
#include "node_root_certs.h" // NOLINT(build/include_order)
Expand Down Expand Up @@ -178,29 +178,22 @@ static void crypto_lock_init(void) {
int i, n;

n = CRYPTO_num_locks();
locks = new uv_rwlock_t[n];
locks = new uv_mutex_t[n];

for (i = 0; i < n; i++)
if (uv_rwlock_init(locks + i))
if (uv_mutex_init(locks + i))
abort();
}


static void crypto_lock_cb(int mode, int n, const char* file, int line) {
CHECK((mode & CRYPTO_LOCK) || (mode & CRYPTO_UNLOCK));
CHECK((mode & CRYPTO_READ) || (mode & CRYPTO_WRITE));
CHECK(!(mode & CRYPTO_LOCK) ^ !(mode & CRYPTO_UNLOCK));
CHECK(!(mode & CRYPTO_READ) ^ !(mode & CRYPTO_WRITE));

if (mode & CRYPTO_LOCK) {
if (mode & CRYPTO_READ)
uv_rwlock_rdlock(locks + n);
else
uv_rwlock_wrlock(locks + n);
} else {
if (mode & CRYPTO_READ)
uv_rwlock_rdunlock(locks + n);
else
uv_rwlock_wrunlock(locks + n);
}
if (mode & CRYPTO_LOCK)
uv_mutex_lock(locks + n);
else
uv_mutex_unlock(locks + n);
}


Expand Down