Beispiel #1
0
void *_ast_register_timing_interface(struct ast_timing_interface *funcs,
				     struct ast_module *mod)
{
	struct timing_holder *h;

	if (!funcs->timer_open ||
	    !funcs->timer_close ||
	    !funcs->timer_set_rate ||
	    !funcs->timer_ack ||
	    !funcs->timer_get_event ||
	    !funcs->timer_get_max_rate ||
	    !funcs->timer_enable_continuous ||
	    !funcs->timer_disable_continuous) {
		return NULL;
	}

	if (!(h = ast_calloc(1, sizeof(*h)))) {
		return NULL;
	}

	h->iface = funcs;
	h->mod = mod;

	ast_heap_wrlock(timing_interfaces);
	ast_heap_push(timing_interfaces, h);
	ast_heap_unlock(timing_interfaces);

	return h;
}
Beispiel #2
0
struct ast_timer *ast_timer_open(void)
{
	int fd = -1;
	struct timing_holder *h;
	struct ast_timer *t = NULL;

	ast_heap_rdlock(timing_interfaces);

	if ((h = ast_heap_peek(timing_interfaces, 1))) {
		fd = h->iface->timer_open();
		ast_module_ref(h->mod);
	}

	if (fd != -1) {
		if (!(t = ast_calloc(1, sizeof(*t)))) {
			h->iface->timer_close(fd);
		} else {
			t->fd = fd;
			t->holder = h;
		}
	}

	ast_heap_unlock(timing_interfaces);

	return t;
}
Beispiel #3
0
struct ast_timer *ast_timer_open(void)
{
	void *data = NULL;
	struct timing_holder *h;
	struct ast_timer *t = NULL;

	ast_heap_rdlock(timing_interfaces);

	if ((h = ast_heap_peek(timing_interfaces, 1))) {
		data = h->iface->timer_open();
		ast_module_ref(h->mod);
	}

	if (data) {
		if (!(t = ast_calloc(1, sizeof(*t)))) {
			h->iface->timer_close(data);
		} else {
			t->data = data;
			t->holder = h;
		}
	}

	ast_heap_unlock(timing_interfaces);

	return t;
}
Beispiel #4
0
int ast_unregister_timing_interface(void *handle)
{
	struct timing_holder *h = handle;
	int res = -1;

	ast_heap_wrlock(timing_interfaces);
	h = ast_heap_remove(timing_interfaces, h);
	ast_heap_unlock(timing_interfaces);

	if (h) {
		ast_free(h);
		h = NULL;
		res = 0;
	}

	return res;
}