Changeset e17f703 in mainline


Ignore:
Timestamp:
2011-04-16T19:39:59Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
9e953bda
Parents:
8b6930d
Message:

Implement memory reservation API.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/reserve.c

    r8b6930d re17f703  
    3636 */
    3737
    38 #include <typedefs.h>
    3938#include <mm/reserve.h>
    4039#include <mm/frame.h>
     40#include <synch/spinlock.h>
     41#include <typedefs.h>
     42#include <arch/types.h>
     43
     44IRQ_SPINLOCK_STATIC_INITIALIZE_NAME(reserve_lock, "reserve_lock");
     45static ssize_t reserve = 0;
    4146
    4247bool reserve_try_alloc(size_t size)
    4348{
    44         return true;
     49        bool reserved = false;
     50
     51        irq_spinlock_lock(&reserve_lock, true);
     52        if (reserve >= 0 && (size_t) reserve >= size) {
     53                reserve -= size;
     54                reserved = true;
     55        }
     56        irq_spinlock_unlock(&reserve_lock, true);
     57
     58        return reserved;
    4559}
    4660
    4761void reserve_force_alloc(size_t size)
    4862{
     63        irq_spinlock_lock(&reserve_lock, true);
     64        reserve -= size;
     65        irq_spinlock_unlock(&reserve_lock, true);
    4966}
    5067
    5168void reserve_free(size_t size)
    5269{
     70        irq_spinlock_lock(&reserve_lock, true);
     71        reserve += size;
     72        irq_spinlock_unlock(&reserve_lock, true);
    5373}
    5474
Note: See TracChangeset for help on using the changeset viewer.