2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <gpxe/refcnt.h>
29 * Increment reference count
31 * @v refcnt Reference counter, or NULL
32 * @ret refcnt Reference counter
34 * If @c refcnt is NULL, no action is taken.
36 struct refcnt
* ref_get ( struct refcnt
*refcnt
) {
40 DBGC2 ( refcnt
, "REFCNT %p incremented to %d\n",
41 refcnt
, refcnt
->refcnt
);
47 * Decrement reference count
49 * @v refcnt Reference counter, or NULL
51 * If the reference count decreases below zero, the object's free()
52 * method will be called.
54 * If @c refcnt is NULL, no action is taken.
56 void ref_put ( struct refcnt
*refcnt
) {
62 DBGC2 ( refcnt
, "REFCNT %p decremented to %d\n",
63 refcnt
, refcnt
->refcnt
);
65 if ( refcnt
->refcnt
>= 0 )
69 DBGC ( refcnt
, "REFCNT %p being freed via method %p\n",
70 refcnt
, refcnt
->free
);
71 refcnt
->free ( refcnt
);
73 DBGC ( refcnt
, "REFCNT %p being freed\n", refcnt
);