chiark / gitweb /
fwd: Improve `source' and `target' lifecycle management.
[fwd] / target.c
CommitLineData
57ceb980
MW
1/* -*-c-*-
2 *
3 * Common functionality for targets
4 *
5 * (c) 2018 Straylight/Edgeware
6 */
7
8/*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of the `fwd' port forwarder.
11 *
12 * `fwd' is free software: you can redistribute it and/or modify it under
13 * the terms of the GNU General Public License as published by the Free
14 * Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * `fwd' is distributed in the hope that it will be useful, but WITHOUT
18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 * for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with `fwd'. If not, write to the Free Software Foundation,
24 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27/*----- Header files ------------------------------------------------------*/
28
29#include "fwd.h"
30
31/*----- Main code ---------------------------------------------------------*/
32
33/* --- @target_inc@ --- *
34 *
35 * Arguments: @target *t@ = pointer to a source
36 *
37 * Returns: ---
38 *
39 * Use: Increments a target's refcount.
40 */
41
42void target_inc(target *t) { t->ref++; }
43
44/* --- @target_dec@ --- *
45 *
46 * Arguments: @target *t@ = pointer to a target
47 *
48 * Returns: ---
49 *
50 * Use: Decrements a target's refcount, destroying it if necessary.
51 */
52
53void target_dec(target *t)
54{
55 assert(t->ref > 0);
56 t->ref--;
57 if (!t->ref) t->ops->destroy(t);
58}
59
60/*----- That's all, folks -------------------------------------------------*/