Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | In StartNotifierThread() don't lock mutex if thread is already started. Fix panic message if thread cannot be started. Remove asserts used for debugging. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | bug-5d170b5ca5 |
Files: | files | file ages | folders |
SHA1: |
795a9a8bc0bb3d58c359048db9064b29 |
User & Date: | jan.nijtmans 2015-09-03 09:39:43 |
Context
2015-09-05
| ||
20:10 | Merge trunk. "paranoia" patch for the notifier, making sure that thread local data from invalid thr... check-in: d8fd974ade user: jan.nijtmans tags: bug-5d170b5ca5 | |
2015-09-03
| ||
09:39 | In StartNotifierThread() don't lock mutex if thread is already started. Fix panic message if thread... check-in: 795a9a8bc0 user: jan.nijtmans tags: bug-5d170b5ca5 | |
2015-09-02
| ||
11:54 | Fix the Cygwin notifier, doing the initialization of the thread-local variables exactly the same as ... check-in: 57e106c650 user: jan.nijtmans tags: bug-5d170b5ca5 | |
Changes
Changes to unix/tclUnixNotfy.c.
︙ | ︙ | |||
13 14 15 16 17 18 19 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #ifndef HAVE_COREFOUNDATION /* Darwin/Mac OS X CoreFoundation notifier is * in tclMacOSXNotify.c */ #include <signal.h> | < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | * of this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #ifndef HAVE_COREFOUNDATION /* Darwin/Mac OS X CoreFoundation notifier is * in tclMacOSXNotify.c */ #include <signal.h> /* * This structure is used to keep track of the notifier info for a registered * file. */ typedef struct FileHandler { |
︙ | ︙ | |||
275 276 277 278 279 280 281 | * * Side effects: * Running Thread. * *---------------------------------------------------------------------- */ static void | | | | | | | | | | | | | | | | | | | | > | 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | * * Side effects: * Running Thread. * *---------------------------------------------------------------------- */ static void StartNotifierThread(const char *proc) { if (!notifierThreadRunning) { pthread_mutex_lock(¬ifierInitMutex); if (!notifierThreadRunning) { if (TclpThreadCreate(¬ifierThread, NotifierThreadProc, NULL, TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) { Tcl_Panic("%s: unable to start notifier thread", proc); } pthread_mutex_lock(¬ifierMutex); /* * Wait for the notifier pipe to be created. */ while (triggerPipe < 0) { pthread_cond_wait(¬ifierCV, ¬ifierMutex); } pthread_mutex_unlock(¬ifierMutex); notifierThreadRunning = 1; } pthread_mutex_unlock(¬ifierInitMutex); } } #endif /* TCL_THREADS */ /* *---------------------------------------------------------------------- * * Tcl_InitNotifier -- |
︙ | ︙ | |||
354 355 356 357 358 359 360 | tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName, class.lpszClassName, 0, 0, 0, 0, 0, NULL, NULL, TclWinGetTclInstance(), NULL); tsdPtr->event = CreateEventW(NULL, 1 /* manual */, 0 /* !signaled */, NULL); #else pthread_cond_init(&tsdPtr->waitCV, NULL); | | | 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | tsdPtr->hwnd = CreateWindowExW(NULL, class.lpszClassName, class.lpszClassName, 0, 0, 0, 0, 0, NULL, NULL, TclWinGetTclInstance(), NULL); tsdPtr->event = CreateEventW(NULL, 1 /* manual */, 0 /* !signaled */, NULL); #else pthread_cond_init(&tsdPtr->waitCV, NULL); #endif /* __CYGWIN__ */ tsdPtr->waitCVinitialized = 1; } pthread_mutex_lock(¬ifierInitMutex); #if defined(HAVE_PTHREAD_ATFORK) && !defined(__APPLE__) && !defined(__hpux) /* * Install pthread_atfork handlers to clean up the notifier in the |
︙ | ︙ | |||
416 417 418 419 420 421 422 | } else { #ifdef TCL_THREADS ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); pthread_mutex_lock(¬ifierInitMutex); notifierCount--; | < < < < < < | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | } else { #ifdef TCL_THREADS ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); pthread_mutex_lock(¬ifierInitMutex); notifierCount--; /* * If this is the last thread to use the notifier, close the notifier * pipe and wait for the background thread to terminate. */ if (notifierCount == 0) { |
︙ | ︙ | |||
570 571 572 573 574 575 576 | * TCL_SERVICE_NONE. */ { if (tclNotifierHooks.serviceModeHookProc) { tclNotifierHooks.serviceModeHookProc(mode); return; } else if (mode == TCL_SERVICE_ALL) { #if TCL_THREADS | | | 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 | * TCL_SERVICE_NONE. */ { if (tclNotifierHooks.serviceModeHookProc) { tclNotifierHooks.serviceModeHookProc(mode); return; } else if (mode == TCL_SERVICE_ALL) { #if TCL_THREADS StartNotifierThread("Tcl_ServiceModeHook"); #endif } } /* *---------------------------------------------------------------------- * |
︙ | ︙ | |||
609 610 611 612 613 614 615 | if (tclNotifierHooks.createFileHandlerProc) { tclNotifierHooks.createFileHandlerProc(fd, mask, proc, clientData); return; } else { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); FileHandler *filePtr; | < < < < | 603 604 605 606 607 608 609 610 611 612 613 614 615 616 | if (tclNotifierHooks.createFileHandlerProc) { tclNotifierHooks.createFileHandlerProc(fd, mask, proc, clientData); return; } else { ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); FileHandler *filePtr; for (filePtr = tsdPtr->firstFileHandlerPtr; filePtr != NULL; filePtr = filePtr->nextPtr) { if (filePtr->fd == fd) { break; } } if (filePtr == NULL) { |
︙ | ︙ | |||
684 685 686 687 688 689 690 | tclNotifierHooks.deleteFileHandlerProc(fd); return; } else { FileHandler *filePtr, *prevPtr; int i; ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); | < < < < < | 674 675 676 677 678 679 680 681 682 683 684 685 686 687 | tclNotifierHooks.deleteFileHandlerProc(fd); return; } else { FileHandler *filePtr, *prevPtr; int i; ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); /* * Find the entry for the given file (and return if there isn't one). */ for (prevPtr = NULL, filePtr = tsdPtr->firstFileHandlerPtr; ; prevPtr = filePtr, filePtr = filePtr->nextPtr) { if (filePtr == NULL) { |
︙ | ︙ | |||
794 795 796 797 798 799 800 | * the event. We do this rather than keeping a pointer to the file handler * directly in the event, so that the handler can be deleted while the * event is queued without leaving a dangling pointer. */ tsdPtr = TCL_TSD_INIT(&dataKey); | < < < < < | 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | * the event. We do this rather than keeping a pointer to the file handler * directly in the event, so that the handler can be deleted while the * event is queued without leaving a dangling pointer. */ tsdPtr = TCL_TSD_INIT(&dataKey); for (filePtr = tsdPtr->firstFileHandlerPtr; filePtr != NULL; filePtr = filePtr->nextPtr) { if (filePtr->fd != fileEvPtr->fd) { continue; } /* |
︙ | ︙ | |||
897 898 899 900 901 902 903 | */ struct timeval timeout, *timeoutPtr; int numFound; #endif /* TCL_THREADS */ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); | < < < < < | 877 878 879 880 881 882 883 884 885 886 887 888 889 890 | */ struct timeval timeout, *timeoutPtr; int numFound; #endif /* TCL_THREADS */ ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); /* * Set up the timeout structure. Note that if there are no events to * check for, we return with a negative result rather than blocking * forever. */ if (timePtr != NULL) { |
︙ | ︙ | |||
945 946 947 948 949 950 951 | #ifdef TCL_THREADS /* * Start notifier thread and place this thread on the list of * interested threads, signal the notifier thread, and wait for a * response or a timeout. */ | | | 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 | #ifdef TCL_THREADS /* * Start notifier thread and place this thread on the list of * interested threads, signal the notifier thread, and wait for a * response or a timeout. */ StartNotifierThread("Tcl_WaitForEvent"); pthread_mutex_lock(¬ifierMutex); if (timePtr != NULL && timePtr->sec == 0 && (timePtr->usec == 0 #if defined(__APPLE__) && defined(__LP64__) /* * On 64-bit Darwin, pthread_cond_timedwait() appears to have |
︙ | ︙ | |||
1472 1473 1474 1475 1476 1477 1478 | */ waitingListPtr = NULL; /* * The tsdPtr from before the fork is copied as well. But since * we are paranoic, we don't trust its condvar and reset it. */ | < > < < < | 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 | */ waitingListPtr = NULL; /* * The tsdPtr from before the fork is copied as well. But since * we are paranoic, we don't trust its condvar and reset it. */ #ifdef __CYGWIN__ DestroyWindow(tsdPtr->hwnd); tsdPtr->hwnd = CreateWindowExW(NULL, NotfyClassName, NotfyClassName, 0, 0, 0, 0, 0, NULL, NULL, TclWinGetTclInstance(), NULL); ResetEvent(tsdPtr->event); #else pthread_cond_destroy(&tsdPtr->waitCV); pthread_cond_init(&tsdPtr->waitCV, NULL); #endif /* * The list of registered event handlers at fork time is in * tsdPtr->firstFileHandlerPtr; */ } } Tcl_InitNotifier(); } #endif /* HAVE_PTHREAD_ATFORK */ #endif /* TCL_THREADS */ |
︙ | ︙ |