1 /* tube.c - tubes implementation */
3 /* Copyright (C) 2008 Keith Rarick and Philotic Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 make_tube(const char *name
)
32 t
= malloc(sizeof(struct tube
));
37 t
->name
[MAX_TUBE_NAME_LEN
- 1] = '\0';
38 strncpy(t
->name
, name
, MAX_TUBE_NAME_LEN
- 1);
39 if (t
->name
[MAX_TUBE_NAME_LEN
- 1] != '\0') twarnx("truncating tube name");
41 pq_init(&t
->ready
, job_pri_cmp
);
42 pq_init(&t
->delay
, job_delay_cmp
);
43 t
->buried
= (struct job
) { &t
->buried
, &t
->buried
, 0 };
44 ms_init(&t
->waiting
, NULL
, NULL
);
46 t
->stat
= (struct stats
) {0, 0, 0, 0};
47 t
->using_ct
= t
->watching_ct
= 0;
57 ms_clear(&t
->waiting
);
65 if (t
->refs
< 1) return twarnx("refs is zero for tube: %s", t
->name
);
68 if (t
->refs
< 1) tube_free(t
);