Tcl Source Code

Check-in [834c53d3c6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:avoid busy wait if new short block-time will be set within service event-cycle (Tcl_DoOneEvent) produced in event-cycle without processing
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | sebres-event-perf-fix-busy-wait
Files: files | file ages | folders
SHA1: 834c53d3c68e5d1762c72f32f4e7bdd4bedb5038
User & Date: sebres 2017-07-13 15:43:42
Context
2017-07-13
16:04
merge sebres-event-perf-fix-busy-wait check-in: de29c24e4b user: sebres tags: sebres-8-6-event-perf-branch
15:46
merge (integrate) sebres-event-perf-fix-busy-wait check-in: e619eb2ac3 user: sebres tags: sebres-8-5-event-perf-branch
15:43
avoid busy wait if new short block-time will be set within service event-cycle (Tcl_DoOneEvent) prod... Closed-Leaf check-in: 834c53d3c6 user: sebres tags: sebres-event-perf-fix-busy-wait
15:41
timer: fixed setup of the block-time to 0.0 by pending timer of new generation, example: tclsh -c ... check-in: 65b4e0df6a user: sebres tags: sebres-event-perf-fix-busy-wait
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclNotify.c.

1522
1523
1524
1525
1526
1527
1528
1529
1530
1531








1532
1533
1534
1535
1536
1537
1538
1539
	 *
	 * We can stop also if works in block to event mode (e. g. block time was
	 * set outside an event source, that means timeout was set so exit loop
	 * also without event/result).
	 */

	result = 0;
	if (blockTimeWasSet) {
	    break;
	}








    } while ( !(flags & TCL_DONT_WAIT) );

done:
    /*
     * Reset block time earliest at the end of event cycle and restore mode.
     */
    if (tsdPtr->blockTimeServLev < tsdPtr->serviceLevel) {
	tsdPtr->blockTimeSet = 0;







|


>
>
>
>
>
>
>
>
|







1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
	 *
	 * We can stop also if works in block to event mode (e. g. block time was
	 * set outside an event source, that means timeout was set so exit loop
	 * also without event/result).
	 */

	result = 0;
	if ((flags & TCL_DONT_WAIT) || blockTimeWasSet) {
	    break;
	}

	/*
	 * Reset block time before continue event-cycle.
	 */
	if (tsdPtr->blockTimeServLev < tsdPtr->serviceLevel) {
	    tsdPtr->blockTimeSet = 0;
	    tsdPtr->blockTimeServLev = 0;
	}
    } while (1);

done:
    /*
     * Reset block time earliest at the end of event cycle and restore mode.
     */
    if (tsdPtr->blockTimeServLev < tsdPtr->serviceLevel) {
	tsdPtr->blockTimeSet = 0;
1575
1576
1577
1578
1579
1580
1581

1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597

1598

1599
1600
1601
1602

1603
1604
1605
1606
1607
1608
1609

1610
1611
1612
1613
1614


1615
1616
1617
1618
1619
1620
1621
    }

    /*
     * We need to turn off event servicing like we to in Tcl_DoOneEvent, to
     * avoid recursive calls.
     */


    tsdPtr->serviceMode = TCL_SERVICE_NONE;

    /*
     * Check async handlers first.
     */

    if (Tcl_AsyncReady()) {
	(void) Tcl_AsyncInvoke(NULL, 0);
    }

    /*
     * Make a single pass through all event sources, queued events, and idle
     * handlers. Note that we wait to update the notifier timer until the end
     * so we can avoid multiple changes.
     */


    tsdPtr->blockTimeSet = 0;


    SetUpEventSources(tsdPtr, TCL_ALL_EVENTS);
    CheckEventSources(tsdPtr, TCL_ALL_EVENTS);


    while (Tcl_ServiceEvent(0)) {
	result = 1;
    }
    if (TclServiceIdle()) {
	result = 1;
    }


    if (!tsdPtr->blockTimeSet) {
	Tcl_SetTimer(NULL);
    } else {
	Tcl_SetTimer(&tsdPtr->blockTime);
    }


    tsdPtr->serviceMode = TCL_SERVICE_ALL;
    return result;
}

/*
 *----------------------------------------------------------------------
 *







>
















>

>




>
|






>
|
|
|
|
|
>
>







1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
    }

    /*
     * We need to turn off event servicing like we to in Tcl_DoOneEvent, to
     * avoid recursive calls.
     */

    tsdPtr->serviceLevel++;
    tsdPtr->serviceMode = TCL_SERVICE_NONE;

    /*
     * Check async handlers first.
     */

    if (Tcl_AsyncReady()) {
	(void) Tcl_AsyncInvoke(NULL, 0);
    }

    /*
     * Make a single pass through all event sources, queued events, and idle
     * handlers. Note that we wait to update the notifier timer until the end
     * so we can avoid multiple changes.
     */

    tsdPtr->inTraversal++;
    tsdPtr->blockTimeSet = 0;
    tsdPtr->blockTimeServLev = 0;

    SetUpEventSources(tsdPtr, TCL_ALL_EVENTS);
    CheckEventSources(tsdPtr, TCL_ALL_EVENTS);

    if (Tcl_ServiceEvent(0)) {
	while (Tcl_ServiceEvent(0)) {};
	result = 1;
    }
    if (TclServiceIdle()) {
	result = 1;
    }

    if (tsdPtr->inTraversal-- <= 1) {
	if (!tsdPtr->blockTimeSet) {
	    Tcl_SetTimer(NULL);
	} else {
	    Tcl_SetTimer(&tsdPtr->blockTime);
	}
    }
    tsdPtr->serviceLevel--;
    tsdPtr->serviceMode = TCL_SERVICE_ALL;
    return result;
}

/*
 *----------------------------------------------------------------------
 *