[Openais] [PATCH]: openais/trunk: Change timer service to use hdb API

Ryan O'Hara rohara at redhat.com
Fri Feb 13 11:58:42 PST 2009


This patch changes the timer service such that is uses the handle
database api (corosync/hdb.h) so manage timer data structures in the
executive. Previously this was handle by lists. This removes the need
for a timer ID database in the library.


-------------- next part --------------
Index: test/testtmr.c
===================================================================
--- test/testtmr.c	(revision 1697)
+++ test/testtmr.c	(working copy)
@@ -59,9 +59,9 @@
 {
 	/* DEBUG */
 	printf ("[DEBUG]: TimerExpiredCallback\n");
-	printf ("[DEBUG]:\t timerId = %u\n", timerId);
+	printf ("[DEBUG]:\t timerId = %"PRIu64"\n", timerId);
 	printf ("[DEBUG]:\t timerData = %p\n", timerData);
-	printf ("[DEBUG]:\t expirationCount = %u\n", expirationCount);
+	printf ("[DEBUG]:\t expirationCount = %"PRIu64"\n", expirationCount);
 
 	return;
 }
@@ -85,23 +85,21 @@
 {
 	SaTmrHandleT handle;
 	SaSelectionObjectT select_obj;
-	SaTmrTimerAttributesT my_attrs;
-	SaTmrTimerAttributesT attrs_a = { SA_TIME_DURATION, TMR_10_SECONDS, TMR_10_SECONDS };
-	SaTmrTimerAttributesT attrs_b = { SA_TIME_DURATION, TMR_20_SECONDS, TMR_20_SECONDS };
+	SaTmrTimerAttributesT attrs;
+	SaTmrTimerAttributesT attrs_a = { SA_TIME_DURATION, TMR_30_SECONDS, 0 };
+	SaTmrTimerAttributesT attrs_b = { SA_TIME_DURATION, TMR_30_SECONDS, 0 };
+	SaTmrTimerAttributesT new_attrs_a = { SA_TIME_DURATION, TMR_10_SECONDS, TMR_10_SECONDS };
+	SaTmrTimerAttributesT new_attrs_b = { SA_TIME_DURATION, TMR_20_SECONDS, TMR_20_SECONDS };
 	SaTmrTimerIdT id_a;
 	SaTmrTimerIdT id_b;
-	SaTimeT time;
-	SaTimeT current_time_a;
-	SaTimeT current_time_b;
-	SaTimeT delta_time;
+	SaTimeT current_time;
 	SaTimeT clock_tick;
+	SaTimeT call_time;
 
 	pthread_t dispatch_thread;
+
 	int result;
-	int i;
 
-	printf ("[DEBUG]: TMR_10_SECONDS = %"PRId64"\n", TMR_10_SECONDS);
-
 	result = saTmrInitialize (&handle, &callbacks, &version);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrInitialize\n", result);
@@ -116,12 +114,12 @@
 		exit (result);
 	}
 
-	result = saTmrTimeGet (handle, &current_time_a);
+	result = saTmrTimeGet (handle, &current_time);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimeGet\n", result);
 	}
 	else {
-		printf ("[DEBUG]: current_time = %"PRIu64"\n", current_time_a);
+		printf ("[DEBUG]: current_time = %"PRIu64"\n", current_time);
 	}
 
 	result = saTmrClockTickGet (handle, &clock_tick);
@@ -132,129 +130,95 @@
 		printf ("[DEBUG]: clock_tick = %"PRIu64"\n", clock_tick);
 	}
 
-	sleep (10);
-
-	result = saTmrTimeGet (handle, &current_time_b);
+	result = saTmrTimerStart (handle, &attrs_a, NULL, &id_a, &call_time);
 	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimeGet\n", result);
+		printf ("[ERROR]: (%d) saTmrTimerStart\n", result);
 	}
 	else {
-		printf ("[DEBUG]: current_time = %"PRIu64"\n", current_time_b);
+		printf ("[DEBUG]: saTmrTimerStart { id=%u }\n", id_a);
+		printf ("[DEBUG]:\t callTime = %"PRIu64"\n", call_time);
 	}
 
-	delta_time = current_time_b - current_time_a;
-
-	printf ("[DEBUG]: delta_time = %"PRIu64"\n", delta_time);
-
-	result = saTmrTimerStart (handle, &attrs_a, NULL, &id_a, &time);
+	result = saTmrTimerStart (handle, &attrs_b, NULL, &id_b, &call_time);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerStart\n", result);
 	}
 	else {
-		printf ("[DEBUG]: saTmrTimerStart { id=%u }\n", id_a);
-		printf ("[DEBUG]:\t callTime = %"PRIu64"\n", time);
+		printf ("[DEBUG]: saTmrTimerStart { id=%u }\n", id_b);
+		printf ("[DEBUG]:\t callTime = %"PRIu64"\n", call_time);
 	}
 
