release-1.10release-1.7release-1.8release-1.9
Last change
on this file since bad4496 was
c6adf17,
checked in by David Benjamin <davidben@mit.edu>, 14 years ago
|
Track names along with timers, add :show timers
This will help people with BarnOwls eating CPU to diagnose timer leaks.
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | use strict; |
---|
2 | use warnings; |
---|
3 | |
---|
4 | package BarnOwl::MainLoopCompatHook; |
---|
5 | |
---|
6 | use BarnOwl; |
---|
7 | use BarnOwl::Hook; |
---|
8 | use BarnOwl::Timer; |
---|
9 | use Scalar::Util qw(weaken); |
---|
10 | |
---|
11 | sub new { |
---|
12 | my $class = shift; |
---|
13 | my $hook = BarnOwl::Hook->new; |
---|
14 | return bless {hook => $hook}, $class; |
---|
15 | } |
---|
16 | |
---|
17 | sub check_owlconf { |
---|
18 | my $self = shift; |
---|
19 | $self->_ensure_timer() if (*BarnOwl::mainloop_hook{CODE}); |
---|
20 | } |
---|
21 | |
---|
22 | sub run { |
---|
23 | my $self = shift; |
---|
24 | return $self->{hook}->run(@_); |
---|
25 | } |
---|
26 | |
---|
27 | sub add { |
---|
28 | my $self = shift; |
---|
29 | $self->_ensure_timer(); |
---|
30 | $self->{hook}->add(@_); |
---|
31 | } |
---|
32 | |
---|
33 | sub clear { |
---|
34 | my $self = shift; |
---|
35 | $self->_kill_timer() unless *BarnOwl::mainloop_hook{CODE}; |
---|
36 | $self->{hook}->clear(); |
---|
37 | } |
---|
38 | |
---|
39 | sub _ensure_timer { |
---|
40 | my $self = shift; |
---|
41 | BarnOwl::debug("Enabling backwards-compatibility \"main loop\" hook"); |
---|
42 | my $weak = $self; |
---|
43 | weaken($weak); |
---|
44 | unless ($self->{timer}) { |
---|
45 | $self->{timer} = BarnOwl::Timer->new( { |
---|
46 | name => "BarnOwl::MainLoopCompatHook", |
---|
47 | after => 0, |
---|
48 | interval => 1, |
---|
49 | cb => sub { |
---|
50 | $weak->run if $weak; |
---|
51 | BarnOwl::mainloop_hook() if *BarnOwl::mainloop_hook{CODE}; |
---|
52 | }, |
---|
53 | } ); |
---|
54 | } |
---|
55 | } |
---|
56 | |
---|
57 | sub _kill_timer { |
---|
58 | my $self = shift; |
---|
59 | if ($self->{timer}) { |
---|
60 | $self->{timer}->stop; |
---|
61 | undef $self->{timer}; |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | 1; |
---|
Note: See
TracBrowser
for help on using the repository browser.