Переглянути джерело

Make URI structures reference-counted.

tags/v0.9.3
Michael Brown 17 роки тому
джерело
коміт
656485c1f1
5 змінених файлів з 27 додано та 14 видалено
  1. 2
    2
      src/core/download.c
  2. 6
    3
      src/core/open.c
  3. 1
    1
      src/core/uri.c
  4. 0
    3
      src/include/gpxe/open.h
  5. 18
    5
      src/include/gpxe/uri.h

+ 2
- 2
src/core/download.c Переглянути файл

@@ -121,7 +121,7 @@ int start_download ( const char *uri_string, struct async *parent,
121 121
  err:
122 122
 	async_uninit ( &download->async );
123 123
 	ufree ( download->buffer.addr );
124
-	free_uri ( download->uri );
124
+	uri_put ( download->uri );
125 125
 	free ( download );
126 126
 	return rc;
127 127
 }
@@ -150,7 +150,7 @@ static void download_sigchld ( struct async *async,
150 150
 		/* Discard the buffer */
151 151
 		ufree ( download->buffer.addr );
152 152
 	}
153
-	free_uri ( download->uri );
153
+	uri_put ( download->uri );
154 154
 	download->uri = NULL;
155 155
 
156 156
 	/* Terminate ourselves */

+ 6
- 3
src/core/open.c Переглянути файл

@@ -52,6 +52,7 @@ static struct socket_opener socket_openers_end[0]
52 52
 int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
53 53
 	struct uri *uri;
54 54
 	struct uri_opener *opener;
55
+	int rc = -ENOTSUP;
55 56
 
56 57
 	DBGC ( xfer, "XFER %p opening URI %s\n", xfer, uri_string );
57 58
 
@@ -61,14 +62,16 @@ int xfer_open_uri ( struct xfer_interface *xfer, const char *uri_string ) {
61 62
 
62 63
 	for ( opener = uri_openers ; opener < uri_openers_end ; opener++ ) {
63 64
 		if ( strcmp ( uri->scheme, opener->scheme ) == 0 ) {
64
-			return opener->open ( xfer, uri );
65
+			rc = opener->open ( xfer, uri );
66
+			goto done;
65 67
 		}
66 68
 	}
67 69
 
68 70
 	DBGC ( xfer, "XFER %p attempted to open unsupported URI scheme "
69 71
 	       "\"%s\"\n", xfer, uri->scheme );
70
-	free_uri ( uri );
71
-	return -ENOTSUP;
72
+ done:
73
+	uri_put ( uri );
74
+	return rc;
72 75
 }
73 76
 
74 77
 /**

+ 1
- 1
src/core/uri.c Переглянути файл

@@ -35,7 +35,7 @@
35 35
  *
36 36
  * Splits a URI into its component parts.  The return URI structure is
37 37
  * dynamically allocated and must eventually be freed by calling
38
- * free_uri().
38
+ * uri_put().
39 39
  */
40 40
 struct uri * parse_uri ( const char *uri_string ) {
41 41
 	struct uri *uri;

+ 0
- 3
src/include/gpxe/open.h Переглянути файл

@@ -46,9 +46,6 @@ struct uri_opener {
46 46
 	 * @v xfer		Data transfer interface
47 47
 	 * @v uri		URI
48 48
 	 * @ret rc		Return status code
49
-	 *
50
-	 * This method takes ownership of the URI structure, and is
51
-	 * responsible for eventually calling free_uri().
52 49
 	 */
53 50
 	int ( * open ) ( struct xfer_interface *xfer, struct uri *uri );
54 51
 };

+ 18
- 5
src/include/gpxe/uri.h Переглянути файл

@@ -8,6 +8,7 @@
8 8
  */
9 9
 
10 10
 #include <stdlib.h>
11
+#include <gpxe/refcnt.h>
11 12
 
12 13
 /** A Uniform Resource Identifier
13 14
  *
@@ -37,6 +38,8 @@
37 38
  *   query = "what=is", fragment = "this"
38 39
  */
39 40
 struct uri {
41
+	/** Reference count */
42
+	struct refcnt refcnt;
40 43
 	/** Scheme */
41 44
 	const char *scheme;
42 45
 	/** Opaque part */
@@ -100,15 +103,25 @@ static inline int uri_has_relative_path ( struct uri *uri ) {
100 103
 }
101 104
 
102 105
 /**
103
- * Free URI structure
106
+ * Increment URI reference count
104 107
  *
105 108
  * @v uri		URI
109
+ * @ret uri		URI
110
+ */
111
+static inline __attribute__ (( always_inline )) struct uri *
112
+uri_get ( struct uri *uri ) {
113
+	ref_get ( &uri->refcnt );
114
+	return uri;
115
+}
116
+
117
+/**
118
+ * Decrement URI reference count
106 119
  *
107
- * Frees all the dynamically-allocated storage used by the URI
108
- * structure.
120
+ * @v uri		URI
109 121
  */
110
-static inline void free_uri ( struct uri *uri ) {
111
-	free ( uri );
122
+static inline __attribute__ (( always_inline )) void
123
+uri_put ( struct uri *uri ) {
124
+	ref_put ( &uri->refcnt );
112 125
 }
113 126
 
114 127
 extern struct uri * parse_uri ( const char *uri_string );

Завантаження…
Відмінити
Зберегти