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

Changeset 3342f33 in mainline


Ignore:
Timestamp:
2011-12-09T21:35:29Z (10 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master
Children:
bb7e6fc5
Parents:
12cb03d
Message:

Basic locking for resource allocator.

Location:
kernel/generic
Files:
2 edited

Legend:

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

    r12cb03d r3342f33  
    3939#include <adt/list.h>
    4040#include <adt/hash_table.h>
     41#include <synch/spinlock.h>
    4142
    4243typedef struct {
     44        SPINLOCK_DECLARE(lock);
    4345        list_t spans;           /**< List of arena's spans. */
    4446} ra_arena_t;
  • kernel/generic/src/lib/ra.c

    r12cb03d r3342f33  
    5353#include <align.h>
    5454#include <macros.h>
     55#include <synch/spinlock.h>
    5556
    5657#define USED_BUCKETS    1024
     
    197198        }
    198199
     200        spinlock_initialize(&arena->lock, "arena_lock");
    199201        list_initialize(&arena->spans);
    200202        list_append(&span->span_link, &arena->spans);
     
    216218
    217219        /* TODO: check for overlaps */
     220        spinlock_lock(&arena->lock);
    218221        list_append(&span->span_link, &arena->spans);
     222        spinlock_unlock(&arena->lock);
    219223        return true;
    220224}
     
    395399        ASSERT(ispwr2(alignment));
    396400
     401        spinlock_lock(&arena->lock);
    397402        list_foreach(arena->spans, cur) {
    398403                ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
     
    402407                        break;
    403408        }
     409        spinlock_unlock(&arena->lock);
    404410
    405411        return base;
     
    409415void ra_free(ra_arena_t *arena, uintptr_t base, size_t size)
    410416{
     417        spinlock_lock(&arena->lock);
    411418        list_foreach(arena->spans, cur) {
    412419                ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
     
    414421                if (iswithin(span->base, span->size, base, size)) {
    415422                        ra_span_free(span, base, size);
     423                        spinlock_unlock(&arena->lock);
    416424                        return;
    417425                }
    418426        }
     427        spinlock_unlock(&arena->lock);
    419428
    420429        panic("Freeing to wrong arena (base=%" PRIxn ", size=%" PRIdn ").",
Note: See TracChangeset for help on using the changeset viewer.