Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 02667d9 in mainline


Ignore:
Timestamp:
2017-10-09T19:10:25Z (4 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
bfdb7c63
Parents:
d75dc05
Message:

Resource arenas should be destructible

Location:
kernel/generic
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/lib/ra.h

    rd75dc05 r02667d9  
    8787extern void ra_init(void);
    8888extern ra_arena_t *ra_arena_create(void);
     89extern void ra_arena_destroy(ra_arena_t *);
    8990extern bool ra_span_add(ra_arena_t *, uintptr_t, size_t);
    9091extern bool ra_alloc(ra_arena_t *, size_t, size_t, uintptr_t *);
  • kernel/generic/src/lib/ra.c

    rd75dc05 r02667d9  
    7575static bool used_key_equal(void *key, const ht_link_t *item)
    7676{
    77         uintptr_t *base = (sysarg_t *) key;
     77        uintptr_t *base = (uintptr_t *) key;
    7878        ra_segment_t *seg = hash_table_get_inst(item, ra_segment_t, uh_link);
    7979        return seg->base == *base;
     
    184184}
    185185
     186static void ra_span_destroy(ra_span_t *span)
     187{
     188        hash_table_destroy(&span->used);
     189
     190        list_foreach_safe(span->segments, cur, next) {
     191                ra_segment_t *seg = list_get_instance(cur, ra_segment_t,
     192                    segment_link);
     193                list_remove(&seg->segment_link);
     194                if (seg->flags & RA_SEGMENT_FREE)
     195                        list_remove(&seg->fl_link);
     196                ra_segment_destroy(seg);
     197        }
     198
     199        free(span);
     200}
     201
    186202/** Create an empty arena. */
    187203ra_arena_t *ra_arena_create(void)
     
    197213
    198214        return arena;
     215}
     216
     217void ra_arena_destroy(ra_arena_t *arena)
     218{
     219        /*
     220         * No locking necessary as this is the cleanup and all users should have
     221         * stopped using the arena already.
     222         */
     223        list_foreach_safe(arena->spans, cur, next) {
     224                ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
     225                list_remove(&span->span_link);
     226                ra_span_destroy(span);
     227        }
     228
     229        free(arena);
    199230}
    200231
Note: See TracChangeset for help on using the changeset viewer.