Jelajahi Sumber

Merge trunk revision 2649:

r2649 | honzaf | 2010-01-22 02:45:29 -0700 (Fri, 22 Jan 2010) | 5 lines

Add schedwrk_create_nolock function

This patch adds schedwrk_create_nolock, which will not call
serialize_lock before execution of callback.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2696 fd59a12c-fef9-0310-b244-a6a79926bd2f
Steven Dake 16 tahun lalu
induk
melakukan
a37cbb6719
4 mengubah file dengan 41 tambahan dan 7 penghapusan
  1. 1 0
      exec/apidef.c
  2. 27 4
      exec/schedwrk.c
  3. 8 3
      exec/schedwrk.h
  4. 5 0
      include/corosync/engine/coroapi.h

+ 1 - 0
exec/apidef.c

@@ -129,6 +129,7 @@ static struct corosync_api_v1 apidef_corosync_api_v1 = {
 	.tpg_groups_reserve = NULL,
 	.tpg_groups_release = NULL,
 	.schedwrk_create = schedwrk_create,
+	.schedwrk_create_nolock = schedwrk_create_nolock,
 	.schedwrk_destroy = schedwrk_destroy,
 	.sync_request = NULL, //sync_request,
 	.quorum_is_quorate = corosync_quorum_is_quorate,

+ 27 - 4
exec/schedwrk.c

@@ -46,6 +46,7 @@ struct schedwrk_instance {
 	int (*schedwrk_fn) (const void *);
 	const void *context;
 	void *callback_handle;
+	int lock;
 };
 
 union u {
@@ -70,9 +71,13 @@ static int schedwrk_do (enum totem_callback_token_type type, const void *context
 		goto error_exit;
 	}
 
-	serialize_lock ();
+	if (instance->lock)
+		serialize_lock ();
+
 	res = instance->schedwrk_fn (instance->context);
-	serialize_unlock ();
+
+	if (instance->lock)
+		serialize_unlock ();
 
 	if (res == 0) {
 		hdb_handle_destroy (&schedwrk_instance_database, hdb_nocheck_convert (handle));
@@ -93,10 +98,11 @@ void schedwrk_init (
 	serialize_unlock = serialize_unlock_fn;
 }
 
-int schedwrk_create (
+static int schedwrk_internal_create (
 	hdb_handle_t *handle,
 	int (schedwrk_fn) (const void *),
-	const void *context)
+	const void *context,
+	int lock)
 {
 	struct schedwrk_instance *instance;
 	int res;
@@ -121,6 +127,7 @@ int schedwrk_create (
 
 	instance->schedwrk_fn = schedwrk_fn;
 	instance->context = context;
+	instance->lock = lock;
 
         hdb_handle_put (&schedwrk_instance_database, *handle);
 
@@ -133,6 +140,22 @@ error_exit:
 	return (-1);
 }
 
+int schedwrk_create (
+	hdb_handle_t *handle,
+	int (schedwrk_fn) (const void *),
+	const void *context)
+{
+	return schedwrk_internal_create (handle, schedwrk_fn, context, 1);
+}
+
+int schedwrk_create_nolock (
+	hdb_handle_t *handle,
+	int (schedwrk_fn) (const void *),
+	const void *context)
+{
+	return schedwrk_internal_create (handle, schedwrk_fn, context, 0);
+}
+
 void schedwrk_destroy (hdb_handle_t handle)
 {
 	hdb_handle_destroy (&schedwrk_instance_database, handle);

+ 8 - 3
exec/schedwrk.h

@@ -34,15 +34,20 @@
 #ifndef SCHEDWRK_H_DEFINED
 #define SCHEDWRK_H_DEFINED
 
-void schedwrk_init (
+extern void schedwrk_init (
         void (*serialize_lock_fn) (void),
         void (*serialize_unlock_fn) (void));
 
-int schedwrk_create (
+extern int schedwrk_create (
         hdb_handle_t *handle,
         int (schedwrk_fn) (const void *),
         const void *context);
 
-void schedwrk_destroy (hdb_handle_t handle);
+extern int schedwrk_create_nolock (
+        hdb_handle_t *handle,
+        int (schedwrk_fn) (const void *),
+        const void *context);
+
+extern void schedwrk_destroy (hdb_handle_t handle);
 
 #endif /* SCHEDWRK_H_DEFINED */

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

@@ -627,6 +627,11 @@ struct corosync_api_v1 {
 		objdb_value_types_t *type);
 
 	void *(*totem_get_stats)(void);
+
+	int (*schedwrk_create_nolock) (
+		hdb_handle_t *handle,
+		int (schedwrk_fn) (const void *),
+		const void *context);
 };
 
 #define SERVICE_ID_MAKE(a,b) ( ((a)<<16) | (b) )