diff options
Diffstat (limited to 'lib/isc')
| -rw-r--r-- | lib/isc/api | 6 | ||||
| -rw-r--r-- | lib/isc/include/isc/mem.h | 12 | ||||
| -rw-r--r-- | lib/isc/mem.c | 36 | 
3 files changed, 47 insertions, 7 deletions
diff --git a/lib/isc/api b/lib/isc/api index e55996b2690b..823f692fe3c4 100644 --- a/lib/isc/api +++ b/lib/isc/api @@ -1,3 +1,3 @@ -LIBINTERFACE = 52 -LIBREVISION = 1 -LIBAGE = 2 +LIBINTERFACE = 53 +LIBREVISION = 0 +LIBAGE = 3 diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index 480a934078ed..b49d4402a075 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -1,5 +1,5 @@  /* - * Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2010  Internet Systems Consortium, Inc. ("ISC")   * Copyright (C) 1997-2001  Internet Software Consortium.   *   * Permission to use, copy, modify, and/or distribute this software for any @@ -15,7 +15,7 @@   * PERFORMANCE OF THIS SOFTWARE.   */ -/* $Id: mem.h,v 1.78.120.3 2009/02/11 03:07:01 jinmei Exp $ */ +/* $Id: mem.h,v 1.78.120.3.24.2 2010/08/12 23:46:25 tbox Exp $ */  #ifndef ISC_MEM_H  #define ISC_MEM_H 1 @@ -334,6 +334,14 @@ isc_mem_inuse(isc_mem_t *mctx);   * allocated from the system but not yet used.   */ +isc_boolean_t +isc_mem_isovermem(isc_mem_t *mctx); +/*%< + * Return true iff the memory context is in "over memory" state, i.e., + * a hiwater mark has been set and the used amount of memory has exceeds + * the mark. + */ +  void  isc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,  		 size_t hiwater, size_t lowater); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 9c37d7478bdb..59f59241b84d 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -1,5 +1,5 @@  /* - * Copyright (C) 2004-2009  Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004-2010  Internet Systems Consortium, Inc. ("ISC")   * Copyright (C) 1997-2003  Internet Software Consortium.   *   * Permission to use, copy, modify, and/or distribute this software for any @@ -15,7 +15,7 @@   * PERFORMANCE OF THIS SOFTWARE.   */ -/* $Id: mem.c,v 1.145.120.4 2009/02/16 03:17:05 marka Exp $ */ +/* $Id: mem.c,v 1.145.120.4.24.2 2010/08/12 23:46:25 tbox Exp $ */  /*! \file */ @@ -141,6 +141,7 @@ struct isc_mem {  	size_t			hi_water;  	size_t			lo_water;  	isc_boolean_t		hi_called; +	isc_boolean_t		is_overmem;  	isc_mem_water_t		water;  	void *			water_arg;  	ISC_LIST(isc_mempool_t)	pools; @@ -764,6 +765,7 @@ isc_mem_createx2(size_t init_max_size, size_t target_size,  	ctx->hi_water = 0;  	ctx->lo_water = 0;  	ctx->hi_called = ISC_FALSE; +	ctx->is_overmem = ISC_FALSE;  	ctx->water = NULL;  	ctx->water_arg = NULL;  	ctx->magic = MEM_MAGIC; @@ -1102,6 +1104,10 @@ isc__mem_get(isc_mem_t *ctx, size_t size FLARG) {  	}  	ADD_TRACE(ctx, ptr, size, file, line); +	if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water && +	    !ctx->is_overmem) { +		ctx->is_overmem = ISC_TRUE; +	}  	if (ctx->hi_water != 0U && !ctx->hi_called &&  	    ctx->inuse > ctx->hi_water) {  		call_water = ISC_TRUE; @@ -1159,6 +1165,10 @@ isc__mem_put(isc_mem_t *ctx, void *ptr, size_t size FLARG)  	 * when the context was pushed over hi_water but then had  	 * isc_mem_setwater() called with 0 for hi_water and lo_water.  	 */ +	if (ctx->is_overmem && +	    (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) { +		ctx->is_overmem = ISC_FALSE; +	}  	if (ctx->hi_called &&  	    (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) {  		if (ctx->water != NULL) @@ -1345,6 +1355,11 @@ isc__mem_allocate(isc_mem_t *ctx, size_t size FLARG) {  #if ISC_MEM_TRACKLINES  	ADD_TRACE(ctx, si, si[-1].u.size, file, line);  #endif +	if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water && +	    !ctx->is_overmem) { +		ctx->is_overmem = ISC_TRUE; +	} +  	if (ctx->hi_water != 0U && !ctx->hi_called &&  	    ctx->inuse > ctx->hi_water) {  		ctx->hi_called = ISC_TRUE; @@ -1433,6 +1448,11 @@ isc__mem_free(isc_mem_t *ctx, void *ptr FLARG) {  	 * when the context was pushed over hi_water but then had  	 * isc_mem_setwater() called with 0 for hi_water and lo_water.  	 */ +	if (ctx->is_overmem && +	    (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) { +		ctx->is_overmem = ISC_FALSE; +	} +  	if (ctx->hi_called &&  	    (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) {  		ctx->hi_called = ISC_FALSE; @@ -1559,6 +1579,18 @@ isc_mem_setwater(isc_mem_t *ctx, isc_mem_water_t water, void *water_arg,  		(oldwater)(oldwater_arg, ISC_MEM_LOWATER);  } +isc_boolean_t +isc_mem_isovermem(isc_mem_t *ctx) { +	REQUIRE(VALID_CONTEXT(ctx)); + +	/* +	 * We don't bother to lock the context because 100% accuracy isn't +	 * necessary (and even if we locked the context the returned value +	 * could be different from the actual state when it's used anyway) +	 */ +	return (ctx->is_overmem); +} +  void  isc_mem_setname(isc_mem_t *ctx, const char *name, void *tag) {  	REQUIRE(VALID_CONTEXT(ctx));  | 
