freemyipod r467 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r466‎ | r467 | r468 >
Date:00:44, 22 January 2011
Author:theseven
Status:new
Tags:
Comment:
emCORE: Reverse library versioning scheme (now works like the syscall API)
Modified paths:
  • /emcore/trunk/library.c (modified) (history)
  • /emcore/trunk/library.h (modified) (history)

Diff [purge]

Index: emcore/trunk/library.c
@@ -125,36 +125,34 @@
126126 return 0;
127127 }
128128
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)
132132 {
133133 int i;
134 - int version = minversion - 1;
135134 struct library_handle* h;
136 - struct library_handle* best = NULL;
 135+ struct library_handle* lib = NULL;
137136 mutex_lock(&library_mutex, TIMEOUT_BLOCK);
138137 for (h = library_list_head; h; h = h->next)
139138 if (h->lib->identifier == identifier &&
140 - h->lib->version > version && h->lib->version <= maxversion)
 139+ h->lib->minversion <= version && h->lib->version >= version)
141140 {
142 - best = h;
143 - version = h->lib->version;
 141+ lib = h;
144142 break;
145143 }
146 - if (!best)
 144+ if (!lib)
147145 {
148146 switch (sourcetype)
149147 {
150148 case LIBSOURCE_RAM_ALLOCED:
151149 {
152 - best = (struct library_handle*)execimage(source, false);
 150+ lib = (struct library_handle*)execimage(source, false);
153151 break;
154152 }
155153
156154 case LIBSOURCE_RAM_NEEDCOPY:
157155 {
158 - best = (struct library_handle*)execimage(source, true);
 156+ lib = (struct library_handle*)execimage(source, true);
159157 break;
160158 }
161159
@@ -170,7 +168,7 @@
171169 free(buffer);
172170 break;
173171 }
174 - best = (struct library_handle*)execimage(buffer, false);
 172+ lib = (struct library_handle*)execimage(buffer, false);
175173 break;
176174 }
177175 #endif
@@ -199,49 +197,52 @@
200198 break;
201199 }
202200 close(fd);
203 - best = (struct library_handle*)execimage(buffer, false);
 201+ lib = (struct library_handle*)execimage(buffer, false);
204202 break;
205203 }
206204 #endif
207205 }
208 - if (!best)
 206+ if (h->lib->identifier != identifier ||
 207+ h->lib->minversion > version && h->lib->version < version)
 208+ lib = NULL;
 209+ if (!lib)
209210 {
210211 mutex_unlock(&library_mutex);
211212 return NULL;
212213 }
213214 }
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)
216217 {
217 - best->users[i] = owner;
 218+ lib->users[i] = owner;
218219 mutex_unlock(&library_mutex);
219 - return best->lib;
 220+ return lib->lib;
220221 }
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++)
223224 if (h->moreusers[i] == NULL)
224225 {
225226 h->moreusers[i] = owner;
226227 mutex_unlock(&library_mutex);
227 - return best->lib;
 228+ return lib->lib;
228229 }
229 - void* newalloc = realloc(best->moreusers, best->moreusers_size + 64);
 230+ void* newalloc = realloc(lib->moreusers, lib->moreusers_size + 64);
230231 if (!newalloc)
231232 {
232233 mutex_unlock(&library_mutex);
233234 return NULL;
234235 }
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;
238239 mutex_unlock(&library_mutex);
239 - return best->lib;
 240+ return lib->lib;
240241 }
241242
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,
243244 enum library_sourcetype sourcetype, void* source)
244245 {
245 - return get_library_ext(identifier, minversion, maxversion, sourcetype, source, current_thread);
 246+ return get_library_ext(identifier, version, sourcetype, source, current_thread);
246247 }
247248
248249 int release_library_ext(struct emcorelib_header* lib, struct scheduler_thread* owner)
Index: emcore/trunk/library.h
@@ -39,6 +39,7 @@
4040 uint32_t headerversion;
4141 uint32_t identifier;
4242 uint32_t version;
 43+ uint32_t minversion;
4344 int (*initfunc)();
4445 int (*shutdownfunc)();
4546 void* api;
@@ -67,11 +68,11 @@
6869 #ifndef _TOOL
6970 struct library_handle* library_register(void* image, struct emcorelib_header* header);
7071 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,
7273 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);
7677 int release_library(struct emcorelib_header* lib);
7778 int release_library_ext(struct emcorelib_header* lib, struct scheduler_thread* owner);
7879 int library_release_all_of_thread(struct scheduler_thread* thread);