|
Atrinik Server 2.5
|
00001 /************************************************************************ 00002 * Atrinik, a Multiplayer Online Role Playing Game * 00003 * * 00004 * Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team * 00005 * * 00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game) * 00007 * and Crossfire (Multiplayer game for X-windows). * 00008 * * 00009 * This program is free software; you can redistribute it and/or modify * 00010 * it under the terms of the GNU General Public License as published by * 00011 * the Free Software Foundation; either version 2 of the License, or * 00012 * (at your option) any later version. * 00013 * * 00014 * This program is distributed in the hope that it will be useful, * 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00017 * GNU General Public License for more details. * 00018 * * 00019 * You should have received a copy of the GNU General Public License * 00020 * along with this program; if not, write to the Free Software * 00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00022 * * 00023 * The author can be reached at admin@atrinik.org * 00024 ************************************************************************/ 00025 00030 #ifndef SHSTR_H 00031 #define SHSTR_H 00032 00035 #define TABLESIZE 8266 00036 00037 /* 00038 * This will make the shared string interface more secure by checking for 00039 * valid string before manipulating them, but also somewhat slower. 00040 * 00041 * Should only be used for debugging purposes. */ 00042 /*#define SECURE_SHSTR_HASH*/ 00043 00048 #ifndef MAXSTRING 00049 #define MAXSTRING 20 00050 #endif 00051 00057 #define REFCOUNT_TYPE long 00058 00059 /* The offsetof macro is part of ANSI C, but many compilers lack it, for 00060 * example "gcc -ansi" */ 00061 #if !defined(offsetof) 00062 #define offsetof(type, member) (int)&(((type *)0)->member) 00063 #endif 00064 00068 #define SS(x) ((shared_string *) ((x) - offsetof(shared_string, string))) 00069 00070 #define SS_DUMP_TABLE 1 00071 #define SS_DUMP_TOTALS 2 00072 00073 #ifdef SS_STATISTICS 00074 00075 static struct statistics 00076 { 00077 int calls; 00078 int hashed; 00079 int strcmps; 00080 int search; 00081 int linked; 00082 } add_stats, add_ref_stats, free_stats, find_stats, hash_stats; 00083 00084 #define GATHER(n) (++n) 00085 #else 00086 #define GATHER(n) 00087 #endif 00088 00089 #define TOPBIT ((unsigned REFCOUNT_TYPE) 1 << (sizeof(REFCOUNT_TYPE) * CHAR_BIT - 1)) 00090 00091 #define PADDING ((2 * sizeof(long) - sizeof(REFCOUNT_TYPE)) % sizeof(long)) + 1 00092 00095 typedef struct _shared_string 00096 { 00097 union 00098 { 00099 struct _shared_string **array; 00100 00101 struct _shared_string *previous; 00102 } u; 00103 00105 struct _shared_string *next; 00106 00110 unsigned REFCOUNT_TYPE refcount; 00111 00116 char string[PADDING]; 00117 } shared_string; 00118 00119 #endif
1.7.4