~ubuntu-branches/ubuntu/karmic/scilab/karmic

« back to all changes in this revision

Viewing changes to pvm3/src/pkt.c

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2002-03-21 16:57:43 UTC
  • Revision ID: james.westby@ubuntu.com-20020321165743-e9mv12c1tb1plztg
Tags: upstream-2.6
ImportĀ upstreamĀ versionĀ 2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
static char rcsid[] =
 
3
        "$Id: pkt.c,v 1.3 1997/06/27 17:32:32 pvmsrc Exp $";
 
4
 
 
5
/*
 
6
 *         PVM version 3.4:  Parallel Virtual Machine System
 
7
 *               University of Tennessee, Knoxville TN.
 
8
 *           Oak Ridge National Laboratory, Oak Ridge TN.
 
9
 *                   Emory University, Atlanta GA.
 
10
 *      Authors:  J. J. Dongarra, G. E. Fagg, M. Fischer
 
11
 *          G. A. Geist, J. A. Kohl, R. J. Manchek, P. Mucci,
 
12
 *         P. M. Papadopoulos, S. L. Scott, and V. S. Sunderam
 
13
 *                   (C) 1997 All Rights Reserved
 
14
 *
 
15
 *                              NOTICE
 
16
 *
 
17
 * Permission to use, copy, modify, and distribute this software and
 
18
 * its documentation for any purpose and without fee is hereby granted
 
19
 * provided that the above copyright notice appear in all copies and
 
20
 * that both the copyright notice and this permission notice appear in
 
21
 * supporting documentation.
 
22
 *
 
23
 * Neither the Institutions (Emory University, Oak Ridge National
 
24
 * Laboratory, and University of Tennessee) nor the Authors make any
 
25
 * representations about the suitability of this software for any
 
26
 * purpose.  This software is provided ``as is'' without express or
 
27
 * implied warranty.
 
28
 *
 
29
 * PVM version 3 was funded in part by the U.S. Department of Energy,
 
30
 * the National Science Foundation and the State of Tennessee.
 
31
 */
 
32
 
 
33
/*
 
34
 *      pkt.c
 
35
 *
 
36
 *      Packet buffers.
 
37
 *
 
38
$Log: pkt.c,v $
 
39
 * Revision 1.3  1997/06/27  17:32:32  pvmsrc
 
40
 * Updated for WIN32 header files & Authors.
 
41
 *
 
42
 * Revision 1.2  1997/01/28  19:26:56  pvmsrc
 
43
 * New Copyright Notice & Authors.
 
44
 *
 
45
 * Revision 1.1  1996/09/23  23:44:23  pvmsrc
 
46
 * Initial revision
 
47
 *
 
48
 * Revision 1.3  1995/07/24  18:27:24  manchek
 
49
 * zero pk_cpos on create
 
50
 *
 
51
 * Revision 1.2  1994/06/03  20:38:20  manchek
 
52
 * version 3.3.0
 
53
 *
 
54
 * Revision 1.1  1993/08/30  23:26:49  manchek
 
55
 * Initial revision
 
56
 *
 
57
 */
 
58
 
 
59
#include <stdio.h>
 
60
#ifndef WIN32
 
61
#include <sys/time.h>
 
62
#else
 
63
#include "pvmwin.h"
 
64
#endif
 
65
 
 
66
#include <pvm3.h>
 
67
#include "pvmalloc.h"
 
68
#include "pkt.h"
 
69
#include "pvmdabuf.h"
 
70
#include "listmac.h"
 
71
#include "bfunc.h"
 
72
 
 
73
 
 
74
extern void pvmbailout();
 
75
 
 
76
 
 
77
/***************
 
78
 **  Private  **
 
79
 **           **
 
80
 ***************/
 
81
 
 
82
 
 
83
 
 
84
/*********************
 
85
 **  Pkt Functions  **
 
86
 **                 **
 
87
 *********************/
 
88
 
 
89
 
 
90
/*      pk_new()
 
91
*
 
92
*       Create a new pkt, not in a list.
 
93
*       If len is nonzero, len bytes are allocated as data space.
 
94
*       Else, the pkt has no data (is a master or will get data later).
 
95
*
 
96
*       The following fields are uninitialized:
 
97
*       pk_src, pk_dst, pk_flag, pk_tag, pk_ctx, pk_enc, pk_wid, pk_crc, pk_hostd,
 
98
*       pk_seq, pk_ack, pk_rtv, pk_rta, pk_rto, pk_at, pk_nrt
 
99
*/
 
100
 
 
101
struct pkt *
 
102
pk_new(len)
 
103
        int len;        /* (max) buffer size or 0 */
 
104
{
 
105
        struct pkt *pp;
 
106
 
 
107
        if (!(pp = TALLOC(1, struct pkt, "pkt")))
 
108
                goto oops;
 
109
/*
 
110
        BZERO((char*)pp, sizeof(struct pkt));
 
111
*/
 
112
 
 
113
        if (len) {              /* slave pkt */
 
114
                if (!(pp->pk_dat = pp->pk_buf = da_new(len))) {
 
115
                        PVM_FREE(pp);
 
116
                        goto oops;
 
117
                }
 
118
                pp->pk_max = len;
 
119
                pp->pk_len = 0;
 
120
                pp->pk_link = pp->pk_rlink = 0;
 
121
 
 
122
        } else {                /* master */
 
123
                pp->pk_dat = pp->pk_buf = 0;
 
124
                pp->pk_link = pp->pk_rlink = pp;
 
125
        }
 
126
        pp->pk_cpos = 0;
 
127
        pp->pk_tlink = pp->pk_trlink = 0;
 
128
        return pp;
 
129
 
 
130
oops:
 
131
        pvmlogerror("pk_new() can't get memory\n");
 
132
        pvmbailout(0);
 
133
        return (struct pkt*)0;
 
134
}
 
135
 
 
136
 
 
137
void
 
138
pk_free(pp)
 
139
        struct pkt *pp;
 
140
{
 
141
        struct pkt *pp2, *pp3;
 
142
 
 
143
        if (pp->pk_buf) {               /* slave pkt */
 
144
                if (pp->pk_tlink) {
 
145
                        LISTDELETE(pp, pk_tlink, pk_trlink);
 
146
                }
 
147
                da_unref(pp->pk_buf);
 
148
 
 
149
        } else {                                /* master pkt */
 
150
 
 
151
        /* free all pkts in chain */
 
152
                for (pp2 = pp->pk_link; pp2 != pp; pp2 = pp3) {
 
153
                        pp3 = pp2->pk_link;
 
154
                        LISTDELETE(pp2, pk_link, pk_rlink);
 
155
                        pk_free(pp2);
 
156
                }
 
157
        }
 
158
        PVM_FREE(pp);
 
159
}
 
160