project_files/frontlib/util/refcounter.h
changeset 7497 7e1d72fc03c7
parent 7494 e65adfc99f15
child 7500 6253cae96f21
equal deleted inserted replaced
7494:e65adfc99f15 7497:7e1d72fc03c7
     1 /*
       
     2  * Hedgewars, a free turn based strategy game
       
     3  * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or
       
     6  * modify it under the terms of the GNU General Public License
       
     7  * as published by the Free Software Foundation; either version 2
       
     8  * of the License, or (at your option) any later version.
       
     9  *
       
    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.
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License
       
    16  * along with this program; if not, write to the Free Software
       
    17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    18  */
       
    19 
       
    20 /**
       
    21  * Helper functions for reference counted structs.
       
    22  *
       
    23  * We don't have enough of them to justify going crazy with macros, but I still prefer
       
    24  * to have the logic in one place.
       
    25  *
       
    26  * In particular, these functions handle counter overflow in a sensible way
       
    27  * (log and leak).
       
    28  */
       
    29 
       
    30 #ifndef REFCOUNTER_H_
       
    31 #define REFCOUNTER_H_
       
    32 
       
    33 #include <stdbool.h>
       
    34 
       
    35 /**
       
    36  * Pass a pointer to the counter variable to be incremented, and the name of the
       
    37  * object for logging purposes. On overflow an error will be logged and the
       
    38  * counter will get "stuck" so neither retain nor release will modify it anymore.
       
    39  */
       
    40 void flib_retain(int *referenceCountPtr, const char *objName);
       
    41 
       
    42 /**
       
    43  * Pass a pointer to the counter variable to be decremented and the name
       
    44  * of the object for logging purposes.
       
    45  * Returns true if the object should be freed.
       
    46  */
       
    47 bool flib_release(int *referenceCountPtr, const char *objName);
       
    48 
       
    49 #endif /* REFCOUNTER_H_ */