Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

crypto: use the libuv rwlock API

  • Loading branch information...
commit 2c6c38e758e11df6f1a15a7fea804d97bd0d0012 1 parent c9a9af0
Ben Noordhuis authored November 14, 2011

Showing 1 changed file with 18 additions and 38 deletions. Show diff stats Hide diff stats

  1. 56  src/node_crypto.cc
56  src/node_crypto.cc
@@ -83,67 +83,47 @@ static Persistent<String> ext_key_usage_symbol;
83 83
 
84 84
 static Persistent<FunctionTemplate> secure_context_constructor;
85 85
 
86  
-#ifdef _WIN32
87  
-
88  
-static HANDLE* locks;
89  
-
90  
-
91  
-static void crypto_lock_init(void) {
92  
-  int i, n;
93  
-
94  
-  n = CRYPTO_num_locks();
95  
-  locks = new HANDLE[n];
96  
-
97  
-  for (i = 0; i < n; i++)
98  
-    if (!(locks[i] = CreateMutex(NULL, FALSE, NULL)))
99  
-      abort();
100  
-}
101  
-
102  
-
103  
-static void crypto_lock_cb(int mode, int n, const char* file, int line) {
104  
-  if (mode & CRYPTO_LOCK)
105  
-    WaitForSingleObject(locks[n], INFINITE);
106  
-  else
107  
-    ReleaseMutex(locks[n]);
108  
-}
109  
-
110  
-
111 86
 static unsigned long crypto_id_cb(void) {
  87
+#ifdef _WIN32
112 88
   return (unsigned long) GetCurrentThreadId();
113  
-}
114  
-
115 89
 #else /* !_WIN32 */
  90
+  return (unsigned long) pthread_self();
  91
+#endif /* !_WIN32 */
  92
+}
116 93
 
117  
-static pthread_rwlock_t* locks;
  94
+static uv_rwlock_t* locks;
118 95
 
119 96
 
120 97
 static void crypto_lock_init(void) {
121 98
   int i, n;
122 99
 
123 100
   n = CRYPTO_num_locks();
124  
-  locks = new pthread_rwlock_t[n];
  101
+  locks = new uv_rwlock_t[n];
125 102
 
126 103
   for (i = 0; i < n; i++)
127  
-    if (pthread_rwlock_init(locks + i, NULL))
  104
+    if (uv_rwlock_init(locks + i))
128 105
       abort();
129 106
 }
130 107
 
131 108
 
132 109
 static void crypto_lock_cb(int mode, int n, const char* file, int line) {
  110
+  assert((mode & CRYPTO_LOCK) || (mode & CRYPTO_UNLOCK));
  111
+  assert((mode & CRYPTO_READ) || (mode & CRYPTO_WRITE));
  112
+
133 113
   if (mode & CRYPTO_LOCK) {
134  
-    if (mode & CRYPTO_READ) pthread_rwlock_rdlock(locks + n);
135  
-    if (mode & CRYPTO_WRITE) pthread_rwlock_wrlock(locks + n);
  114
+    if (mode & CRYPTO_READ)
  115
+      uv_rwlock_rdlock(locks + n);
  116
+    else
  117
+      uv_rwlock_wrlock(locks + n);
136 118
   } else {
137  
-    pthread_rwlock_unlock(locks + n);
  119
+    if (mode & CRYPTO_READ)
  120
+      uv_rwlock_rdunlock(locks + n);
  121
+    else
  122
+      uv_rwlock_wrunlock(locks + n);
138 123
   }
139 124
 }
140 125
 
141 126
 
142  
-static unsigned long crypto_id_cb(void) {
143  
-  return (unsigned long) pthread_self();
144  
-}
145  
-
146  
-#endif /* !_WIN32 */
147 127
 
148 128
 
149 129
 void SecureContext::Initialize(Handle<Object> target) {

0 notes on commit 2c6c38e

Please sign in to comment.
Something went wrong with that request. Please try again.