Changeset 300f4c4 in mainline
- Timestamp:
- 2017-09-30T18:52:38Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6886705
- Parents:
- 91b60499
- Location:
- kernel/generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/lib/ra.h
r91b60499 r300f4c4 80 80 extern ra_arena_t *ra_arena_create(void); 81 81 extern bool ra_span_add(ra_arena_t *, uintptr_t, size_t); 82 extern uintptr_t ra_alloc(ra_arena_t *, size_t, size_t);82 extern bool ra_alloc(ra_arena_t *, size_t, size_t, uintptr_t *); 83 83 extern void ra_free(ra_arena_t *, uintptr_t, size_t); 84 84 -
kernel/generic/src/lib/ra.c
r91b60499 r300f4c4 196 196 ra_span_t *span; 197 197 198 /*199 * At the moment, we can only create resources that don't include 0.200 * If 0 needs to be considered as a valid resource, we would need to201 * slightly change the API of the resource allocator.202 */203 if (base == 0)204 return false;205 206 198 span = ra_span_create(base, size); 207 199 if (!span) … … 215 207 } 216 208 217 static uintptr_t ra_span_alloc(ra_span_t *span, size_t size, size_t align) 209 static bool 210 ra_span_alloc(ra_span_t *span, size_t size, size_t align, uintptr_t *base) 218 211 { 219 212 /* … … 301 294 hash_table_insert(&span->used, &key, &seg->fu_link); 302 295 303 return newbase; 304 } 305 306 return 0; 296 *base = newbase; 297 return true; 298 } 299 300 return false; 307 301 } 308 302 … … 382 376 383 377 /** Allocate resources from arena. */ 384 uintptr_t ra_alloc(ra_arena_t *arena, size_t size, size_t alignment) 385 { 386 uintptr_t base = 0; 378 bool 379 ra_alloc(ra_arena_t *arena, size_t size, size_t alignment, uintptr_t *base) 380 { 381 bool success = false; 387 382 388 383 assert(size >= 1); … … 392 387 irq_spinlock_lock(&arena->lock, true); 393 388 list_foreach(arena->spans, span_link, ra_span_t, span) { 394 base = ra_span_alloc(span, size, alignment);395 if ( base)389 success = ra_span_alloc(span, size, alignment, base); 390 if (success) 396 391 break; 397 392 } 398 393 irq_spinlock_unlock(&arena->lock, true); 399 394 400 return base;395 return success; 401 396 } 402 397 -
kernel/generic/src/mm/km.c
r91b60499 r300f4c4 117 117 uintptr_t km_page_alloc(size_t size, size_t align) 118 118 { 119 return ra_alloc(km_ni_arena, size, align); 119 uintptr_t base; 120 if (ra_alloc(km_ni_arena, size, align, &base)) 121 return base; 122 else 123 return (uintptr_t) NULL; 120 124 } 121 125
Note:
See TracChangeset
for help on using the changeset viewer.