-	result = saTmrTimerAttributesGet (handle, id_a, &my_attrs);
+	/* SLEEP */
+	sleep (10);
+
+	result = saTmrTimerAttributesGet (handle, id_a, &attrs);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerAttributesGet\n", result);
 	}
 	else {
 		printf ("[DEBUG]: id=%u attributes:\n", id_a);
-		printf ("[DEBUG]:\t type=%"PRId64"\n", my_attrs.type);
-		printf ("[DEBUG]:\t expire=%"PRIi64"\n", my_attrs.initialExpirationTime);
-		printf ("[DEBUG]:\t duration=%"PRIi64"\n", my_attrs.timerPeriodDuration);
+		printf ("[DEBUG]:\t type=%"PRId64"\n", attrs.type);
+		printf ("[DEBUG]:\t expire=%"PRIi64"\n", attrs.initialExpirationTime);
+		printf ("[DEBUG]:\t duration=%"PRIi64"\n", attrs.timerPeriodDuration);
 	}
 
-	result = saTmrTimerStart (handle, &attrs_b, NULL, &id_b, &time);
+	result = saTmrTimerAttributesGet (handle, id_b, &attrs);
 	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerStart\n", result);
+		printf ("[ERROR]: (%d) saTmrTimerAttributesGet\n", result);
 	}
 	else {
-		printf ("[DEBUG]: saTmrTimerStart { id=%u }\n", id_b);
-		printf ("[DEBUG]:\t callTime = %"PRIu64"\n", time);
+		printf ("[DEBUG]: id=%u attributes:\n", id_b);
+		printf ("[DEBUG]:\t type=%"PRId64"\n", attrs.type);
+		printf ("[DEBUG]:\t expire=%"PRIi64"\n", attrs.initialExpirationTime);
+		printf ("[DEBUG]:\t duration=%"PRIi64"\n", attrs.timerPeriodDuration);
 	}
 
-	result = saTmrTimerAttributesGet (handle, id_a, &my_attrs);
+	/* SLEEP */
+	sleep (10);
+
+	result = saTmrTimerReschedule (handle, id_a, &new_attrs_a, &time);
 	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerAttributesGet\n", result);
+		printf ("[ERROR]: (%d) saTmrTimerReschedule\n", result);
 	}
-	else {
-		printf ("[DEBUG]: id=%u attributes:\n", id_a);
-		printf ("[DEBUG]:\t type=%"PRId64"\n", my_attrs.type);
-		printf ("[DEBUG]:\t expire=%"PRId64"\n", my_attrs.initialExpirationTime);
-		printf ("[DEBUG]:\t duration=%"PRId64"\n", my_attrs.timerPeriodDuration);
-	}
 
-	result = saTmrTimerReschedule (handle, id_a, &attrs_a, &time);
+	result = saTmrTimerReschedule (handle, id_b, &new_attrs_b, &time);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerReschedule\n", result);
 	}
 
-	result = saTmrTimerAttributesGet (handle, id_a, &my_attrs);
+	result = saTmrTimerAttributesGet (handle, id_a, &attrs);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerAttributesGet\n", result);
 	}
 	else {
 		printf ("[DEBUG]: id=%u attributes:\n", id_a);
-		printf ("[DEBUG]:\t type=%"PRId64"\n", my_attrs.type);
-		printf ("[DEBUG]:\t expire=%"PRId64"\n", my_attrs.initialExpirationTime);
-		printf ("[DEBUG]:\t duration=%"PRId64"\n", my_attrs.timerPeriodDuration);
+		printf ("[DEBUG]:\t type=%"PRId64"\n", attrs.type);
+		printf ("[DEBUG]:\t expire=%"PRIi64"\n", attrs.initialExpirationTime);
+		printf ("[DEBUG]:\t duration=%"PRIi64"\n", attrs.timerPeriodDuration);
 	}
 
-	result = saTmrTimerReschedule (handle, id_b, &attrs_b, &time);
+	result = saTmrTimerAttributesGet (handle, id_b, &attrs);
 	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerReschedule\n", result);
