root/ompi/mca/io/romio321/romio/adio/common/req_malloc.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_Malloc_request
  2. ADIOI_Free_request

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "adio.h"
   9 #include "adio_extern.h"
  10 
  11 struct ADIOI_RequestD *ADIOI_Malloc_request(void)
  12 {
  13 /* returns a pointer to a new request object.
  14    To reduce the number of system calls, mallocs NUM requests at a time
  15    and maintains list of available requests. Supplies an object from this
  16    list if available, else mallocs a new set of NUM and provides one
  17    from that set. Is NUM=100 a good number? */
  18 
  19 #define NUM 100
  20 
  21     ADIOI_Req_node *curr, *ptr;
  22     int i;
  23 
  24     if (!ADIOI_Req_avail_head) {
  25         ADIOI_Req_avail_head = (ADIOI_Req_node *) 
  26                       ADIOI_Malloc(NUM*sizeof(ADIOI_Req_node));
  27         if (ADIOI_Req_avail_head == NULL)
  28         {
  29             /* FIXME: Insert error here */
  30             return NULL;
  31         }
  32         curr = ADIOI_Req_avail_head;
  33         for (i=1; i<NUM; i++) {
  34             curr->next = ADIOI_Req_avail_head+i;
  35             curr = curr->next;
  36         }
  37         curr->next = NULL;
  38         ADIOI_Req_avail_tail = curr;
  39 
  40         /* keep track of malloced area that needs to be freed later */
  41         if (!ADIOI_Malloc_req_tail) {
  42             ADIOI_Malloc_req_tail = (ADIOI_Malloc_req *)
  43                 ADIOI_Malloc(sizeof(ADIOI_Malloc_req)); 
  44             ADIOI_Malloc_req_head = ADIOI_Malloc_req_tail;
  45             ADIOI_Malloc_req_head->ptr = ADIOI_Req_avail_head;
  46             ADIOI_Malloc_req_head->next = NULL;
  47         }
  48         else {
  49             ADIOI_Malloc_req_tail->next = (ADIOI_Malloc_req *)
  50                 ADIOI_Malloc(sizeof(ADIOI_Malloc_req));
  51             ADIOI_Malloc_req_tail = ADIOI_Malloc_req_tail->next;
  52             ADIOI_Malloc_req_tail->ptr = ADIOI_Req_avail_head;
  53             ADIOI_Malloc_req_tail->next = NULL;
  54         }
  55     }
  56 
  57     ptr = ADIOI_Req_avail_head;
  58     ADIOI_Req_avail_head = ADIOI_Req_avail_head->next;
  59     if (!ADIOI_Req_avail_head) ADIOI_Req_avail_tail = NULL;
  60     
  61     (ptr->reqd).cookie = ADIOI_REQ_COOKIE;
  62     return &(ptr->reqd);
  63 }
  64 
  65 
  66 void ADIOI_Free_request(ADIOI_Req_node *node)
  67 {
  68 /* This function could be called as ADIOI_Free_request(ADIO_Request request), 
  69    because request would be a pointer to the first element of ADIOI_Req_node.*/
  70 
  71 /* moves this node to available pool. does not actually free it. */
  72 
  73     (node->reqd).cookie = 0;
  74 
  75     if (!ADIOI_Req_avail_tail)
  76         ADIOI_Req_avail_head = ADIOI_Req_avail_tail = node;
  77     else {
  78         ADIOI_Req_avail_tail->next = node;
  79         ADIOI_Req_avail_tail = node;
  80     }
  81     node->next = NULL;
  82 }
  83 

/* [<][>][^][v][top][bottom][index][help] */