Browse Source

Minimal hotplug support: provide a facility for notifying persistent

reference holders that their reference is about to become invalid.
tags/v0.9.3
Michael Brown 18 years ago
parent
commit
0063725d28
2 changed files with 103 additions and 0 deletions
  1. 45
    0
      src/core/hotplug.c
  2. 58
    0
      src/include/gpxe/hotplug.h

+ 45
- 0
src/core/hotplug.c View File

@@ -0,0 +1,45 @@
1
+/*
2
+ * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <assert.h>
20
+#include <gpxe/hotplug.h>
21
+
22
+/** @file
23
+ *
24
+ * Hotplug support
25
+ *
26
+ */
27
+
28
+/**
29
+ * Forget all persistent references to an object
30
+ *
31
+ * @v list		List of persistent references
32
+ */
33
+void forget_references ( struct list_head *list ) {
34
+	struct reference *ref;
35
+	struct reference *ref_tmp;
36
+
37
+	list_for_each_entry_safe ( ref, ref_tmp, list, list ) {
38
+		ref->forget ( ref );
39
+	}
40
+
41
+	/* The list had really better be empty by now, otherwise we're
42
+	 * screwed.
43
+	 */
44
+	assert ( list_empty ( list ) );
45
+}

+ 58
- 0
src/include/gpxe/hotplug.h View File

@@ -0,0 +1,58 @@
1
+#ifndef _GPXE_HOTPLUG_H
2
+#define _GPXE_HOTPLUG_H
3
+
4
+/** @file
5
+ *
6
+ * Hotplug support
7
+ *
8
+ */
9
+
10
+#include <gpxe/list.h>
11
+
12
+/**
13
+ * A persistent reference to another data structure
14
+ *
15
+ * This data structure should be embedded within any data structure
16
+ * (the referrer) which holds a persistent reference to a separate,
17
+ * volatile data structure (the referee).
18
+ */
19
+struct reference {
20
+	/** List of persistent references */
21
+	struct list_head list;
22
+	/** Forget persistent reference
23
+	 *
24
+	 * @v ref		Persistent reference
25
+	 *
26
+	 * This method is called immediately before the referred-to
27
+	 * data structure is destroyed.  The reference holder must
28
+	 * forget all references to the referee before returning from
29
+	 * this method.
30
+	 *
31
+	 * This method must also call ref_del() to remove the
32
+	 * reference.
33
+	 */
34
+	void ( * forget ) ( struct reference *ref );
35
+};
36
+
37
+/**
38
+ * Add persistent reference
39
+ *
40
+ * @v ref		Persistent reference
41
+ * @v list		List of persistent references
42
+ */
43
+static inline void ref_add ( struct reference *ref, struct list_head *list ) {
44
+	list_add ( &ref->list, list );
45
+}
46
+
47
+/**
48
+ * Remove persistent reference
49
+ *
50
+ * @v ref		Persistent reference
51
+ */
52
+static inline void ref_del ( struct reference *ref ) {
53
+	list_del ( &ref->list );
54
+}
55
+
56
+extern void forget_references ( struct list_head *list );
57
+
58
+#endif /* _GPXE_HOTPLUG_H */

Loading…
Cancel
Save