Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #include  <linux/types.h>
  3. #include <syscall.h>
  4. #include "hmm.h"
  5.  
  6. int init_hmm(struct hmm *mm, u32 count)
  7. {
  8.     u32* data;
  9.  
  10.     if( mm == NULL)
  11.         return -EINVAL;
  12.  
  13.     data = malloc(count*sizeof(u32*));
  14.     if( data )
  15.     {
  16.         int i;
  17.  
  18.         for(i = 0; i < count-1; )
  19.             data[i] = ++i;
  20.         data[i] = 0;
  21.  
  22.         mm->table = data;
  23.         mm->next  = 0;
  24.         mm->avail = count;
  25.         mm->count = count;
  26.  
  27.         return 0;
  28.     };
  29.     return -ENOMEM;
  30. };
  31.  
  32. u32  alloc_handle(struct hmm *mm)
  33. {
  34.     u32 handle = 0;
  35.     u32 ifl;
  36.  
  37.     ifl = safe_cli();
  38.     if(mm->avail)
  39.     {
  40.         handle = mm->next;
  41.         mm->next = mm->table[handle];
  42.         mm->avail--;
  43.         handle++;
  44.     }
  45.     safe_sti(ifl);
  46.  
  47.     return handle;
  48. };
  49.  
  50. int free_handle(struct hmm *mm, u32 handle)
  51. {
  52.     int ret = -1;
  53.     u32 ifl;
  54.  
  55.     handle--;
  56.  
  57.     ifl = safe_cli();
  58.     if(handle < mm->count)
  59.     {
  60.         mm->table[handle] = mm->next;
  61.         mm->next = handle;
  62.         mm->avail++;
  63.         ret = 0;
  64.     };
  65.     safe_sti(ifl);
  66.  
  67.     return ret;
  68. };
  69.  
  70.  
  71.  
  72.