ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev++.h
(Generate patch)

Comparing libev/ev++.h (file contents):
Revision 1.65 by root, Mon Oct 29 00:00:21 2018 UTC vs.
Revision 1.69 by root, Sat Jun 3 08:53:03 2023 UTC

1/* 1/*
2 * libev simple C++ wrapper classes 2 * libev simple C++ wrapper classes
3 * 3 *
4 * Copyright (c) 2007,2008,2010,2018 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2010,2018,2020 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
419#endif 419#endif
420 420
421 template<class ev_watcher, class watcher> 421 template<class ev_watcher, class watcher>
422 struct base : ev_watcher 422 struct base : ev_watcher
423 { 423 {
424 // scoped pause/unpause of a watcher
425 struct freeze_guard
426 {
427 watcher &w;
428 bool active;
429
430 freeze_guard (watcher *self) EV_NOEXCEPT
431 : w (*self), active (w.is_active ())
432 {
433 if (active) w.stop ();
434 }
435
436 ~freeze_guard ()
437 {
438 if (active) w.start ();
439 }
440 };
441
424 #if EV_MULTIPLICITY 442 #if EV_MULTIPLICITY
425 EV_PX; 443 EV_PX;
426 444
427 // loop set 445 // loop set
428 void set (EV_P) EV_NOEXCEPT 446 void set (EV_P) EV_NOEXCEPT
562 ev_set_syserr_cb (cb); 580 ev_set_syserr_cb (cb);
563 } 581 }
564 582
565 #if EV_MULTIPLICITY 583 #if EV_MULTIPLICITY
566 #define EV_CONSTRUCT(cppstem,cstem) \ 584 #define EV_CONSTRUCT(cppstem,cstem) \
567 (EV_PX = get_default_loop ()) EV_NOEXCEPT \ 585 (EV_PX = get_default_loop ()) EV_NOEXCEPT \
568 : base<ev_ ## cstem, cppstem> (EV_A) \ 586 : base<ev_ ## cstem, cppstem> (EV_A) \
569 { \ 587 { \
570 } 588 }
571 #else 589 #else
572 #define EV_CONSTRUCT(cppstem,cstem) \ 590 #define EV_CONSTRUCT(cppstem,cstem) \
573 () EV_NOEXCEPT \ 591 () EV_NOEXCEPT \
574 { \ 592 { \
575 } 593 }
576 #endif 594 #endif
577 595
578 /* using a template here would require quite a few more lines, 596 /* using a template here would require quite a few more lines,
579 * so a macro solution was chosen */ 597 * so a macro solution was chosen */
580 #define EV_BEGIN_WATCHER(cppstem,cstem) \ 598 #define EV_BEGIN_WATCHER(cppstem,cstem) \
581 \ 599 \
582 struct cppstem : base<ev_ ## cstem, cppstem> \ 600 struct cppstem : base<ev_ ## cstem, cppstem> \
583 { \ 601 { \
584 void start () EV_NOEXCEPT \ 602 void start () EV_NOEXCEPT \
585 { \ 603 { \
586 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 604 ev_ ## cstem ## _start (EV_A_ static_cast<ev_ ## cstem *>(this)); \
587 } \ 605 } \
588 \ 606 \
589 void stop () EV_NOEXCEPT \ 607 void stop () EV_NOEXCEPT \
590 { \ 608 { \
591 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \ 609 ev_ ## cstem ## _stop (EV_A_ static_cast<ev_ ## cstem *>(this)); \
592 } \ 610 } \
593 \ 611 \
594 cppstem EV_CONSTRUCT(cppstem,cstem) \ 612 cppstem EV_CONSTRUCT(cppstem,cstem) \
595 \ 613 \
596 ~cppstem () EV_NOEXCEPT \ 614 ~cppstem () EV_NOEXCEPT \
597 { \ 615 { \
598 stop (); \ 616 stop (); \
599 } \ 617 } \
600 \ 618 \
601 using base<ev_ ## cstem, cppstem>::set; \ 619 using base<ev_ ## cstem, cppstem>::set; \
608 \ 626 \
609 public: 627 public:
610 628
611 #define EV_END_WATCHER(cppstem,cstem) \ 629 #define EV_END_WATCHER(cppstem,cstem) \
612 }; 630 };
631 //TODO: https://paste.debian.net/1268417/
613 632
614 EV_BEGIN_WATCHER (io, io) 633 EV_BEGIN_WATCHER (io, io)
615 void set (int fd, int events) EV_NOEXCEPT 634 void set (int fd, int events) EV_NOEXCEPT
616 { 635 {
617 int active = is_active (); 636 freeze_guard freeze (this);
618 if (active) stop ();
619 ev_io_set (static_cast<ev_io *>(this), fd, events); 637 ev_io_set (static_cast<ev_io *>(this), fd, events);
620 if (active) start ();
621 } 638 }
622 639
623 void set (int events) EV_NOEXCEPT 640 void set (int events) EV_NOEXCEPT
624 { 641 {
625 int active = is_active (); 642 freeze_guard freeze (this);
626 if (active) stop ();
627 ev_io_set (static_cast<ev_io *>(this), fd, events); 643 ev_io_modify (static_cast<ev_io *>(this), events);
628 if (active) start ();
629 } 644 }
630 645
631 void start (int fd, int events) EV_NOEXCEPT 646 void start (int fd, int events) EV_NOEXCEPT
632 { 647 {
633 set (fd, events); 648 set (fd, events);
636 EV_END_WATCHER (io, io) 651 EV_END_WATCHER (io, io)
637 652
638 EV_BEGIN_WATCHER (timer, timer) 653 EV_BEGIN_WATCHER (timer, timer)
639 void set (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT 654 void set (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT
640 { 655 {
641 int active = is_active (); 656 freeze_guard freeze (this);
642 if (active) stop ();
643 ev_timer_set (static_cast<ev_timer *>(this), after, repeat); 657 ev_timer_set (static_cast<ev_timer *>(this), after, repeat);
644 if (active) start ();
645 } 658 }
646 659
647 void start (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT 660 void start (ev_tstamp after, ev_tstamp repeat = 0.) EV_NOEXCEPT
648 { 661 {
649 set (after, repeat); 662 set (after, repeat);
663 676
664 #if EV_PERIODIC_ENABLE 677 #if EV_PERIODIC_ENABLE
665 EV_BEGIN_WATCHER (periodic, periodic) 678 EV_BEGIN_WATCHER (periodic, periodic)
666 void set (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT 679 void set (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT
667 { 680 {
668 int active = is_active (); 681 freeze_guard freeze (this);
669 if (active) stop ();
670 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0); 682 ev_periodic_set (static_cast<ev_periodic *>(this), at, interval, 0);
671 if (active) start ();
672 } 683 }
673 684
674 void start (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT 685 void start (ev_tstamp at, ev_tstamp interval = 0.) EV_NOEXCEPT
675 { 686 {
676 set (at, interval); 687 set (at, interval);
686 697
687 #if EV_SIGNAL_ENABLE 698 #if EV_SIGNAL_ENABLE
688 EV_BEGIN_WATCHER (sig, signal) 699 EV_BEGIN_WATCHER (sig, signal)
689 void set (int signum) EV_NOEXCEPT 700 void set (int signum) EV_NOEXCEPT
690 { 701 {
691 int active = is_active (); 702 freeze_guard freeze (this);
692 if (active) stop ();
693 ev_signal_set (static_cast<ev_signal *>(this), signum); 703 ev_signal_set (static_cast<ev_signal *>(this), signum);
694 if (active) start ();
695 } 704 }
696 705
697 void start (int signum) EV_NOEXCEPT 706 void start (int signum) EV_NOEXCEPT
698 { 707 {
699 set (signum); 708 set (signum);
704 713
705 #if EV_CHILD_ENABLE 714 #if EV_CHILD_ENABLE
706 EV_BEGIN_WATCHER (child, child) 715 EV_BEGIN_WATCHER (child, child)
707 void set (int pid, int trace = 0) EV_NOEXCEPT 716 void set (int pid, int trace = 0) EV_NOEXCEPT
708 { 717 {
709 int active = is_active (); 718 freeze_guard freeze (this);
710 if (active) stop ();
711 ev_child_set (static_cast<ev_child *>(this), pid, trace); 719 ev_child_set (static_cast<ev_child *>(this), pid, trace);
712 if (active) start ();
713 } 720 }
714 721
715 void start (int pid, int trace = 0) EV_NOEXCEPT 722 void start (int pid, int trace = 0) EV_NOEXCEPT
716 { 723 {
717 set (pid, trace); 724 set (pid, trace);
722 729
723 #if EV_STAT_ENABLE 730 #if EV_STAT_ENABLE
724 EV_BEGIN_WATCHER (stat, stat) 731 EV_BEGIN_WATCHER (stat, stat)
725 void set (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT 732 void set (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT
726 { 733 {
727 int active = is_active (); 734 freeze_guard freeze (this);
728 if (active) stop ();
729 ev_stat_set (static_cast<ev_stat *>(this), path, interval); 735 ev_stat_set (static_cast<ev_stat *>(this), path, interval);
730 if (active) start ();
731 } 736 }
732 737
733 void start (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT 738 void start (const char *path, ev_tstamp interval = 0.) EV_NOEXCEPT
734 { 739 {
735 stop (); 740 stop ();
764 769
765 #if EV_EMBED_ENABLE 770 #if EV_EMBED_ENABLE
766 EV_BEGIN_WATCHER (embed, embed) 771 EV_BEGIN_WATCHER (embed, embed)
767 void set_embed (struct ev_loop *embedded_loop) EV_NOEXCEPT 772 void set_embed (struct ev_loop *embedded_loop) EV_NOEXCEPT
768 { 773 {
769 int active = is_active (); 774 freeze_guard freeze (this);
770 if (active) stop ();
771 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop); 775 ev_embed_set (static_cast<ev_embed *>(this), embedded_loop);
772 if (active) start ();
773 } 776 }
774 777
775 void start (struct ev_loop *embedded_loop) EV_NOEXCEPT 778 void start (struct ev_loop *embedded_loop) EV_NOEXCEPT
776 { 779 {
777 set (embedded_loop); 780 set (embedded_loop);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines