Use z rather than the obsolete Z modifier.
[beanstalkd.git] / tube.c
blob5e728b84af855385d99713a21dcb5fde3ef116bc
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/>.
19 #include <stdlib.h>
20 #include <string.h>
22 #include "stat.h"
23 #include "tube.h"
24 #include "prot.h"
25 #include "util.h"
27 tube
28 make_tube(const char *name)
30 tube t;
32 t = malloc(sizeof(struct tube));
33 if (!t) return NULL;
35 t->refs = 0;
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 t->buried = (struct job) { &t->buried, &t->buried, 0 };
43 ms_init(&t->waiting, NULL, NULL);
45 t->stat = (struct stats) {0, 0, 0, 0};
46 t->using_ct = t->watching_ct = 0;
48 return t;
51 static void
52 tube_free(tube t)
54 prot_remove_tube(t);
55 pq_clear(&t->ready);
56 ms_clear(&t->waiting);
57 free(t);
60 void
61 tube_dref(tube t)
63 if (!t) return;
64 if (t->refs < 1) return twarnx("refs is zero for tube: %s", t->name);
66 --t->refs;
67 if (t->refs < 1) tube_free(t);
70 void
71 tube_iref(tube t)
73 if (!t) return;
74 ++t->refs;