[syslinux] [Syslinux] Patch sensible callback framework

Ayvaz, James James.Ayvaz at hp.com
Tue Jun 1 05:21:48 PDT 2010


Following up on this.  Were there any more changes that I need to make to get this patch accepted?  Thanks.


diff -uprN syslinux-3.86-vanilla/com32/include/syslinux/callback.h syslinux-3.86/com32/include/syslinux/callback.h
--- syslinux-3.86-vanilla/com32/include/syslinux/callback.h	1969-12-31 18:00:00.000000000 -0600
+++ syslinux-3.86/com32/include/syslinux/callback.h	2010-05-12 05:28:41.000000000 -0500
@@ -0,0 +1,67 @@
+#ifndef LIBUTIL_CALLBACK_H
+#define LIBUTIL_CALLBACK_H
+
+#include <stddef.h>
+#include <stdio.h>
+#include <inttypes.h>
+#include <assert.h>
+
+struct callback_record;
+
+typedef void (*callback_t)(void *rarg, va_list ap);
+
+#define INIT_CALLBACK( ptr ) do { \
+	assert ((ptr) != NULL ); \
+        if ((ptr)->next) break; \
+	(ptr)->next = (ptr); (ptr)->prev = (ptr); (ptr)->function = NULL; (ptr)->rarg = NULL; \
+} while ( 0 )
+
+struct callback_record  {
+  callback_t function;
+  struct callback_record *next;
+  struct callback_record *prev;
+  void *rarg;
+};
+
+
+static inline struct callback_record* register_callback(struct callback_record *head, callback_t callback, void *rarg) {
+    struct callback_record *new;
+
+    new = malloc(sizeof(struct callback_record));
+    if (!new)
+        return NULL;
+
+    INIT_CALLBACK(head);
+
+    new->function = callback;
+    new->rarg = rarg;
+    new->next = head->next;
+    new->prev = head;
+    head->next->prev = new;
+    head->next = new;
+    return new;
+}
+
+static inline int unregister_callback(struct callback_record *cb) {
+    cb->next->prev = cb->prev;
+    cb->prev->next = cb->next;
+    free(cb);
+    return 0;
+}
+
+static int invoke_callbacks(struct callback_record *head, ...) {
+   va_list ap;
+   struct callback_record *curr;
+
+   curr = head;
+   do {
+       if (curr->function) {
+           va_start(ap, head);
+           curr->function(curr->rarg, ap);
+           va_end(ap);
+       }
+       curr = curr->next;
+   } while(curr != head);
+}
+
+#endif

-----Original Message-----
From: H. Peter Anvin [mailto:hpa at zytor.com] 
Sent: Tuesday, May 11, 2010 3:44 PM
To: For discussion of Syslinux and tftp-hpa
Cc: Ayvaz, James
Subject: Re: [syslinux] Patch sensible callback framework

On 05/11/2010 08:45 AM, Ayvaz, James wrote:
> Is something like this what you had in mind? 

No, use a head node -- i.e. a struct callback_record (with function ==
NULL) at the start of the list.  Google for "doubly linked list with
head node".

Oh yes, and lose the typedefs.

	-hpa
-- 
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.



More information about the Syslinux mailing list