summaryrefslogtreecommitdiff
path: root/mblock/src/lib/mb_timer_queue.cc
blob: 1293e8a4cc3f18dcab454c12f8211333f0eaf336 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* -*- c++ -*- */
/*
 * Copyright 2007 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <mb_timer_queue.h>

static pmt_t
make_handle()
{
  static long counter = 0;
  pmt_t n = pmt_from_long(counter++);
  return pmt_list1(n);		// guaranteed to be a unique object
}

// one-shot constructor
mb_timeout::mb_timeout(const mb_time &abs_time,
		       pmt_t user_data, mb_msg_accepter_sptr accepter)
  : d_when(abs_time), d_is_periodic(false),
    d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter)
{
}

// periodic constructor
mb_timeout::mb_timeout(const mb_time &first_abs_time, const mb_time &delta_time,
		       pmt_t user_data, mb_msg_accepter_sptr accepter)
  : d_when(first_abs_time), d_delta(delta_time), d_is_periodic(true),
    d_user_data(user_data), d_handle(make_handle()), d_accepter(accepter)
{
}

void
mb_timer_queue::cancel(pmt_t handle)
{
  container_type::iterator it;

  for (it = c.begin(); it != c.end();){
    if (pmt_equal((*it)->handle(), handle))
      it = c.erase(it);
    else
      ++it;
  }
  std::make_heap(c.begin(), c.end(), comp);
}