-	}
-
-	result = saTmrTimerAttributesGet (handle, id_a, &my_attrs);
-	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerAttributesGet\n", result);
 	}
 	else {
-		printf ("[DEBUG]: id=%u attributes:\n", id_a);
-		printf ("[DEBUG]:\t type=%"PRId64"\n", my_attrs.type);
-		printf ("[DEBUG]:\t expire=%"PRId64"\n", my_attrs.initialExpirationTime);
-		printf ("[DEBUG]:\t duration=%"PRId64"\n", my_attrs.timerPeriodDuration);
+		printf ("[DEBUG]: id=%u attributes:\n", id_b);
+		printf ("[DEBUG]:\t type=%"PRId64"\n", attrs.type);
+		printf ("[DEBUG]:\t expire=%"PRIi64"\n", attrs.initialExpirationTime);
+		printf ("[DEBUG]:\t duration=%"PRIi64"\n", attrs.timerPeriodDuration);
 	}
 
+	/* SLEEP */
 	sleep (30);
 
-	result = saTmrPeriodicTimerSkip (handle, id_a);
-	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrPeriodicTimerSkip\n", result);
-	}
-
-	sleep (60);
-
-	for (i = 0; i < 4; i++) {
-		result = saTmrPeriodicTimerSkip (handle, id_a);
-		if (result != SA_AIS_OK) {
-			printf ("[ERROR]: (%d) saTmrPeriodicTimerSkip\n", result);
-		}
-	}
-
-	sleep (120);
-
-	result = saTmrTimerCancel (handle, id_a, NULL);
-	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerCancel\n", result);
-	}
-
-	result = saTmrTimerReschedule (handle, id_a, &attrs_a, &time);
-	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerReschedule\n", result);
-	}
-
 	result = saTmrTimerCancel (handle, id_b, NULL);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerCancel\n", result);
+		exit (1);
 	}
 
-	result = saTmrTimerReschedule (handle, id_b, &attrs_b, &time);
-	if (result != SA_AIS_OK) {
-		printf ("[ERROR]: (%d) saTmrTimerReschedule\n", result);
-	}
+	/* SLEEP */
+	sleep (30);
 
 	result = saTmrFinalize (handle);
 	if (result != SA_AIS_OK) {
Index: include/ipc_tmr.h
===================================================================
--- include/ipc_tmr.h	(revision 1697)
+++ include/ipc_tmr.h	(working copy)
@@ -66,14 +66,13 @@
 
 struct req_lib_tmr_timerstart {
 	mar_req_header_t header;
-	SaTmrTimerIdT timer_id;
 	SaTmrTimerAttributesT timer_attributes;
-	SaTimeT call_time;
 };
 
 struct res_lib_tmr_timerstart {
 	mar_res_header_t header;
 	SaTmrTimerIdT timer_id;
+	SaTimeT call_time;
 };
 
 struct req_lib_tmr_timerreschedule {
@@ -150,8 +149,8 @@
 struct res_lib_tmr_timerexpiredcallback {
 	mar_res_header_t header;
 	SaTmrTimerIdT timer_id;
-	void *timer_data;
 	SaUint64T expiration_count;
+	void *timer_data;
 };
 
 #endif /* IPC_TMR_H_DEFINED  */
Index: services/tmr.c
===================================================================
--- services/tmr.c	(revision 1697)
+++ services/tmr.c	(working copy)
@@ -47,12 +47,11 @@
 #include <time.h>
 #include <arpa/inet.h>
 
-#include <inttypes.h> /* for development only */
-
 #include <corosync/ipc_gen.h>
 #include <corosync/mar_gen.h>
 #include <corosync/swab.h>
 #include <corosync/list.h>
+#include <corosync/hdb.h>
 #include <corosync/engine/coroapi.h>
 #include <corosync/engine/logsys.h>
 #include <corosync/lcr/lcr_comp.h>
@@ -63,19 +62,24 @@
 
 LOGSYS_DECLARE_SUBSYS ("TMR", LOG_INFO);
 
-struct timer {
+struct timer_instance {
 	SaTmrTimerIdT timer_id;
 	SaTmrTimerAttributesT timer_attributes;
-	corosync_timer_handle_t timer_handle;
-	mar_message_source_t source;
 	SaUint64T expiration_count;
 	SaUint64T timer_skip;
 	SaTimeT call_time;
+	corosync_timer_handle_t timer_handle;
+	mar_message_source_t source;
 	void *timer_data;
-	struct list_head list;
+	struct list_head cleanup_list;
 };
 
-DECLARE_LIST_INIT(timer_list_head);
+static struct hdb_handle_database timer_hdb = {
+	.handle_count	= 0,
+	.handles	= 0,
+	.iterator	= 0,
+	.mutex		= PTHREAD_MUTEX_INITIALIZER
+};
 
 static struct corosync_api_v1 *api;
 
@@ -238,16 +242,40 @@
 
 static int tmr_lib_init_fn (void *conn)
 {
+	struct tmr_pd *tmr_pd = (struct tmr_pd *) api->ipc_private_data_get (conn);
+
+	list_init (&tmr_pd->timer_list);
+	list_init (&tmr_pd->timer_cleanup_list);
+
 	return (0);
 }
 
 static int tmr_lib_exit_fn (void *conn)
 {
+	struct timer_instance *timer_instance;
+	struct list_head *cleanup_list;
 	struct tmr_pd *tmr_pd = (struct tmr_pd *) api->ipc_private_data_get (conn);
 
-	list_init (&tmr_pd->timer_list);
-	list_init (&tmr_pd->timer_cleanup_list);
+	cleanup_list = tmr_pd->timer_cleanup_list.next;
 
+	while (!list_empty (&tmr_pd->timer_cleanup_list))
+	{
+		timer_instance = list_entry (cleanup_list, struct timer_instance, cleanup_list);
+
+		/* DEBUG */
+		log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: cleanup timer { id=%u }\n",
+			    (unsigned int)(timer_instance->timer_id));
+
+		api->timer_delete (timer_instance->timer_handle);
+
+		list_del (&timer_instance->cleanup_list);
+
+		hdb_handle_destroy (&timer_hdb, timer_instance->timer_id);
+		hdb_handle_put (&timer_hdb, timer_instance->timer_id);
+
+		cleanup_list = tmr_pd->timer_cleanup_list.next;
+	}
+
 	return (0);
 }
 
@@ -263,22 +291,19 @@
 	time = (SaTimeT)(tv.tv_sec) * 1000000000ULL;
 	time += (SaTimeT)(tv.tv_usec) * 1000ULL;
 
-	/* DEBUG */
-	log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: tmr_time_now %"PRIu64"\n", time);
-
 	return (time);
 }
 
 static void tmr_timer_expired (void *data)
 {
-	struct timer *timer = (struct timer *)data;
+	struct timer_instance *timer_instance = (struct timer_instance *)data;
 	struct res_lib_tmr_timerexpiredcallback res_lib_tmr_timerexpiredcallback;
 
-	timer->expiration_count += 1;
+	timer_instance->expiration_count += 1;
 
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: tmr_timer_expired { id=%u }\n",
-		    (unsigned int)(timer->timer_id));
+		    (unsigned int)(timer_instance->timer_id));
 
 	res_lib_tmr_timerexpiredcallback.header.size =
 		sizeof (struct res_lib_tmr_timerexpiredcallback);
