[Openais] [PATCH]: openais/trunk: Add timer data to TMR service

Ryan O'Hara rohara at redhat.com
Mon Feb 16 23:13:51 PST 2009


This is a simple patch to handle timer data. A void pointer is passed
in when the timer is created. The pointer is returned to the caller
when either the timer is cancelled or the timer expires (via the
callback).

-------------- next part --------------
Index: test/testtmr.c
===================================================================
--- test/testtmr.c	(revision 1700)
+++ test/testtmr.c	(working copy)
@@ -96,6 +96,10 @@
 	SaTimeT clock_tick;
 	SaTimeT call_time;
 
+	void *data_a = 0xdeadbeef;
+	void *data_b = 0xdecafbad;
+	void *cancel_data = NULL;
+
 	pthread_t dispatch_thread;
 
 	int result;
@@ -130,7 +134,7 @@
 		printf ("[DEBUG]: clock_tick = %"PRIu64"\n", clock_tick);
 	}
 
-	result = saTmrTimerStart (handle, &attrs_a, NULL, &id_a, &call_time);
+	result = saTmrTimerStart (handle, &attrs_a, data_a, &id_a, &call_time);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerStart\n", result);
 	}
@@ -139,7 +143,7 @@
 		printf ("[DEBUG]:\t callTime = %"PRIu64"\n", call_time);
 	}
 
-	result = saTmrTimerStart (handle, &attrs_b, NULL, &id_b, &call_time);
+	result = saTmrTimerStart (handle, &attrs_b, data_b, &id_b, &call_time);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerStart\n", result);
 	}
@@ -211,11 +215,14 @@
 	/* SLEEP */
 	sleep (30);
 
-	result = saTmrTimerCancel (handle, id_b, NULL);
+	result = saTmrTimerCancel (handle, id_b, &cancel_data);
 	if (result != SA_AIS_OK) {
 		printf ("[ERROR]: (%d) saTmrTimerCancel\n", result);
 		exit (1);
 	}
+	else {
+		printf ("[DEBUG]:\t id=%u data=%p\n", id_b, cancel_data);
+	}
 
 	/* SLEEP */
 	sleep (30);
Index: include/ipc_tmr.h
===================================================================
--- include/ipc_tmr.h	(revision 1700)
+++ include/ipc_tmr.h	(working copy)
@@ -67,6 +67,7 @@
 struct req_lib_tmr_timerstart {
 	mar_req_header_t header;
 	SaTmrTimerAttributesT timer_attributes;
+	void *timer_data;
 };
 
 struct res_lib_tmr_timerstart {
@@ -93,6 +94,7 @@
 
 struct res_lib_tmr_timercancel {
 	mar_res_header_t header;
+	void *timer_data;
 };
 
 struct req_lib_tmr_periodictimerskip {
Index: services/tmr.c
===================================================================
--- services/tmr.c	(revision 1700)
+++ services/tmr.c	(working copy)
@@ -372,7 +372,12 @@
 	}
 
 	timer_instance->timer_id = timer_id;
+	timer_instance->timer_data = req_lib_tmr_timerstart->timer_data;
 
+	/* DEBUG */
+	log_printf (LOG_LEVEL_NOTICE, "[DEBUG]:\t timer_data=%p\n",
+		    (void *)(timer_instance->timer_data));
+
 	memcpy (&timer_instance->timer_attributes,
 		&req_lib_tmr_timerstart->timer_attributes,
 		sizeof (SaTmrTimerAttributesT));
@@ -483,6 +488,8 @@
 		goto error_exit;
 	}
 
+	res_lib_tmr_timercancel.timer_data = timer_instance->timer_data;
+
 	api->timer_delete (timer_instance->timer_handle);
 
 	list_del (&timer_instance->cleanup_list);
Index: lib/tmr.c
===================================================================
--- lib/tmr.c	(revision 1700)
+++ lib/tmr.c	(working copy)
@@ -386,7 +386,8 @@
 	struct res_lib_tmr_timerstart res_lib_tmr_timerstart;
 
 	/* DEBUG */
-	printf ("[DEBUG]: saTmrTimerStart\n");
+	printf ("[DEBUG]: saTmrTimerStart { data=%p }\n",
+		(void *)(timerData));
 
 	if (timerAttributes == NULL) {
 		return (SA_AIS_ERR_INVALID_PARAM);
@@ -397,12 +398,6 @@
 		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);
@@ -416,6 +411,8 @@
 	memcpy (&req_lib_tmr_timerstart.timer_attributes,
 		timerAttributes, sizeof (SaTmrTimerAttributesT));
 
+	req_lib_tmr_timerstart.timer_data = timerData;
+
 	pthread_mutex_lock (&tmrInstance->response_mutex);
 
 	error = saSendReceiveReply (tmrInstance->response_fd,
@@ -535,6 +532,10 @@
 		error = res_lib_tmr_timercancel.header.error;
 	}
 
+	if (error == SA_AIS_OK) {
+		*timerDataP = res_lib_tmr_timercancel.timer_data;
+	}
+
 error_exit:
 	return (error);
 }


More information about the Openais mailing list