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 | #include "st_scheduler.hpp" |
---|
9 | |
---|
10 | #include <cassert> |
---|
11 | |
---|
12 | |
---|
13 | namespace boost { |
---|
14 | |
---|
15 | namespace threads { |
---|
16 | |
---|
17 | namespace mac { |
---|
18 | |
---|
19 | namespace detail { |
---|
20 | |
---|
21 | |
---|
22 | #if TARGET_CARBON |
---|
23 | |
---|
24 | st_scheduler::st_scheduler(): |
---|
25 | m_uppTask(NULL), |
---|
26 | m_pTimer(NULL) |
---|
27 | { |
---|
28 | m_uppTask = NewEventLoopTimerUPP(task_entry); |
---|
29 | // TODO - throw on error |
---|
30 | assert(m_uppTask != NULL); |
---|
31 | } |
---|
32 | |
---|
33 | st_scheduler::~st_scheduler() |
---|
34 | { |
---|
35 | DisposeEventLoopTimerUPP(m_uppTask); |
---|
36 | m_uppTask = NULL; |
---|
37 | } |
---|
38 | |
---|
39 | |
---|
40 | void st_scheduler::start_polling() |
---|
41 | { |
---|
42 | assert(m_pTimer == NULL); |
---|
43 | OSStatus lStatus = InstallEventLoopTimer(GetMainEventLoop(), |
---|
44 | 0 * kEventDurationSecond, |
---|
45 | kEventDurationMillisecond, |
---|
46 | m_uppTask, |
---|
47 | this, |
---|
48 | &m_pTimer); |
---|
49 | // TODO - throw on error |
---|
50 | assert(lStatus == noErr); |
---|
51 | } |
---|
52 | |
---|
53 | void st_scheduler::stop_polling() |
---|
54 | { |
---|
55 | assert(m_pTimer != NULL); |
---|
56 | OSStatus lStatus = RemoveEventLoopTimer(m_pTimer); |
---|
57 | assert(lStatus == noErr); |
---|
58 | m_pTimer = NULL; |
---|
59 | } |
---|
60 | |
---|
61 | |
---|
62 | /*static*/ pascal void st_scheduler::task_entry(EventLoopTimerRef /*pTimer*/, void *pRefCon) |
---|
63 | { |
---|
64 | st_scheduler *pThis = reinterpret_cast<st_scheduler *>(pRefCon); |
---|
65 | assert(pThis != NULL); |
---|
66 | pThis->task(); |
---|
67 | } |
---|
68 | |
---|
69 | void st_scheduler::task() |
---|
70 | { |
---|
71 | periodic_function(); |
---|
72 | } |
---|
73 | |
---|
74 | #else |
---|
75 | # error st_scheduler unimplemented! |
---|
76 | #endif |
---|
77 | |
---|
78 | |
---|
79 | } // namespace detail |
---|
80 | |
---|
81 | } // namespace mac |
---|
82 | |
---|
83 | } // namespace threads |
---|
84 | |
---|
85 | } // namespace boost |
---|