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.
19 FILE_LICENCE ( GPL2_OR_LATER );
22 #include <gpxe/refcnt.h>
31 * Increment reference count
33 * @v refcnt Reference counter, or NULL
34 * @ret refcnt Reference counter
36 * If @c refcnt is NULL, no action is taken.
38 struct refcnt * ref_get ( struct refcnt *refcnt ) {
42 DBGC2 ( refcnt, "REFCNT %p incremented to %d\n",
43 refcnt, refcnt->refcnt );
49 * Decrement reference count
51 * @v refcnt Reference counter, or NULL
53 * If the reference count decreases below zero, the object's free()
54 * method will be called.
56 * If @c refcnt is NULL, no action is taken.
58 void ref_put ( struct refcnt *refcnt ) {
64 DBGC2 ( refcnt, "REFCNT %p decremented to %d\n",
65 refcnt, refcnt->refcnt );
67 if ( refcnt->refcnt >= 0 )
71 DBGC ( refcnt, "REFCNT %p being freed via method %p\n",
72 refcnt, refcnt->free );
73 refcnt->free ( refcnt );
75 DBGC ( refcnt, "REFCNT %p being freed\n", refcnt );