--------------------- PatchSet 1806 Date: 2001/04/03 22:35:48 Author: akroonmaa Branch: chunked_mempools Tag: (none) Log: Moved funcs gb_flush gb_to_double and gb_to_str from src/tools.c to lib/util.c Need that later when split MemPool.c into worker under lib/ and Stats under src/ Had to update few .h files to reflect the change. Members: include/util.h:1.7->1.7.16.1 lib/util.c:1.7->1.7.20.1 src/defines.h:1.10->1.10.4.1 src/protos.h:1.23->1.23.4.1 src/squid.h:1.11->1.11.6.1 src/tools.c:1.11->1.11.8.1 src/typedefs.h:1.17->1.17.8.1 Index: squid/include/util.h =================================================================== RCS file: /cvsroot/squid-sf//squid/include/util.h,v retrieving revision 1.7 retrieving revision 1.7.16.1 diff -u -r1.7 -r1.7.16.1 --- squid/include/util.h 7 Feb 2001 19:11:47 -0000 1.7 +++ squid/include/util.h 3 Apr 2001 22:35:48 -0000 1.7.16.1 @@ -1,5 +1,5 @@ /* - * $Id: util.h,v 1.7 2001/02/07 19:11:47 hno Exp $ + * $Id: util.h,v 1.7.16.1 2001/04/03 22:35:48 akroonmaa Exp $ * * AUTHOR: Harvest Derived * @@ -127,6 +127,19 @@ double drand48(void); #endif +typedef struct { + size_t count; + size_t bytes; + size_t gb; +} gb_t; + +/* gb_type operations */ +#define gb_flush_limit (0x3FFFFFFF) +#define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; } +extern double gb_to_double(const gb_t *); +extern const char *gb_to_str(const gb_t *); +extern void gb_flush(gb_t *); /* internal, do not use this */ + /* * Returns the amount of known allocated memory */ Index: squid/lib/util.c =================================================================== RCS file: /cvsroot/squid-sf//squid/lib/util.c,v retrieving revision 1.7 retrieving revision 1.7.20.1 diff -u -r1.7 -r1.7.20.1 --- squid/lib/util.c 12 Jan 2001 08:20:31 -0000 1.7 +++ squid/lib/util.c 3 Apr 2001 22:35:48 -0000 1.7.20.1 @@ -1,6 +1,6 @@ /* - * $Id: util.c,v 1.7 2001/01/12 08:20:31 hno Exp $ + * $Id: util.c,v 1.7.20.1 2001/04/03 22:35:48 akroonmaa Exp $ * * DEBUG: * AUTHOR: Harvest Derived @@ -756,3 +756,40 @@ write(2, "\n", 1); abort(); } + +void +gb_flush(gb_t * g) +{ + g->gb += (g->bytes >> 30); + g->bytes &= (1 << 30) - 1; +} + +double +gb_to_double(const gb_t * g) +{ + return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); +} + +const char * +gb_to_str(const gb_t * g) +{ + /* + * it is often convenient to call gb_to_str several times for _one_ printf + */ +#define max_cc_calls 5 + typedef char GbBuf[32]; + static GbBuf bufs[max_cc_calls]; + static int call_id = 0; + double value = gb_to_double(g); + char *buf = bufs[call_id++]; + if (call_id >= max_cc_calls) + call_id = 0; + /* select format */ + if (value < 1e9) + snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); + else if (value < 1e12) + snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); + else + snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); + return buf; +} Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.10 retrieving revision 1.10.4.1 diff -u -r1.10 -r1.10.4.1 --- squid/src/defines.h 20 Mar 2001 01:16:29 -0000 1.10 +++ squid/src/defines.h 3 Apr 2001 22:35:48 -0000 1.10.4.1 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.10 2001/03/20 01:16:29 squidadm Exp $ + * $Id: defines.h,v 1.10.4.1 2001/04/03 22:35:48 akroonmaa Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -219,10 +219,6 @@ /* were to look for errors if config path fails */ #define DEFAULT_SQUID_ERROR_DIR "/usr/local/squid/etc/errors" -/* gb_type operations */ -#define gb_flush_limit (0x3FFFFFFF) -#define gb_inc(gb, delta) { if ((gb)->bytes > gb_flush_limit || delta > gb_flush_limit) gb_flush(gb); (gb)->bytes += delta; (gb)->count++; } - /* iteration for HttpHdrRange */ #define HttpHdrRangeInitPos (-1) Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.23 retrieving revision 1.23.4.1 diff -u -r1.23 -r1.23.4.1 --- squid/src/protos.h 30 Mar 2001 22:29:38 -0000 1.23 +++ squid/src/protos.h 3 Apr 2001 22:35:48 -0000 1.23.4.1 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.23 2001/03/30 22:29:38 squidadm Exp $ + * $Id: protos.h,v 1.23.4.1 2001/04/03 22:35:48 akroonmaa Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -1131,9 +1131,6 @@ extern dlink_node *dlinkNodeNew(void); extern void kb_incr(kb_t *, size_t); -extern double gb_to_double(const gb_t *); -extern const char *gb_to_str(const gb_t *); -extern void gb_flush(gb_t *); /* internal, do not use this */ extern int stringHasWhitespace(const char *); extern int stringHasCntl(const char *); extern void linklistPush(link_list **, void *); Index: squid/src/squid.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/squid.h,v retrieving revision 1.11 retrieving revision 1.11.6.1 diff -u -r1.11 -r1.11.6.1 --- squid/src/squid.h 11 Mar 2001 22:11:09 -0000 1.11 +++ squid/src/squid.h 3 Apr 2001 22:35:48 -0000 1.11.6.1 @@ -1,6 +1,6 @@ /* - * $Id: squid.h,v 1.11 2001/03/11 22:11:09 squidadm Exp $ + * $Id: squid.h,v 1.11.6.1 2001/04/03 22:35:48 akroonmaa Exp $ * * AUTHOR: Duane Wessels * @@ -387,6 +387,8 @@ #include "hash.h" #include "rfc1035.h" +#include "util.h" + #include "defines.h" #include "enums.h" #include "typedefs.h" @@ -394,7 +396,6 @@ #include "protos.h" #include "globals.h" -#include "util.h" /* * Mac OS X Server already has radix.h as a standard header, so Index: squid/src/tools.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/tools.c,v retrieving revision 1.11 retrieving revision 1.11.8.1 diff -u -r1.11 -r1.11.8.1 --- squid/src/tools.c 15 Feb 2001 21:09:17 -0000 1.11 +++ squid/src/tools.c 3 Apr 2001 22:35:48 -0000 1.11.8.1 @@ -1,6 +1,6 @@ /* - * $Id: tools.c,v 1.11 2001/02/15 21:09:17 hno Exp $ + * $Id: tools.c,v 1.11.8.1 2001/04/03 22:35:48 akroonmaa Exp $ * * DEBUG: section 21 Misc Functions * AUTHOR: Harvest Derived @@ -831,43 +831,6 @@ } void -gb_flush(gb_t * g) -{ - g->gb += (g->bytes >> 30); - g->bytes &= (1 << 30) - 1; -} - -double -gb_to_double(const gb_t * g) -{ - return ((double) g->gb) * ((double) (1 << 30)) + ((double) g->bytes); -} - -const char * -gb_to_str(const gb_t * g) -{ - /* - * it is often convenient to call gb_to_str several times for _one_ printf - */ -#define max_cc_calls 5 - typedef char GbBuf[32]; - static GbBuf bufs[max_cc_calls]; - static int call_id = 0; - double value = gb_to_double(g); - char *buf = bufs[call_id++]; - if (call_id >= max_cc_calls) - call_id = 0; - /* select format */ - if (value < 1e9) - snprintf(buf, sizeof(GbBuf), "%.2f MB", value / 1e6); - else if (value < 1e12) - snprintf(buf, sizeof(GbBuf), "%.2f GB", value / 1e9); - else - snprintf(buf, sizeof(GbBuf), "%.2f TB", value / 1e12); - return buf; -} - -void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm) { MemBuf mb; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.17 retrieving revision 1.17.8.1 diff -u -r1.17 -r1.17.8.1 --- squid/src/typedefs.h 1 Mar 2001 04:04:19 -0000 1.17 +++ squid/src/typedefs.h 3 Apr 2001 22:35:48 -0000 1.17.8.1 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.17 2001/03/01 04:04:19 hno Exp $ + * $Id: typedefs.h,v 1.17.8.1 2001/04/03 22:35:48 akroonmaa Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -46,12 +46,6 @@ size_t kb; } kb_t; -typedef struct { - size_t count; - size_t bytes; - size_t gb; -} gb_t; - /* * grep '^struct' structs.h \ * | perl -ne '($a,$b)=split;$c=$b;$c=~s/^_//; print "typedef struct $b $c;\n";'