Index: emcore/trunk/library.c |
— | — | @@ -125,36 +125,34 @@ |
126 | 126 | return 0;
|
127 | 127 | }
|
128 | 128 |
|
129 | | -struct emcorelib_header* get_library_ext(uint32_t identifier, uint32_t minversion,
|
130 | | - uint32_t maxversion, enum library_sourcetype sourcetype,
|
131 | | - void* source, struct scheduler_thread* owner)
|
| 129 | +struct emcorelib_header* get_library_ext(uint32_t identifier, uint32_t version,
|
| 130 | + enum library_sourcetype sourcetype, void* source,
|
| 131 | + struct scheduler_thread* owner)
|
132 | 132 | {
|
133 | 133 | int i;
|
134 | | - int version = minversion - 1;
|
135 | 134 | struct library_handle* h;
|
136 | | - struct library_handle* best = NULL;
|
| 135 | + struct library_handle* lib = NULL;
|
137 | 136 | mutex_lock(&library_mutex, TIMEOUT_BLOCK);
|
138 | 137 | for (h = library_list_head; h; h = h->next)
|
139 | 138 | if (h->lib->identifier == identifier &&
|
140 | | - h->lib->version > version && h->lib->version <= maxversion)
|
| 139 | + h->lib->minversion <= version && h->lib->version >= version)
|
141 | 140 | {
|
142 | | - best = h;
|
143 | | - version = h->lib->version;
|
| 141 | + lib = h;
|
144 | 142 | break;
|
145 | 143 | }
|
146 | | - if (!best)
|
| 144 | + if (!lib)
|
147 | 145 | {
|
148 | 146 | switch (sourcetype)
|
149 | 147 | {
|
150 | 148 | case LIBSOURCE_RAM_ALLOCED:
|
151 | 149 | {
|
152 | | - best = (struct library_handle*)execimage(source, false);
|
| 150 | + lib = (struct library_handle*)execimage(source, false);
|
153 | 151 | break;
|
154 | 152 | }
|
155 | 153 |
|
156 | 154 | case LIBSOURCE_RAM_NEEDCOPY:
|
157 | 155 | {
|
158 | | - best = (struct library_handle*)execimage(source, true);
|
| 156 | + lib = (struct library_handle*)execimage(source, true);
|
159 | 157 | break;
|
160 | 158 | }
|
161 | 159 |
|
— | — | @@ -170,7 +168,7 @@ |
171 | 169 | free(buffer);
|
172 | 170 | break;
|
173 | 171 | }
|
174 | | - best = (struct library_handle*)execimage(buffer, false);
|
| 172 | + lib = (struct library_handle*)execimage(buffer, false);
|
175 | 173 | break;
|
176 | 174 | }
|
177 | 175 | #endif
|
— | — | @@ -199,49 +197,52 @@ |
200 | 198 | break;
|
201 | 199 | }
|
202 | 200 | close(fd);
|
203 | | - best = (struct library_handle*)execimage(buffer, false);
|
| 201 | + lib = (struct library_handle*)execimage(buffer, false);
|
204 | 202 | break;
|
205 | 203 | }
|
206 | 204 | #endif
|
207 | 205 | }
|
208 | | - if (!best)
|
| 206 | + if (h->lib->identifier != identifier ||
|
| 207 | + h->lib->minversion > version && h->lib->version < version)
|
| 208 | + lib = NULL;
|
| 209 | + if (!lib)
|
209 | 210 | {
|
210 | 211 | mutex_unlock(&library_mutex);
|
211 | 212 | return NULL;
|
212 | 213 | }
|
213 | 214 | }
|
214 | | - for (i = 0; i < ARRAYLEN(best->users); i++)
|
215 | | - if (best->users[i] == NULL)
|
| 215 | + for (i = 0; i < ARRAYLEN(lib->users); i++)
|
| 216 | + if (lib->users[i] == NULL)
|
216 | 217 | {
|
217 | | - best->users[i] = owner;
|
| 218 | + lib->users[i] = owner;
|
218 | 219 | mutex_unlock(&library_mutex);
|
219 | | - return best->lib;
|
| 220 | + return lib->lib;
|
220 | 221 | }
|
221 | | - if (best->moreusers)
|
222 | | - for (i = 0; i < best->moreusers_size / 4; i++)
|
| 222 | + if (lib->moreusers)
|
| 223 | + for (i = 0; i < lib->moreusers_size / 4; i++)
|
223 | 224 | if (h->moreusers[i] == NULL)
|
224 | 225 | {
|
225 | 226 | h->moreusers[i] = owner;
|
226 | 227 | mutex_unlock(&library_mutex);
|
227 | | - return best->lib;
|
| 228 | + return lib->lib;
|
228 | 229 | }
|
229 | | - void* newalloc = realloc(best->moreusers, best->moreusers_size + 64);
|
| 230 | + void* newalloc = realloc(lib->moreusers, lib->moreusers_size + 64);
|
230 | 231 | if (!newalloc)
|
231 | 232 | {
|
232 | 233 | mutex_unlock(&library_mutex);
|
233 | 234 | return NULL;
|
234 | 235 | }
|
235 | | - best->moreusers = (void**)newalloc;
|
236 | | - best->moreusers[best->moreusers_size / 4] = owner;
|
237 | | - best->moreusers_size += 64;
|
| 236 | + lib->moreusers = (void**)newalloc;
|
| 237 | + lib->moreusers[lib->moreusers_size / 4] = owner;
|
| 238 | + lib->moreusers_size += 64;
|
238 | 239 | mutex_unlock(&library_mutex);
|
239 | | - return best->lib;
|
| 240 | + return lib->lib;
|
240 | 241 | }
|
241 | 242 |
|
242 | | -struct emcorelib_header* get_library(uint32_t identifier, uint32_t minversion, uint32_t maxversion,
|
| 243 | +struct emcorelib_header* get_library(uint32_t identifier, uint32_t version,
|
243 | 244 | enum library_sourcetype sourcetype, void* source)
|
244 | 245 | {
|
245 | | - return get_library_ext(identifier, minversion, maxversion, sourcetype, source, current_thread);
|
| 246 | + return get_library_ext(identifier, version, sourcetype, source, current_thread);
|
246 | 247 | }
|
247 | 248 |
|
248 | 249 | int release_library_ext(struct emcorelib_header* lib, struct scheduler_thread* owner)
|
Index: emcore/trunk/library.h |
— | — | @@ -39,6 +39,7 @@ |
40 | 40 | uint32_t headerversion;
|
41 | 41 | uint32_t identifier;
|
42 | 42 | uint32_t version;
|
| 43 | + uint32_t minversion;
|
43 | 44 | int (*initfunc)();
|
44 | 45 | int (*shutdownfunc)();
|
45 | 46 | void* api;
|
— | — | @@ -67,11 +68,11 @@ |
68 | 69 | #ifndef _TOOL
|
69 | 70 | struct library_handle* library_register(void* image, struct emcorelib_header* header);
|
70 | 71 | int library_unload(struct library_handle* lib);
|
71 | | -struct emcorelib_header* get_library(uint32_t identifier, uint32_t minversion, uint32_t maxversion,
|
| 72 | +struct emcorelib_header* get_library(uint32_t identifier, uint32_t version,
|
72 | 73 | enum library_sourcetype sourcetype, void* source);
|
73 | | -struct emcorelib_header* get_library_ext(uint32_t identifier, uint32_t minversion,
|
74 | | - uint32_t maxversion, enum library_sourcetype sourcetype,
|
75 | | - void* source, struct scheduler_thread* owner);
|
| 74 | +struct emcorelib_header* get_library_ext(uint32_t identifier, uint32_t version,
|
| 75 | + enum library_sourcetype sourcetype, void* source,
|
| 76 | + struct scheduler_thread* owner);
|
76 | 77 | int release_library(struct emcorelib_header* lib);
|
77 | 78 | int release_library_ext(struct emcorelib_header* lib, struct scheduler_thread* owner);
|
78 | 79 | int library_release_all_of_thread(struct scheduler_thread* thread);
|