2 * Copyright (c) 1990,1991 Regents of The University of Michigan.
5 * Permission to use, copy, modify, and distribute this software and
6 * its documentation for any purpose and without fee is hereby granted,
7 * provided that the above copyright notice appears in all copies and
8 * that both that copyright notice and this permission notice appear
9 * in supporting documentation, and that the name of The University
10 * of Michigan not be used in advertising or publicity pertaining to
11 * distribution of the software without specific, written prior
12 * permission. This software is supplied as is without expressed or
13 * implied warranties of any kind.
15 * Research Systems Unix Group
16 * The University of Michigan
18 * 535 W. William Street
21 * netatalk@itd.umich.edu
25 * Our own memory maintenance for atp
32 #include <sys/types.h>
35 #include <netatalk/at.h>
36 #include <atalk/atp.h>
37 #include "atp_internals.h"
39 #define N_MORE_BUFS 10
41 static struct atpbuf *free_list = NULL; /* free buffers */
44 static int numbufs = 0;
47 /* only call this when the free_list is empty...
48 * N_MORE_BUFS must be >= one
50 static int more_bufs(void)
56 /* get the whole chunk in one malloc call
58 if (( mem = malloc( N_MORE_BUFS * sizeof( struct atpbuf ))) == NULL ) {
62 /* now split into separate bufs
64 bp = free_list = (struct atpbuf *) mem;
65 for ( i = 1; i < N_MORE_BUFS; ++i ) {
66 bp->atpbuf_next = (struct atpbuf *) ( mem += sizeof( struct atpbuf ));
69 bp->atpbuf_next = NULL;
76 void atp_print_bufuse( ah, s )
81 int i, sentcount, incount, respcount;
84 for ( bp = ah->atph_sent; bp != NULL; bp = bp->atpbuf_next ) {
86 for ( i = 0; i < 8; ++i ) {
87 if ( bp->atpbuf_info.atpbuf_xo.atpxo_packet[ i ] != NULL ) {
93 if ( ah->atph_reqpkt != NULL ) {
99 for ( bp = ah->atph_queue; bp != NULL; bp = bp->atpbuf_next, ++incount );
102 for ( i = 0; i < 8; ++i ) {
103 if ( ah->atph_resppkt[ i ] != NULL ) {
108 printf( "<%d> %s: bufs total %d sent %d incoming %d req %d resp %d\n",
109 getpid(), s, numbufs, sentcount, incount,
110 ( ah->atph_reqpkt != NULL ) ? 1: 0, respcount );
115 struct atpbuf *atp_alloc_buf(void)
119 if ( free_list == NULL && more_bufs() ) return NULL;
122 free_list = free_list->atpbuf_next;
130 int atp_free_buf( bp )
136 bp->atpbuf_next = free_list;