Subversion Repositories shark

Rev

Rev 141 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
141 trimarchi 1
#include "didma.h"
2
#ifndef _QUEUEM_H_
3
#define _QUEUEM_H_
4
 
5
#define BLOCK_SIZE_CM (32 * sizeof(unsigned char *))
6
 
7
typedef struct cm_block {
8
  struct cm_block *next;
9
  unsigned char *block[BLOCK_SIZE_CM];
10
} cm_block_t;
11
 
12
static cm_block_t *cm_header, *cm_free;
13
 
14
static inline int _init_malloc_ (int n_blocks) {
15
  int n;
16
 
17
  cm_header = (cm_block_t *) SYSTEM_MALLOC (n_blocks * sizeof(cm_block_t));
18
 
19
  if (cm_header == NULL) return -1;
20
 
21
  for (n = 0; n < n_blocks; n++)
22
    cm_header [n].next =((n + 1 == n_blocks)? NULL : &(cm_header [n + 1]));
23
 
24
  cm_free = &cm_header [0];
25
  return 0;
26
}
27
 
28
static inline void _destroy_malloc_ (void) {
29
  SYSTEM_FREE (cm_header);
30
}
31
 
32
 
33
static inline void *_malloc_ (void){
34
  cm_block_t *aux;
35
  if (cm_free == NULL) return NULL;
36
 
37
  aux = cm_free;
38
  cm_free = cm_free -> next;
39
  aux -> next = NULL;
40
  memset(aux, 0, BLOCK_SIZE_CM);
41
  return aux;
42
}
43
 
44
static inline void _free_ (void *ptr){
45
  cm_block_t *aux;
46
  aux = (cm_block_t *) ptr;
47
  aux -> next = cm_free;
48
  cm_free = aux;
49
}
50
 
51
#endif