@@ -286,37 +311,42 @@
 		MESSAGE_RES_TMR_TIMEREXPIREDCALLBACK;
 	res_lib_tmr_timerexpiredcallback.header.error = SA_AIS_OK; /* FIXME */
 
-	res_lib_tmr_timerexpiredcallback.timer_id = timer->timer_id;
-	res_lib_tmr_timerexpiredcallback.timer_data = timer->timer_data;
-	res_lib_tmr_timerexpiredcallback.expiration_count = timer->expiration_count;
+	res_lib_tmr_timerexpiredcallback.timer_id = timer_instance->timer_id;
+	res_lib_tmr_timerexpiredcallback.timer_data = timer_instance->timer_data;
+	res_lib_tmr_timerexpiredcallback.expiration_count = timer_instance->expiration_count;
 
-	if (timer->timer_skip == 0) {
+	if (timer_instance->timer_skip == 0) {
 		api->ipc_conn_send_response (
-			api->ipc_conn_partner_get (timer->source.conn),
+			api->ipc_conn_partner_get (timer_instance->source.conn),
 			&res_lib_tmr_timerexpiredcallback,
 			sizeof (struct res_lib_tmr_timerexpiredcallback));
 	}
 	else {
 		/* DEBUG */
 		log_printf (LOG_LEVEL_NOTICE, "[DEBUG]: skipping timer { id=%u }\n",
-			    (unsigned int)(timer->timer_id));
+			    (unsigned int)(timer_instance->timer_id));
 
-		timer->timer_skip -= 1;
+		timer_instance->timer_skip -= 1;
 	}
 
