| 142 | |
| 143 | #if defined(UV_VERSION_MAJOR) && UV_VERSION_MAJOR > 0 |
| 144 | static void make_callback(uv_async_t* handle) { |
| 145 | #else |
| 146 | static void make_callback(uv_async_t* handle, int status) { |
| 147 | #endif |
| 148 | |
| 149 | Nan::HandleScope scope; |
| 150 | |
| 151 | struct callback_args* args = (struct callback_args*) handle->data; |
| 152 | |
| 153 | // lock the mutex |
| 154 | pthread_mutex_lock(&args->mutex); |
| 155 | |
| 156 | // build the stack arguments |
| 157 | Local<Array> argStack = Nan::New<Array>(args->stack_size); |
| 158 | for (size_t i = 0; i < args->stack_size; i++) { |
| 159 | Nan::Set(argStack, i, Nan::New<String>(args->stack[i]).ToLocalChecked()); |
| 160 | } |
| 161 | |
| 162 | // collect all callback arguments |
| 163 | Local<Value> argv[3] = {Nan::New<Number>(args->signo), Nan::New<Number>(args->addr), argStack}; |
| 164 | |
| 165 | // execute the callback function on the main threaod |
| 166 | Nan::Call(Nan::New<Function>(*args->callback), Nan::GetCurrentContext()->Global(), 3, argv); |
| 167 | |
| 168 | // broadcast that we're done with the callback |
| 169 | pthread_cond_broadcast(&args->cond); |
| 170 | |
| 171 | // unlock the mutex |
| 172 | pthread_mutex_unlock(&args->mutex); |
| 173 | } |
| 174 | }; |
| 175 | |
| 176 | struct callback_helper* callback; |
| 177 | #endif |