
00001 /* -*- Mode: C; c-basic-offset:4 ; -*- */ 00002 /* 00003 * $Id$ 00004 * 00005 * Copyright (C) 1997 University of Chicago. 00006 * See COPYRIGHT notice in top-level directory. 00007 */ 00008 00009 #include "adio.h" 00010 #include "adio_extern.h" 00011 00012 struct ADIOI_RequestD *ADIOI_Malloc_request(void) 00013 { 00014 /* returns a pointer to a new request object. 00015 To reduce the number of system calls, mallocs NUM requests at a time 00016 and maintains list of available requests. Supplies an object from this 00017 list if available, else mallocs a new set of NUM and provides one 00018 from that set. Is NUM=100 a good number? */ 00019 00020 #define NUM 100 00021 00022 ADIOI_Req_node *curr, *ptr; 00023 int i; 00024 00025 if (!ADIOI_Req_avail_head) { 00026 ADIOI_Req_avail_head = (ADIOI_Req_node *) 00027 ADIOI_Malloc(NUM*sizeof(ADIOI_Req_node)); 00028 curr = ADIOI_Req_avail_head; 00029 for (i=1; i<NUM; i++) { 00030 curr->next = ADIOI_Req_avail_head+i; 00031 curr = curr->next; 00032 } 00033 curr->next = NULL; 00034 ADIOI_Req_avail_tail = curr; 00035 00036 /* keep track of malloced area that needs to be freed later */ 00037 if (!ADIOI_Malloc_req_tail) { 00038 ADIOI_Malloc_req_tail = (ADIOI_Malloc_req *) 00039 ADIOI_Malloc(sizeof(ADIOI_Malloc_req)); 00040 ADIOI_Malloc_req_head = ADIOI_Malloc_req_tail; 00041 ADIOI_Malloc_req_head->ptr = ADIOI_Req_avail_head; 00042 ADIOI_Malloc_req_head->next = NULL; 00043 } 00044 else { 00045 ADIOI_Malloc_req_tail->next = (ADIOI_Malloc_req *) 00046 ADIOI_Malloc(sizeof(ADIOI_Malloc_req)); 00047 ADIOI_Malloc_req_tail = ADIOI_Malloc_req_tail->next; 00048 ADIOI_Malloc_req_tail->ptr = ADIOI_Req_avail_head; 00049 ADIOI_Malloc_req_tail->next = NULL; 00050 } 00051 } 00052 00053 ptr = ADIOI_Req_avail_head; 00054 ADIOI_Req_avail_head = ADIOI_Req_avail_head->next; 00055 if (!ADIOI_Req_avail_head) ADIOI_Req_avail_tail = NULL; 00056 00057 (ptr->reqd).cookie = ADIOI_REQ_COOKIE; 00058 return &(ptr->reqd); 00059 } 00060 00061 00062 void ADIOI_Free_request(ADIOI_Req_node *node) 00063 { 00064 /* This function could be called as ADIOI_Free_request(ADIO_Request request), 00065 because request would be a pointer to the first element of ADIOI_Req_node.*/ 00066 00067 /* moves this node to available pool. does not actually free it. */ 00068 00069 (node->reqd).cookie = 0; 00070 00071 if (!ADIOI_Req_avail_tail) 00072 ADIOI_Req_avail_head = ADIOI_Req_avail_tail = node; 00073 else { 00074 ADIOI_Req_avail_tail->next = node; 00075 ADIOI_Req_avail_tail = node; 00076 } 00077 node->next = NULL; 00078 } 00079
1.5.5