-	if (timer->timer_attributes.timerPeriodDuration > 0) {
-		switch (timer->timer_attributes.type) {
+	if (timer_instance->timer_attributes.timerPeriodDuration > 0) {
+		switch (timer_instance->timer_attributes.type) {
+		/*
+		 * We don't really need a switch statement here,
+		 * since periodic timers will always get recreated
+		 * as duration timers.
+		 */
 		case SA_TIME_ABSOLUTE:
 			api->timer_add_absolute (
-				timer->timer_attributes.timerPeriodDuration,
-				(void *)(timer), tmr_timer_expired,
-				&timer->timer_handle);
+				timer_instance->timer_attributes.timerPeriodDuration,
+				(void *)(timer_instance), tmr_timer_expired,
+				&timer_instance->timer_handle);
 			break;
 		case SA_TIME_DURATION:
 			api->timer_add_duration (
-				timer->timer_attributes.timerPeriodDuration,
-				(void *)(timer), tmr_timer_expired,
-				&timer->timer_handle);
+				timer_instance->timer_attributes.timerPeriodDuration,
+				(void *)(timer_instance), tmr_timer_expired,
+				&timer_instance->timer_handle);
 			break;
 		default:
 			break;
@@ -326,24 +356,6 @@
 	return;
 }
 
-static struct timer *tmr_find_timer (
-	struct list_head *head,
-	SaTmrTimerIdT timer_id)
-{
-	struct list_head *list;
-	struct timer *timer;
-
-	for (list = head->next; list != head; list = list->next)
-	{
-		timer = list_entry (list, struct timer, list);
-
-		if (timer->timer_id == timer_id) {
-			return (timer);
-		}
-	}
-	return (0);
-}
-
 static void message_handler_req_lib_tmr_timerstart (
 	void *conn,
 	void *msg)
@@ -351,57 +363,60 @@
 	struct req_lib_tmr_timerstart *req_lib_tmr_timerstart =
 		(struct req_lib_tmr_timerstart *)msg;
 	struct res_lib_tmr_timerstart res_lib_tmr_timerstart;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
+	unsigned int timer_id;
+	struct tmr_pd *tmr_pd = (struct tmr_pd *) api->ipc_private_data_get (conn);
+
 	/* DEBUG */
-	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerStart { id=%u }\n",
-		    (unsigned int)(req_lib_tmr_timerstart->timer_id));
+	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerStart\n");
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_timerstart->timer_id);
-	if (timer == NULL) {
-		timer = malloc (sizeof (struct timer));
-		if (timer == NULL) {
-			error = SA_AIS_ERR_NO_MEMORY;
-			goto error_exit;
-		}
-		memset (timer, 0, sizeof (struct timer));
+	hdb_handle_create (&timer_hdb,
+		   sizeof (struct timer_instance),
+		   &timer_id);
 
-		timer->timer_id = req_lib_tmr_timerstart->timer_id;
-		timer->call_time = req_lib_tmr_timerstart->call_time;
+	hdb_handle_get (&timer_hdb, timer_id,
+		(void *)&timer_instance);
 
-		memcpy (&timer->timer_attributes,
-			&req_lib_tmr_timerstart->timer_attributes,
-			sizeof (SaTmrTimerAttributesT));
+	if (timer_instance == NULL) {
+		error = SA_AIS_ERR_NO_MEMORY;
+		goto error_exit;
+	}
 
-		api->ipc_source_set (&timer->source, conn);
+	timer_instance->timer_id = timer_id;
 
-		list_init (&timer->list);
-		list_add (&timer->list, &timer_list_head);
+	memcpy (&timer_instance->timer_attributes,
+		&req_lib_tmr_timerstart->timer_attributes,
+		sizeof (SaTmrTimerAttributesT));
 
-		switch (timer->timer_attributes.type)
-		{
-		case SA_TIME_ABSOLUTE:
-			api->timer_add_absolute (
-				timer->timer_attributes.initialExpirationTime,
-				(void *)(timer), tmr_timer_expired,
-				&timer->timer_handle);
-			break;
-		case SA_TIME_DURATION:
-			api->timer_add_duration (
-				timer->timer_attributes.initialExpirationTime,
-				(void *)(timer), tmr_timer_expired,
-				&timer->timer_handle);
-			break;
-		default:
-			/*
-			 * This case is handled in the library.
-			 */
-			break;
-		}
+	api->ipc_source_set (&timer_instance->source, conn);
+
+	list_init (&timer_instance->cleanup_list);
+
+	switch (timer_instance->timer_attributes.type)
+	{
+	case SA_TIME_ABSOLUTE:
+		api->timer_add_absolute (
+			timer_instance->timer_attributes.initialExpirationTime,
+			(void *)(timer_instance), tmr_timer_expired,
+			&timer_instance->timer_handle);
+		break;
+	case SA_TIME_DURATION:
+		api->timer_add_duration (
+			timer_instance->timer_attributes.initialExpirationTime,
+			(void *)(timer_instance), tmr_timer_expired,
+			&timer_instance->timer_handle);
+		break;
+	default:
+		/*
+		 * This case is handled in the library.
+		 */
+		break;
 	}
 
+	list_add (&timer_instance->cleanup_list, &tmr_pd->timer_cleanup_list);
+
 error_exit:
 
 	res_lib_tmr_timerstart.header.size =
@@ -410,6 +425,9 @@
 		MESSAGE_RES_TMR_TIMERSTART;
 	res_lib_tmr_timerstart.header.error = error;
 
+	res_lib_tmr_timerstart.timer_id = timer_id;
+	res_lib_tmr_timerstart.call_time = tmr_time_now (); /* FIXME */
+
 	api->ipc_conn_send_response (conn,
 		&res_lib_tmr_timerstart,
 		sizeof (struct res_lib_tmr_timerstart));
@@ -422,24 +440,27 @@
 	struct req_lib_tmr_timerreschedule *req_lib_tmr_timerreschedule =
 		(struct req_lib_tmr_timerreschedule *)msg;
 	struct res_lib_tmr_timerreschedule res_lib_tmr_timerreschedule;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerReschedule { id=%u }\n",
 		    (unsigned int)(req_lib_tmr_timerreschedule->timer_id));
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_timerreschedule->timer_id);
-	if (timer == NULL) {
+	hdb_handle_get (&timer_hdb,
+		(unsigned int)(req_lib_tmr_timerreschedule->timer_id),
+		(void *)&timer_instance);
+	if (timer_instance == NULL) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
-	memcpy (&timer->timer_attributes,
+	memcpy (&timer_instance->timer_attributes,
 		&req_lib_tmr_timerreschedule->timer_attributes,
 		sizeof (SaTmrTimerAttributesT));
 
+	hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+
 error_exit:
 
 	res_lib_tmr_timerreschedule.header.size =
@@ -460,23 +481,28 @@
 	struct req_lib_tmr_timercancel *req_lib_tmr_timercancel =
 		(struct req_lib_tmr_timercancel *)msg;
 	struct res_lib_tmr_timercancel res_lib_tmr_timercancel;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
 	/* DEBUG */
-	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerCancel\n");
+	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerCancel { id=%u }\n",
+		    (unsigned int)(req_lib_tmr_timercancel->timer_id));
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_timercancel->timer_id);
-	if (timer == NULL) {
+	hdb_handle_get (&timer_hdb,
+		(unsigned int)(req_lib_tmr_timercancel->timer_id),
+		(void *)&timer_instance);
+	if (timer_instance == NULL) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
-	api->timer_delete (timer->timer_handle);
-	list_del (&timer->list);
-	free (timer);
+	api->timer_delete (timer_instance->timer_handle);
 
+	list_del (&timer_instance->cleanup_list);
+
+	hdb_handle_destroy (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+	hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+
 error_exit:
 
 	res_lib_tmr_timercancel.header.size =
@@ -497,27 +523,30 @@
 	struct req_lib_tmr_periodictimerskip *req_lib_tmr_periodictimerskip =
 		(struct req_lib_tmr_periodictimerskip *)msg;
 	struct res_lib_tmr_periodictimerskip res_lib_tmr_periodictimerskip;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrPeriodicTimerSkip { id=%u }\n",
 		    (unsigned int)(req_lib_tmr_periodictimerskip->timer_id));
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_periodictimerskip->timer_id);
-	if (timer == NULL) {
+	hdb_handle_get (&timer_hdb,
+		(unsigned int)(req_lib_tmr_periodictimerskip->timer_id),
+		(void *)&timer_instance);
+	if (timer_instance == NULL) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
-	if (timer->timer_attributes.timerPeriodDuration == 0) {
+	if (timer_instance->timer_attributes.timerPeriodDuration == 0) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
-	timer->timer_skip += 1;
+	timer_instance->timer_skip += 1;
 
+	hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+
 error_exit:
 
 	res_lib_tmr_periodictimerskip.header.size =
@@ -538,20 +567,23 @@
 	struct req_lib_tmr_timerremainingtimeget *req_lib_tmr_timerremainingtimeget =
 		(struct req_lib_tmr_timerremainingtimeget *)msg;
 	struct res_lib_tmr_timerremainingtimeget res_lib_tmr_timerremainingtimeget;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerRemainingTimeGet { id=%u }\n",
 		    (unsigned int)(req_lib_tmr_timerremainingtimeget->timer_id));
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_timerremainingtimeget->timer_id);
-	if (timer == NULL) {
+	hdb_handle_get (&timer_hdb,
+		(unsigned int)(req_lib_tmr_timerremainingtimeget->timer_id),
+		(void *)&timer_instance);
+	if (timer_instance == NULL) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
+	hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+
 error_exit:
 
 	res_lib_tmr_timerremainingtimeget.header.size =
@@ -572,23 +604,27 @@
 	struct req_lib_tmr_timerattributesget *req_lib_tmr_timerattributesget =
 		(struct req_lib_tmr_timerattributesget *)msg;
 	struct res_lib_tmr_timerattributesget res_lib_tmr_timerattributesget;
+	struct timer_instance *timer_instance = NULL;
 	SaAisErrorT error = SA_AIS_OK;
-	struct timer *timer = NULL;
 
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimerAttributesGet { id=%u }\n",
 		    (unsigned int)(req_lib_tmr_timerattributesget->timer_id));
 
