summaryrefslogtreecommitdiff
path: root/legacy/ecore/src/lib/ecore/ecore_main.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2011-09-02 03:29:11 +0000
committerCarsten Haitzler <raster@rasterman.com>2011-09-02 03:29:11 +0000
commitf67bdb7c374dbc7c47b0ed9a5d0539bb15c9fdc7 (patch)
treed3318121d10e677aec884b6515cef4d16f4e65a8 /legacy/ecore/src/lib/ecore/ecore_main.c
parente26e9df5b22fd75b08a6d0671d6f4dcca7754492 (diff)
mainloop cleanups on top of previous ones and fixes for previous refactors
SVN revision: 63082
Diffstat (limited to '')
-rw-r--r--legacy/ecore/src/lib/ecore/ecore_main.c218
1 files changed, 134 insertions, 84 deletions
diff --git a/legacy/ecore/src/lib/ecore/ecore_main.c b/legacy/ecore/src/lib/ecore/ecore_main.c
index 290052ddf2..791d66ff7a 100644
--- a/legacy/ecore/src/lib/ecore/ecore_main.c
+++ b/legacy/ecore/src/lib/ecore/ecore_main.c
@@ -494,7 +494,7 @@ _ecore_main_gsource_prepare(GSource *source __UNUSED__, gint *next_time)
494 if (!ecore_idling && !_ecore_glib_idle_enterer_called) 494 if (!ecore_idling && !_ecore_glib_idle_enterer_called)
495 { 495 {
496 _ecore_time_loop_time = ecore_time_get(); 496 _ecore_time_loop_time = ecore_time_get();
497 while (_ecore_timer_call(_ecore_time_loop_time)); 497 _ecore_timer_expired_timers_call(_ecore_time_loop_time);
498 _ecore_timer_cleanup(); 498 _ecore_timer_cleanup();
499 499
500 _ecore_idle_enterer_call(); 500 _ecore_idle_enterer_call();
@@ -505,7 +505,7 @@ _ecore_main_gsource_prepare(GSource *source __UNUSED__, gint *next_time)
505 _ecore_main_fd_handlers_buf_call(); 505 _ecore_main_fd_handlers_buf_call();
506 } 506 }
507 507
508 while (_ecore_signal_count_get()) _ecore_signal_call(); 508 _ecore_signal_received_process();
509 509
510 /* don't check fds if somebody quit */ 510 /* don't check fds if somebody quit */
511 if (g_main_loop_is_running(ecore_main_loop)) 511 if (g_main_loop_is_running(ecore_main_loop))
@@ -673,11 +673,11 @@ _ecore_main_gsource_dispatch(GSource *source __UNUSED__, GSourceFunc callback __
673 _ecore_main_fd_handlers_call(); 673 _ecore_main_fd_handlers_call();
674 if (fd_handlers_with_buffer) 674 if (fd_handlers_with_buffer)
675 _ecore_main_fd_handlers_buf_call(); 675 _ecore_main_fd_handlers_buf_call();
676 while (_ecore_signal_count_get()) _ecore_signal_call(); 676 _ecore_signal_received_process();
677 _ecore_event_call(); 677 _ecore_event_call();
678 _ecore_main_fd_handlers_cleanup(); 678 _ecore_main_fd_handlers_cleanup();
679 679
680 while (_ecore_timer_call(_ecore_time_loop_time)); 680 _ecore_timer_expired_timers_call(_ecore_time_loop_time);
681 _ecore_timer_cleanup(); 681 _ecore_timer_cleanup();
682 682
683 _ecore_idle_enterer_call(); 683 _ecore_idle_enterer_call();
@@ -1600,157 +1600,207 @@ _ecore_main_fd_handlers_buf_call(void)
1600} 1600}
1601 1601
1602#ifndef USE_G_MAIN_LOOP 1602#ifndef USE_G_MAIN_LOOP
1603
1604enum {
1605 SPIN_MORE,
1606 SPIN_RESTART,
1607 LOOP_CONTINUE
1608};
1609
1610static int
1611_ecore_main_loop_spin_core(void)
1612{
1613 /* as we are spinning we need to update loop time per spin */
1614 _ecore_time_loop_time = ecore_time_get();
1615 /* call all idlers, which returns false if no more idelrs exist */
1616 if (!_ecore_idler_all_call()) return SPIN_RESTART;
1617 /* sneaky - drop through or if checks - the first one to succeed
1618 * drops through and returns "continue" so further ones dont run */
1619 if ((_ecore_main_select(0.0) > 0) || (_ecore_event_exist()) ||
1620 (_ecore_signal_count_get() > 0) || (do_quit))
1621 return LOOP_CONTINUE;
1622 /* default - spin more */
1623 return SPIN_MORE;
1624}
1625
1626static int
1627_ecore_main_loop_spin_no_timers(void)
1628{
1629 /* if we have idlers we HAVE to spin and handle everything
1630 * in a polling way - spin in a tight polling loop */
1631 for (;;)
1632 {
1633 int action = _ecore_main_loop_spin_core();
1634 if (action != SPIN_MORE) return action;
1635 /* if an idler has added a timer then we need to go through
1636 * the start of the spin cycle again to handle cases properly */
1637 if (_ecore_timers_exists()) return SPIN_RESTART;
1638 }
1639 /* just contiune handling events etc. */
1640 return LOOP_CONTINUE;
1641}
1642
1643static int
1644_ecore_main_loop_spin_timers(void)
1645{
1646 /* if we have idlers we HAVE to spin and handle everything
1647 * in a polling way - spin in a tight polling loop */
1648 for (;;)
1649 {
1650 int action = _ecore_main_loop_spin_core();
1651 if (action != SPIN_MORE) return action;
1652 /* if next timer expires now or in the past - stop spinning and
1653 * continue the mainloop walk as our "select" timeout has
1654 * expired now */
1655 if (_ecore_timer_next_get() <= 0.0) return LOOP_CONTINUE;
1656 }
1657 /* just contiune handling events etc. */
1658 return LOOP_CONTINUE;
1659}
1660
1661static void
1662_ecore_fps_marker_1(void)
1663{
1664 if (!_ecore_fps_debug) return;
1665 t2 = ecore_time_get();
1666 if ((t1 > 0.0) && (t2 > 0.0)) _ecore_fps_debug_runtime_add(t2 - t1);
1667}
1668
1669static void
1670_ecore_fps_marker_2(void)
1671{
1672 if (!_ecore_fps_debug) return;
1673 t1 = ecore_time_get();
1674}
1675
1603static void 1676static void
1604_ecore_main_loop_iterate_internal(int once_only) 1677_ecore_main_loop_iterate_internal(int once_only)
1605{ 1678{
1606 double next_time = -1.0; 1679 double next_time = -1.0;
1607 int have_event = 0;
1608 int have_signal;
1609 1680
1610 in_main_loop++; 1681 in_main_loop++;
1611 /* expire any timers */ 1682 /* expire any timers */
1612 while (_ecore_timer_call(_ecore_time_loop_time)); 1683 _ecore_timer_expired_timers_call(_ecore_time_loop_time);
1613 _ecore_timer_cleanup(); 1684 _ecore_timer_cleanup();
1614 1685
1615 /* process signals into events .... */ 1686 /* process signals into events .... */
1616 while (_ecore_signal_count_get()) _ecore_signal_call(); 1687 _ecore_signal_received_process();
1688 /* if as a result of timers/animators or signals we have accumulated
1689 * events, then instantly handle them */
1617 if (_ecore_event_exist()) 1690 if (_ecore_event_exist())
1618 { 1691 {
1692 /* but first conceptually enter an idle state */
1619 _ecore_idle_enterer_call(); 1693 _ecore_idle_enterer_call();
1620 _ecore_throttle(); 1694 _ecore_throttle();
1621 have_event = 1; 1695 /* now quickly poll to see which input fd's are active */
1622 _ecore_main_select(0.0); 1696 _ecore_main_select(0.0);
1697 /* allow newly queued timers to expire from now on */
1623 _ecore_timer_enable_new(); 1698 _ecore_timer_enable_new();
1624 goto process_events; 1699 /* go straight to processing the events we had queued */
1700 goto process_all;
1625 } 1701 }
1626 /* call idle enterers ... */ 1702
1627 if (!once_only) 1703 if (once_only)
1628 {
1629 _ecore_idle_enterer_call();
1630 _ecore_throttle();
1631 }
1632 else
1633 { 1704 {
1634 have_event = have_signal = 0; 1705 /* in once_only mode we should quickly poll for inputs, signals
1635 1706 * if we got any events or signals, allow new timers to process.
1636 if (_ecore_main_select(0.0) > 0) have_event = 1; 1707 * use bitwise or to force both conditions to be tested and
1637 if (_ecore_signal_count_get() > 0) have_signal = 1; 1708 * merged together */
1638 if (have_signal || have_event) 1709 if (_ecore_main_select(0.0) | _ecore_signal_count_get())
1639 { 1710 {
1640 _ecore_timer_enable_new(); 1711 _ecore_timer_enable_new();
1641 goto process_events; 1712 goto process_all;
1642 } 1713 }
1643 } 1714 }
1715 else
1716 {
1717 /* call idle enterers ... */
1718 _ecore_idle_enterer_call();
1719 _ecore_throttle();
1720 }
1644 1721
1645 /* if these calls caused any buffered events to appear - deal with them */ 1722 /* if these calls caused any buffered events to appear - deal with them */
1646 if (fd_handlers_with_buffer) 1723 if (fd_handlers_with_buffer)
1647 _ecore_main_fd_handlers_buf_call(); 1724 _ecore_main_fd_handlers_buf_call();
1648 1725
1649 /* if there are any - jump to processing them */ 1726 /* if there are any (buffered fd handling may generate them)
1727 * then jump to processing them */
1650 if (_ecore_event_exist()) 1728 if (_ecore_event_exist())
1651 { 1729 {
1652 have_event = 1;
1653 _ecore_main_select(0.0); 1730 _ecore_main_select(0.0);
1654 _ecore_timer_enable_new(); 1731 _ecore_timer_enable_new();
1655 goto process_events; 1732 goto process_all;
1656 } 1733 }
1734
1657 if (once_only) 1735 if (once_only)
1658 { 1736 {
1737 /* in once_only mode enter idle here instead and then return */
1659 _ecore_idle_enterer_call(); 1738 _ecore_idle_enterer_call();
1660 _ecore_throttle(); 1739 _ecore_throttle();
1661 in_main_loop--;
1662 _ecore_timer_enable_new(); 1740 _ecore_timer_enable_new();
1663 return; 1741 goto done;
1664 } 1742 }
1665 1743
1666 if (_ecore_fps_debug) 1744 _ecore_fps_marker_1();
1667 { 1745
1668 t2 = ecore_time_get(); 1746 /* start of the sleeping or looping section */
1669 if ((t1 > 0.0) && (t2 > 0.0)) 1747start_loop: /***************************************************************/
1670 _ecore_fps_debug_runtime_add(t2 - t1);
1671 }
1672 start_loop:
1673 /* any timers re-added as a result of these are allowed to go */ 1748 /* any timers re-added as a result of these are allowed to go */
1674 _ecore_timer_enable_new(); 1749 _ecore_timer_enable_new();
1750 /* if we have been asked to quit the mainloop then exit at this point */
1675 if (do_quit) 1751 if (do_quit)
1676 { 1752 {
1677 in_main_loop--;
1678 _ecore_timer_enable_new(); 1753 _ecore_timer_enable_new();
1679 return; 1754 goto done;
1680 } 1755 }
1681 /* init flags */ 1756 if (!_ecore_event_exist())
1682 have_event = have_signal = 0;
1683 next_time = _ecore_timer_next_get();
1684 /* no timers */
1685 if (next_time < 0)
1686 { 1757 {
1758 /* init flags */
1759 next_time = _ecore_timer_next_get();
1687 /* no idlers */ 1760 /* no idlers */
1688 if (!_ecore_idler_exist()) 1761 if (!_ecore_idler_exist())
1689 { 1762 {
1690 if (_ecore_main_select(-1.0) > 0) have_event = 1; 1763 /* sleep until timeout or forever (-1.0) waiting for on fds */
1764 _ecore_main_select(next_time);
1691 } 1765 }
1692 /* idlers */
1693 else 1766 else
1694 { 1767 {
1695 for (;;) 1768 int action = LOOP_CONTINUE;
1696 { 1769
1697 _ecore_time_loop_time = ecore_time_get(); 1770 /* no timers - spin */
1698 if (!_ecore_idler_call()) goto start_loop; 1771 if (next_time < 0) action = _ecore_main_loop_spin_no_timers();
1699 if (_ecore_main_select(0.0) > 0) break; 1772 /* timers - spin */
1700 if (_ecore_event_exist()) break; 1773 else action = _ecore_main_loop_spin_timers();
1701 if (_ecore_signal_count_get() > 0) break; 1774 if (action == SPIN_RESTART) goto start_loop;
1702 if (_ecore_timers_exists()) goto start_loop;
1703 if (do_quit) break;
1704 }
1705 }
1706 }
1707 /* timers */
1708 else
1709 {
1710 /* no idlers */
1711 if (!_ecore_idler_exist())
1712 {
1713 if (_ecore_main_select(next_time) > 0) have_event = 1;
1714 }
1715 /* idlers */
1716 else
1717 {
1718 for (;;)
1719 {
1720 _ecore_time_loop_time = ecore_time_get();
1721 if (!_ecore_idler_call()) goto start_loop;
1722 if (_ecore_main_select(0.0) > 0) break;
1723 if (_ecore_event_exist()) break;
1724 if (_ecore_signal_count_get() > 0) break;
1725 if (have_event || have_signal) break;
1726 next_time = _ecore_timer_next_get();
1727 if (next_time <= 0) break;
1728 if (do_quit) break;
1729 }
1730 } 1775 }
1731 } 1776 }
1777 _ecore_fps_marker_2();
1778
1779
1780 /* actually wake up and deal with input, events etc. */
1781process_all: /***********************************************************/
1732 1782
1733 if (_ecore_fps_debug) t1 = ecore_time_get();
1734 /* we came out of our "wait state" so idle has exited */ 1783 /* we came out of our "wait state" so idle has exited */
1735 process_events:
1736 if (!once_only) _ecore_idle_exiter_call(); 1784 if (!once_only) _ecore_idle_exiter_call();
1737 /* call the fd handler per fd that became alive... */ 1785 /* call the fd handler per fd that became alive... */
1738 /* this should read or write any data to the monitored fd and then */ 1786 /* this should read or write any data to the monitored fd and then */
1739 /* post events onto the ecore event pipe if necessary */ 1787 /* post events onto the ecore event pipe if necessary */
1740 _ecore_main_fd_handlers_call(); 1788 _ecore_main_fd_handlers_call();
1741 if (fd_handlers_with_buffer) 1789 if (fd_handlers_with_buffer) _ecore_main_fd_handlers_buf_call();
1742 _ecore_main_fd_handlers_buf_call();
1743 /* process signals into events .... */ 1790 /* process signals into events .... */
1744 while (_ecore_signal_count_get()) _ecore_signal_call(); 1791 _ecore_signal_received_process();
1745 /* handle events ... */ 1792 /* handle events ... */
1746 _ecore_event_call(); 1793 _ecore_event_call();
1747 _ecore_main_fd_handlers_cleanup(); 1794 _ecore_main_fd_handlers_cleanup();
1748 1795
1749 if (once_only) 1796 if (once_only)
1750 { 1797 {
1798 /* if in once_only mode handle idle exiting */
1751 _ecore_idle_enterer_call(); 1799 _ecore_idle_enterer_call();
1752 _ecore_throttle(); 1800 _ecore_throttle();
1753 } 1801 }
1802
1803done: /*******************************************************************/
1754 in_main_loop--; 1804 in_main_loop--;
1755} 1805}
1756#endif 1806#endif