1 #include "bcrepeater.h"
8 BC_Repeater::BC_Repeater(BC_WindowBase *top_level, long delay)
12 pause_lock = new Condition(0, "BC_Repeater::pause_lock");
13 startup_lock = new Condition(0, "BC_Repeater::startup_lock");
14 repeat_lock = new Condition(1, "BC_Repeater::repeat_lock");
18 this->top_level = top_level;
22 BC_Repeater::~BC_Repeater()
26 repeat_lock->unlock();
36 void BC_Repeater::initialize()
39 // This is important. It doesn't unblock until the thread is running.
40 startup_lock->lock("BC_Repeater::initialize");
43 int BC_Repeater::start_repeating()
45 //printf("BC_Repeater::start_repeating 1 %d\n", delay);
55 int BC_Repeater::stop_repeating()
57 // Recursive calling happens when mouse wheel is used.
62 if(repeating == 0) pause_lock->lock("BC_Repeater::stop_repeating");
67 void BC_Repeater::run()
69 //printf("BC_Repeater::run 1 %d\n", getpid());
71 Thread::disable_cancel();
72 startup_lock->unlock();
76 Thread::enable_cancel();
77 timer.delay(next_delay);
78 Thread::disable_cancel();
79 //if(next_delay <= 0) printf("BC_Repeater::run delay=%d next_delay=%d\n", delay, next_delay);
81 // Test exit conditions
82 if(interrupted) return;
84 // if(repeating <= 0) continue;
87 pause_lock->lock("BC_Repeater::run");
91 // Test exit conditions
92 if(interrupted) return;
93 if(repeating <= 0) continue;
95 // Wait for existing signal to be processed before sending a new one
96 repeat_lock->lock("BC_Repeater::run");
98 // Test exit conditions
101 repeat_lock->unlock();
106 repeat_lock->unlock();
110 // Wait for window to become available.
111 top_level->lock_window("BC_Repeater::run");
113 // Test exit conditions
116 repeat_lock->unlock();
117 top_level->unlock_window();
122 repeat_lock->unlock();
123 top_level->unlock_window();
127 // Stick event into queue
128 top_level->arm_repeat(delay);
129 top_level->unlock_window();
130 next_delay = delay - timer.get_difference();
131 if(next_delay <= 0) next_delay = 0;
133 // Test exit conditions
136 repeat_lock->unlock();
141 repeat_lock->unlock();