-	timer = tmr_find_timer (&timer_list_head,
-		req_lib_tmr_timerattributesget->timer_id);
-	if (timer == NULL) {
+	hdb_handle_get (&timer_hdb,
+		(unsigned int)(req_lib_tmr_timerattributesget->timer_id),
+		(void *)&timer_instance);
+	if (timer_instance == NULL) {
 		error = SA_AIS_ERR_NOT_EXIST;
 		goto error_exit;
 	}
 
 	memcpy (&res_lib_tmr_timerattributesget.timer_attributes,
-		&timer->timer_attributes, sizeof (SaTmrTimerAttributesT));
+		&timer_instance->timer_attributes,
+		sizeof (SaTmrTimerAttributesT));
 
+	hdb_handle_put (&timer_hdb, (unsigned int)(timer_instance->timer_id));
+
 error_exit:
 
 	res_lib_tmr_timerattributesget.header.size =
@@ -615,6 +651,9 @@
 	/* DEBUG */
 	log_printf (LOG_LEVEL_NOTICE, "LIB request: saTmrTimeGet\n");
 
+	/*
+	 * Use api->timer_time_get();
+	 */
 	current_time = tmr_time_now();
 
 	memcpy (&res_lib_tmr_timeget.current_time,
Index: lib/tmr.c
===================================================================
--- lib/tmr.c	(revision 1697)
+++ lib/tmr.c	(working copy)
@@ -71,21 +71,8 @@
 	pthread_mutex_t dispatch_mutex;
 };
 
