00001 /* Part of the culibs project, <http://www.eideticdew.org/culibs/>. 00002 * Copyright (C) 2006--2010 Petter Urkedal <paurkedal@eideticdew.org> 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef CUOO_HCOBJ_H 00019 #define CUOO_HCOBJ_H 00020 00021 #include <cuoo/fwd.h> 00022 #include <cu/conf.h> 00023 #include <cu/inherit.h> 00024 #include <atomic_ops.h> 00025 00026 CU_BEGIN_DECLARATIONS 00027 /** \defgroup cuoo_hcobj_h cuoo/hcobj.h: Hash-consed Object Headers 00028 ** @{ \ingroup cuoo_mod 00029 ** 00030 ** This header defines a macro \ref CUOO_HCOBJ to put right after the opening 00031 ** brace of a hash-consed object struct: 00032 ** \code 00033 ** struct my_obj { 00034 ** CUOO_HCOBJ 00035 ** ... key fields ... 00036 ** ... value fields if present ... 00037 ** }; 00038 ** \endcode 00039 ** Note that there is no semicolon after the macro. A macro is used here, 00040 ** because the need for this field depends on the configuration. 00041 ** 00042 ** \def CUOO_HCOBJ 00043 ** Put this on the top of struct which define hash-consed objects, leaving out 00044 ** semicolon. 00045 ** 00046 ** \def CUOO_HCOBJ_SHIFT 00047 ** The offset of the key-part of a hash-consed object struct. 00048 **/ 00049 00050 typedef struct cuooP_hcobj *cuooP_hcobj_t; 00051 00052 #ifdef CUCONF_ENABLE_HASHCONS_DISCLAIM_OLD 00053 00054 # define CUOO_HC_GENERATION 0 00055 # define CUOO_HCOBJ_NEEDED 1 00056 00057 # define CUOO_HCOBJ CUOO_OBJ cu_inherit (cuooP_hcobj); 00058 # define CUOO_HCOBJ_SHIFT sizeof(struct cuooP_hcobj) 00059 # define CUOO_HCOBJ_INIT CUOO_OBJ_INIT { 0 }, 00060 00061 struct cuooP_hcobj 00062 { 00063 AO_t hcset_next; 00064 # if CUOO_HC_GENERATION 00065 AO_t generation; 00066 # endif 00067 }; 00068 00069 #else /* !CUCONF_ENABLE_HASHCONS_DISCLAIM_OLD */ 00070 00071 # define CUOO_HCOBJ 00072 # define CUOO_HCOBJ_SHIFT 0 00073 # define CUOO_HCOBJ_INIT 00074 00075 #endif /* !CUCONF_ENABLE_HASHCONS_DISCLAIM_OLD */ 00076 00077 #define CUOO_HCOBJ_SHIFTW (CUOO_HCOBJ_SHIFT/CU_WORD_SIZE) 00078 #define CUOO_HCOBJ_KEY(obj) ((void *)((char *)(obj) + CUOO_HCOBJ_SHIFT)) 00079 00080 /** @} */ 00081 CU_END_DECLARATIONS 00082 00083 #endif