1 /* -*- Mode: C; c-basic-offset:4 ; -*- */
4 * Copyright (C) 1997 University of Chicago.
5 * See COPYRIGHT notice in top-level directory.
9 #include "adio_extern.h"
11 struct ADIOI_RequestD
*ADIOI_Malloc_request(void)
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? */
21 ADIOI_Req_node
*curr
, *ptr
;
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
)
29 /* FIXME: Insert error here */
32 curr
= ADIOI_Req_avail_head
;
33 for (i
=1; i
<NUM
; i
++) {
34 curr
->next
= ADIOI_Req_avail_head
+i
;
38 ADIOI_Req_avail_tail
= curr
;
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
;
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
;
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
;
61 (ptr
->reqd
).cookie
= ADIOI_REQ_COOKIE
;
66 void ADIOI_Free_request(ADIOI_Req_node
*node
)
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.*/
71 /* moves this node to available pool. does not actually free it. */
73 (node
->reqd
).cookie
= 0;
75 if (!CtvAccess(ADIOI_Req_avail_tail
))
76 CtvAccess(ADIOI_Req_avail_head
) = CtvAccess(ADIOI_Req_avail_tail
) = node
;
78 CtvAccess(ADIOI_Req_avail_tail
)->next
= node
;
79 CtvAccess(ADIOI_Req_avail_tail
) = node
;