-struct tmrTimerIdInstance {
-	int response_fd;
-	int dispatch_fd;
-	SaTmrHandleT tmrHandle;
-	struct list_head list;
-	void *timer_lock;
-	pthread_mutex_t *response_mutex;
-	pthread_mutex_t *dispatch_mutex;
-};
-
 void tmrHandleInstanceDestructor (void *instance);
-void tmrTimerIdHandleInstanceDestructor (void *instance);
 
-static SaTimeT tmrGetTimeNow (void);
-
 static struct saHandleDatabase tmrHandleDatabase = {
 	.handleCount			= 0,
 	.handles			= 0,
@@ -93,13 +80,6 @@
 	.handleInstanceDestructor	= tmrHandleInstanceDestructor
 };
 
-static struct saHandleDatabase tmrTimerIdHandleDatabase = {
-	.handleCount			= 0,
-	.handles			= 0,
-	.mutex				= PTHREAD_MUTEX_INITIALIZER,
-	.handleInstanceDestructor	= tmrTimerIdHandleInstanceDestructor
-};
-
 static SaVersionT tmrVersionsSupported[] = {
 	{ 'A', 1, 1 }
 };
@@ -117,11 +97,6 @@
 	pthread_mutex_destroy (&tmrInstance->dispatch_mutex);
 }
 
-void tmrTimerIdHandleInstanceDestructor (void *instance)
-{
-	return;
-}
-
 #ifdef COMPILE_OUT
 static void tmrInstanceFinalize (struct tmrInstance *tmrInstance)
 {
@@ -405,7 +380,6 @@
 	SaTimeT *callTime)
 {
 	struct tmrInstance *tmrInstance;
-	struct tmrTimerIdInstance *tmrTimerIdInstance;
 	SaAisErrorT error = SA_AIS_OK;
 
 	struct req_lib_tmr_timerstart req_lib_tmr_timerstart;
@@ -434,32 +408,11 @@
 		return (error);
 	}
 
-	error = saHandleCreate (&tmrTimerIdHandleDatabase,
-		sizeof (struct tmrTimerIdInstance), timerId);
-	if (error != SA_AIS_OK) {
-		goto error_exit;
-	}
-
-	error = saHandleInstanceGet (&tmrTimerIdHandleDatabase, *timerId,
-		(void *)&tmrTimerIdInstance);
-	if (error != SA_AIS_OK) {
-		goto error_destroy;
-	}
-
-	*callTime = tmrGetTimeNow ();
-
-	tmrTimerIdInstance->response_fd = tmrInstance->response_fd;
-	tmrTimerIdInstance->response_mutex = &tmrInstance->response_mutex;
-	tmrTimerIdInstance->tmrHandle = tmrHandle;
-
 	req_lib_tmr_timerstart.header.size =
 		sizeof (struct req_lib_tmr_timerstart);
 	req_lib_tmr_timerstart.header.id =
 		MESSAGE_REQ_TMR_TIMERSTART;
 
