Mercurial > hg > nginx
comparison src/event/modules/ngx_kqueue_module.c @ 6029:e284f3ff6831
Removed old pthread implementation.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Fri, 20 Mar 2015 06:43:19 +0300 |
parents | e5f1d83360ef |
children | 4652f8f26b12 |
comparison
equal
deleted
inserted
replaced
6028:fa77496b1df2 | 6029:e284f3ff6831 |
---|---|
56 | 56 |
57 #ifdef EVFILT_USER | 57 #ifdef EVFILT_USER |
58 static ngx_event_t notify_event; | 58 static ngx_event_t notify_event; |
59 static struct kevent notify_kev; | 59 static struct kevent notify_kev; |
60 #endif | 60 #endif |
61 | |
62 #if (NGX_OLD_THREADS) | |
63 static ngx_mutex_t *list_mutex; | |
64 static ngx_mutex_t *kevent_mutex; | |
65 #endif | |
66 | |
67 | 61 |
68 | 62 |
69 static ngx_str_t kqueue_name = ngx_string("kqueue"); | 63 static ngx_str_t kqueue_name = ngx_string("kqueue"); |
70 | 64 |
71 static ngx_command_t ngx_kqueue_commands[] = { | 65 static ngx_command_t ngx_kqueue_commands[] = { |
152 #ifdef EVFILT_USER | 146 #ifdef EVFILT_USER |
153 if (ngx_kqueue_notify_init(cycle->log) != NGX_OK) { | 147 if (ngx_kqueue_notify_init(cycle->log) != NGX_OK) { |
154 return NGX_ERROR; | 148 return NGX_ERROR; |
155 } | 149 } |
156 #endif | 150 #endif |
157 | |
158 #if (NGX_OLD_THREADS) | |
159 | |
160 list_mutex = ngx_mutex_init(cycle->log, 0); | |
161 if (list_mutex == NULL) { | |
162 return NGX_ERROR; | |
163 } | |
164 | |
165 kevent_mutex = ngx_mutex_init(cycle->log, 0); | |
166 if (kevent_mutex == NULL) { | |
167 return NGX_ERROR; | |
168 } | |
169 | |
170 #endif | |
171 } | 151 } |
172 | 152 |
173 if (max_changes < kcf->changes) { | 153 if (max_changes < kcf->changes) { |
174 if (nchanges) { | 154 if (nchanges) { |
175 ts.tv_sec = 0; | 155 ts.tv_sec = 0; |
308 "kqueue close() failed"); | 288 "kqueue close() failed"); |
309 } | 289 } |
310 | 290 |
311 ngx_kqueue = -1; | 291 ngx_kqueue = -1; |
312 | 292 |
313 #if (NGX_OLD_THREADS) | |
314 ngx_mutex_destroy(kevent_mutex); | |
315 ngx_mutex_destroy(list_mutex); | |
316 #endif | |
317 | |
318 ngx_free(change_list1); | 293 ngx_free(change_list1); |
319 ngx_free(change_list0); | 294 ngx_free(change_list0); |
320 ngx_free(event_list); | 295 ngx_free(event_list); |
321 | 296 |
322 change_list1 = NULL; | 297 change_list1 = NULL; |
340 | 315 |
341 ev->active = 1; | 316 ev->active = 1; |
342 ev->disabled = 0; | 317 ev->disabled = 0; |
343 ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0; | 318 ev->oneshot = (flags & NGX_ONESHOT_EVENT) ? 1 : 0; |
344 | 319 |
345 ngx_mutex_lock(list_mutex); | |
346 | |
347 #if 0 | 320 #if 0 |
348 | 321 |
349 if (ev->index < nchanges | 322 if (ev->index < nchanges |
350 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) | 323 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) |
351 == (uintptr_t) ev) | 324 == (uintptr_t) ev) |
366 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); | 339 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); |
367 change_list[ev->index] = change_list[nchanges]; | 340 change_list[ev->index] = change_list[nchanges]; |
368 e->index = ev->index; | 341 e->index = ev->index; |
369 } | 342 } |
370 | 343 |
371 ngx_mutex_unlock(list_mutex); | |
372 | |
373 return NGX_OK; | 344 return NGX_OK; |
374 } | 345 } |
375 | 346 |
376 c = ev->data; | 347 c = ev->data; |
377 | 348 |
378 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, | 349 ngx_log_error(NGX_LOG_ALERT, ev->log, 0, |
379 "previous event on #%d were not passed in kernel", c->fd); | 350 "previous event on #%d were not passed in kernel", c->fd); |
380 | 351 |
381 ngx_mutex_unlock(list_mutex); | |
382 | |
383 return NGX_ERROR; | 352 return NGX_ERROR; |
384 } | 353 } |
385 | 354 |
386 #endif | 355 #endif |
387 | 356 |
388 rc = ngx_kqueue_set_event(ev, event, EV_ADD|EV_ENABLE|flags); | 357 rc = ngx_kqueue_set_event(ev, event, EV_ADD|EV_ENABLE|flags); |
389 | |
390 ngx_mutex_unlock(list_mutex); | |
391 | 358 |
392 return rc; | 359 return rc; |
393 } | 360 } |
394 | 361 |
395 | 362 |
399 ngx_int_t rc; | 366 ngx_int_t rc; |
400 ngx_event_t *e; | 367 ngx_event_t *e; |
401 | 368 |
402 ev->active = 0; | 369 ev->active = 0; |
403 ev->disabled = 0; | 370 ev->disabled = 0; |
404 | |
405 ngx_mutex_lock(list_mutex); | |
406 | 371 |
407 if (ev->index < nchanges | 372 if (ev->index < nchanges |
408 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) | 373 && ((uintptr_t) change_list[ev->index].udata & (uintptr_t) ~1) |
409 == (uintptr_t) ev) | 374 == (uintptr_t) ev) |
410 { | 375 { |
421 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); | 386 ((uintptr_t) change_list[nchanges].udata & (uintptr_t) ~1); |
422 change_list[ev->index] = change_list[nchanges]; | 387 change_list[ev->index] = change_list[nchanges]; |
423 e->index = ev->index; | 388 e->index = ev->index; |
424 } | 389 } |
425 | 390 |
426 ngx_mutex_unlock(list_mutex); | |
427 | |
428 return NGX_OK; | 391 return NGX_OK; |
429 } | 392 } |
430 | 393 |
431 /* | 394 /* |
432 * when the file descriptor is closed the kqueue automatically deletes | 395 * when the file descriptor is closed the kqueue automatically deletes |
433 * its filters so we do not need to delete explicitly the event | 396 * its filters so we do not need to delete explicitly the event |
434 * before the closing the file descriptor. | 397 * before the closing the file descriptor. |
435 */ | 398 */ |
436 | 399 |
437 if (flags & NGX_CLOSE_EVENT) { | 400 if (flags & NGX_CLOSE_EVENT) { |
438 ngx_mutex_unlock(list_mutex); | |
439 return NGX_OK; | 401 return NGX_OK; |
440 } | 402 } |
441 | 403 |
442 if (flags & NGX_DISABLE_EVENT) { | 404 if (flags & NGX_DISABLE_EVENT) { |
443 ev->disabled = 1; | 405 ev->disabled = 1; |
445 } else { | 407 } else { |
446 flags |= EV_DELETE; | 408 flags |= EV_DELETE; |
447 } | 409 } |
448 | 410 |
449 rc = ngx_kqueue_set_event(ev, event, flags); | 411 rc = ngx_kqueue_set_event(ev, event, flags); |
450 | |
451 ngx_mutex_unlock(list_mutex); | |
452 | 412 |
453 return rc; | 413 return rc; |
454 } | 414 } |
455 | 415 |
456 | 416 |
754 ngx_int_t rc; | 714 ngx_int_t rc; |
755 ngx_err_t err; | 715 ngx_err_t err; |
756 struct timespec ts; | 716 struct timespec ts; |
757 struct kevent *changes; | 717 struct kevent *changes; |
758 | 718 |
759 ngx_mutex_lock(kevent_mutex); | |
760 | |
761 ngx_mutex_lock(list_mutex); | |
762 | |
763 if (nchanges == 0) { | 719 if (nchanges == 0) { |
764 ngx_mutex_unlock(list_mutex); | |
765 ngx_mutex_unlock(kevent_mutex); | |
766 return NGX_OK; | 720 return NGX_OK; |
767 } | 721 } |
768 | 722 |
769 changes = change_list; | 723 changes = change_list; |
770 if (change_list == change_list0) { | 724 if (change_list == change_list0) { |
774 } | 728 } |
775 | 729 |
776 n = (int) nchanges; | 730 n = (int) nchanges; |
777 nchanges = 0; | 731 nchanges = 0; |
778 | 732 |
779 ngx_mutex_unlock(list_mutex); | |
780 | |
781 ts.tv_sec = 0; | 733 ts.tv_sec = 0; |
782 ts.tv_nsec = 0; | 734 ts.tv_nsec = 0; |
783 | 735 |
784 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, | 736 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
785 "kevent changes: %d", n); | 737 "kevent changes: %d", n); |
791 rc = NGX_ERROR; | 743 rc = NGX_ERROR; |
792 | 744 |
793 } else { | 745 } else { |
794 rc = NGX_OK; | 746 rc = NGX_OK; |
795 } | 747 } |
796 | |
797 ngx_mutex_unlock(kevent_mutex); | |
798 | 748 |
799 return rc; | 749 return rc; |
800 } | 750 } |
801 | 751 |
802 | 752 |