Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/thread/src/mac/periodical.hpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 1.7 KB
Line 
1// (C) Copyright Mac Murrett 2001.
2// Use, modification and distribution are subject to the
3// Boost Software License, Version 1.0. (See accompanying file
4// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6// See http://www.boost.org for most recent version.
7
8#ifndef BOOST_PERIODICAL_MJM012402_HPP
9#define BOOST_PERIODICAL_MJM012402_HPP
10
11
12#include <boost/function.hpp>
13#include <boost/utility.hpp>
14
15
16namespace boost {
17
18namespace threads {
19
20namespace mac {
21
22namespace detail {
23
24
25// class periodical inherits from its template parameter, which should follow the
26//    pattern set by classes dt_scheduler and st_scheduler.  periodical knows how to
27//    call a boost::function, where the xx_scheduler classes only know to to call a
28//    member periodically.
29
30template<class Scheduler>
31class periodical: private noncopyable, private Scheduler
32{
33  public:
34    periodical(function<void> &rFunction);
35    ~periodical();
36
37  public:
38    void start();
39    void stop();
40
41  protected:
42    virtual void periodic_function();
43
44  private:
45    function<void> m_oFunction;
46};
47
48
49template<class Scheduler>
50periodical<Scheduler>::periodical(function<void> &rFunction):
51    m_oFunction(rFunction)
52{
53// no-op
54}
55
56template<class Scheduler>
57periodical<Scheduler>::~periodical()
58{
59    stop();
60}
61
62template<class Scheduler>
63void periodical<Scheduler>::start()
64{
65    start_polling();
66}
67
68template<class Scheduler>
69void periodical<Scheduler>::stop()
70{
71    stop_polling();
72}
73
74
75template<class Scheduler>
76inline void periodical<Scheduler>::periodic_function()
77{
78    try
79    {
80        m_oFunction();
81    }
82    catch(...)
83    {
84    }
85}
86
87
88} // namespace detail
89
90} // namespace mac
91
92} // namespace threads
93
94} // namespace boost
95
96
97#endif // BOOST_PERIODICAL_MJM012402_HPP
Note: See TracBrowser for help on using the repository browser.