Просмотр исходного кода

Add timer_expire_time_get
Add timer_expire_time_get corosync API call.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@1761 fd59a12c-fef9-0310-b244-a6a79926bd2f

Ryan O'Hara 17 лет назад
Родитель
Сommit
4e189328ed
5 измененных файлов с 39 добавлено и 1 удалено
  1. 1 0
      exec/apidef.c
  2. 26 0
      exec/timer.c
  3. 2 0
      exec/timer.h
  4. 7 1
      exec/tlist.h
  5. 3 0
      include/corosync/engine/coroapi.h

+ 1 - 0
exec/apidef.c

@@ -72,6 +72,7 @@ static struct corosync_api_v1 apidef_corosync_api_v1 = {
 	.timer_add_absolute = corosync_timer_add_absolute,
 	.timer_delete = corosync_timer_delete,
 	.timer_time_get = corosync_timer_time_get,
+	.timer_expire_time_get = corosync_timer_expire_time_get,
 	.ipc_source_set = message_source_set,
 	.ipc_source_is_local = message_source_is_local,
 	.ipc_private_data_get = cs_conn_private_data_get,

+ 26 - 0
exec/timer.c

@@ -267,3 +267,29 @@ unsigned long long corosync_timer_time_get (void)
 {
 	return (timerlist_nano_from_epoch());
 }
+
+unsigned long long corosync_timer_expire_time_get (
+	timer_handle timer_handle)
+{
+	int unlock;
+	unsigned long long expire;
+
+	if (timer_handle == 0) {
+		return (0);
+	}
+
+	if (pthread_equal (pthread_self(), expiry_thread) != 0) {
+		unlock = 0;
+	} else {
+		unlock = 1;
+		pthread_mutex_lock (&timer_mutex);
+	}
+
+	expire = timerlist_expire_time (&timers_timerlist, timer_handle);
+
+	if (unlock) {
+		pthread_mutex_unlock (&timer_mutex);
+	}
+
+	return (expire);
+}

+ 2 - 0
exec/timer.h

@@ -63,4 +63,6 @@ extern void corosync_timer_unlock (void);
 
 extern unsigned long long corosync_timer_time_get (void);
 
+extern unsigned long long corosync_timer_expire_time_get (corosync_timer_handle timer_handle);
+
 #endif /* TIMER_H_DEFINED */

+ 7 - 1
exec/tlist.h

@@ -172,6 +172,13 @@ static inline void timerlist_del (struct timerlist *timerlist, timer_handle time
 	free (timer);
 }
 
+static inline unsigned long long timerlist_expire_time (struct timerlist *timerlist, timer_handle timer_handle)
+{
+	struct timerlist_timer *timer = (struct timerlist_timer *)timer_handle;
+
+	return (timer->nano_from_epoch);
+}
+
 static inline void timerlist_pre_dispatch (struct timerlist *timerlist, timer_handle timer_handle)
 {
 	struct timerlist_timer *timer = (struct timerlist_timer *)timer_handle;
@@ -215,7 +222,6 @@ static inline unsigned long long timerlist_msec_duration_to_expire (struct timer
 	if (timer_from_list->nano_from_epoch < nano_from_epoch) {
 		return (0);
 	}
-
 	
 	msec_duration_to_expire = ((timer_from_list->nano_from_epoch - nano_from_epoch) / 1000000ULL) +
 		(1000 / HZ);

+ 3 - 0
include/corosync/engine/coroapi.h

@@ -376,6 +376,9 @@ struct corosync_api_v1 {
 
 	unsigned long long (*timer_time_get) (void);
 
+	unsigned long long (*timer_expire_time_get) (
+		corosync_timer_handle_t timer_handle);
+
 	/*
 	 * IPC APIs
 	 */