-	req_lib_tmr_timerstart.timer_id = *timerId;
-	req_lib_tmr_timerstart.call_time = *callTime;
-
 	memcpy (&req_lib_tmr_timerstart.timer_attributes,
 		timerAttributes, sizeof (SaTmrTimerAttributesT));
 
@@ -473,13 +426,13 @@
 
 	pthread_mutex_unlock (&tmrInstance->response_mutex);
 
+	*timerId = (SaTmrTimerIdT)(res_lib_tmr_timerstart.timer_id);
+	*callTime = (SaTimeT)(res_lib_tmr_timerstart.call_time);
+
 	if (res_lib_tmr_timerstart.header.error != SA_AIS_OK) {
 		error = res_lib_tmr_timerstart.header.error;
 	}
 
-error_destroy:
-	saHandleDestroy (&tmrTimerIdHandleDatabase, *timerId);
-
 error_exit:
 	saHandleInstancePut (&tmrHandleDatabase, tmrHandle);
 	return (error);;
@@ -499,18 +452,13 @@
 	struct res_lib_tmr_timerreschedule res_lib_tmr_timerreschedule;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTmrTimerReschedule\n");
+	printf ("[DEBUG]: saTmrTimerReschedule { id=%u }\n",
+		(unsigned int)(timerId));
 
 	if (timerAttributes == NULL) {
 		return (SA_AIS_ERR_INVALID_PARAM);
 	}
 
-	/* DEBUG */
-	printf ("[DEBUG]:\t type=%d expire=%"PRId64" duration=%"PRId64"\n",
-		timerAttributes->type,
-		timerAttributes->initialExpirationTime,
-		timerAttributes->timerPeriodDuration);
-
 	error = saHandleInstanceGet (&tmrHandleDatabase, tmrHandle, (void *)&tmrInstance);
 	if (error != SA_AIS_OK) {
 		return (error);
@@ -558,7 +506,8 @@
 	struct res_lib_tmr_timercancel res_lib_tmr_timercancel;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTmrTimerCancel\n");
+	printf ("[DEBUG]: saTmrTimerCancel { id=%u }\n",
+		(unsigned int)(timerId));
 
 	error = saHandleInstanceGet (&tmrHandleDatabase, tmrHandle, (void *)&tmrInstance);
 	if (error != SA_AIS_OK) {
@@ -602,7 +551,8 @@
 	struct res_lib_tmr_periodictimerskip res_lib_tmr_periodictimerskip;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTmrPeriodicTimerSkip\n");
+	printf ("[DEBUG]: saTmrPeriodicTimerSkip { id=%u }\n",
+		(unsigned int)(timerId));
 
 	error = saHandleInstanceGet (&tmrHandleDatabase, tmrHandle, (void *)&tmrInstance);
 	if (error != SA_AIS_OK) {
@@ -646,7 +596,8 @@
 	struct res_lib_tmr_timerremainingtimeget res_lib_tmr_timerremainingtimeget;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTimerRemainingTimeGet\n");
+	printf ("[DEBUG]: saTimerRemainingTimeGet { id=%u }\n",
+		(unsigned int)(timerId));
 
 	if (remainingTime == NULL) {
 		error = SA_AIS_ERR_INVALID_PARAM;
@@ -696,7 +647,8 @@
 	struct res_lib_tmr_timerattributesget res_lib_tmr_timerattributesget;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTmrTimerAttributesGet\n");
+	printf ("[DEBUG]: saTmrTimerAttributesGet { id=%u }\n",
+		(unsigned int)(timerId));
 
 	if (timerAttributes == NULL) {
 		error = SA_AIS_ERR_INVALID_PARAM;
@@ -835,18 +787,3 @@
 error_exit:
 	return (error);
 }
-
-static SaTimeT tmrGetTimeNow (void)
-{
-	struct timeval tv;
-	SaTimeT time;
-
-	if (gettimeofday (&tv, 0)) {
-		return (0ULL);
-	}
-
-	time = (SaTimeT)(tv.tv_sec) *  1000000000ULL;
-	time += (SaTimeT)(tv.tv_usec) * 1000ULL;
-
-	return (time);
-}


More information about the Openais mailing list