summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_block_alloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/mysqlnd/mysqlnd_block_alloc.c')
-rw-r--r--ext/mysqlnd/mysqlnd_block_alloc.c31
1 files changed, 10 insertions, 21 deletions
diff --git a/ext/mysqlnd/mysqlnd_block_alloc.c b/ext/mysqlnd/mysqlnd_block_alloc.c
index 9a7fdae0f7..60e6f938ef 100644
--- a/ext/mysqlnd/mysqlnd_block_alloc.c
+++ b/ext/mysqlnd/mysqlnd_block_alloc.c
@@ -2,7 +2,7 @@
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
- | Copyright (c) 2006-2015 The PHP Group |
+ | Copyright (c) 2006-2016 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
@@ -12,14 +12,11 @@
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
- | Authors: Georg Richter <georg@mysql.com> |
- | Andrey Hristov <andrey@mysql.com> |
- | Ulf Wendel <uwendel@mysql.com> |
+ | Authors: Andrey Hristov <andrey@php.net> |
+ | Ulf Wendel <uw@php.net> |
+----------------------------------------------------------------------+
*/
-/* $Id$ */
-
#include "php.h"
#include "mysqlnd.h"
#include "mysqlnd_block_alloc.h"
@@ -29,9 +26,8 @@
/* {{{ mysqlnd_mempool_free_chunk */
static void
-mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk)
+mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk)
{
- MYSQLND_MEMORY_POOL * pool = chunk->pool;
DBG_ENTER("mysqlnd_mempool_free_chunk");
if (chunk->from_pool) {
/* Try to back-off and guess if this is the last block allocated */
@@ -42,7 +38,6 @@ mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk)
*/
pool->free_size += chunk->size;
}
- pool->refcount--;
} else {
mnd_efree(chunk->ptr);
}
@@ -54,11 +49,10 @@ mysqlnd_mempool_free_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk)
/* {{{ mysqlnd_mempool_resize_chunk */
static enum_func_status
-mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int size)
+mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL * pool, MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int size)
{
DBG_ENTER("mysqlnd_mempool_resize_chunk");
if (chunk->from_pool) {
- MYSQLND_MEMORY_POOL * pool = chunk->pool;
/* Try to back-off and guess if this is the last block allocated */
if (chunk->ptr == (pool->arena + (pool->arena_size - pool->free_size - chunk->size))) {
/*
@@ -75,8 +69,7 @@ mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int siz
chunk->ptr = new_ptr;
pool->free_size += chunk->size;
chunk->size = size;
- chunk->pool = NULL; /* now we have no pool memory */
- pool->refcount--;
+ chunk->from_pool = FALSE; /* now we have no pool memory */
} else {
/* If the chunk is > than asked size then free_memory increases, otherwise decreases*/
pool->free_size += (chunk->size - size);
@@ -94,8 +87,7 @@ mysqlnd_mempool_resize_chunk(MYSQLND_MEMORY_POOL_CHUNK * chunk, unsigned int siz
memcpy(new_ptr, chunk->ptr, chunk->size);
chunk->ptr = new_ptr;
chunk->size = size;
- chunk->pool = NULL; /* now we have non-pool memory */
- pool->refcount--;
+ chunk->from_pool = FALSE; /* now we have non-pool memory */
}
}
} else {
@@ -119,25 +111,21 @@ MYSQLND_MEMORY_POOL_CHUNK * mysqlnd_mempool_get_chunk(MYSQLND_MEMORY_POOL * pool
chunk = mnd_emalloc(sizeof(MYSQLND_MEMORY_POOL_CHUNK));
if (chunk) {
- chunk->free_chunk = mysqlnd_mempool_free_chunk;
- chunk->resize_chunk = mysqlnd_mempool_resize_chunk;
chunk->size = size;
/*
Should not go over MYSQLND_MAX_PACKET_SIZE, since we
expect non-arena memory in mysqlnd_wireprotocol.c . We
realloc the non-arena memory.
*/
- chunk->pool = pool;
if (size > pool->free_size) {
chunk->from_pool = FALSE;
chunk->ptr = mnd_emalloc(size);
if (!chunk->ptr) {
- chunk->free_chunk(chunk);
+ pool->free_chunk(pool, chunk);
chunk = NULL;
}
} else {
chunk->from_pool = TRUE;
- ++pool->refcount;
chunk->ptr = pool->arena + (pool->arena_size - pool->free_size);
/* Last step, update free_size */
pool->free_size -= size;
@@ -157,8 +145,9 @@ mysqlnd_mempool_create(size_t arena_size)
DBG_ENTER("mysqlnd_mempool_create");
if (ret) {
ret->get_chunk = mysqlnd_mempool_get_chunk;
+ ret->free_chunk = mysqlnd_mempool_free_chunk;
+ ret->resize_chunk = mysqlnd_mempool_resize_chunk;
ret->free_size = ret->arena_size = arena_size ? arena_size : 0;
- ret->refcount = 0;
/* OOM ? */
ret->arena = mnd_emalloc(ret->arena_size);
if (!ret->arena) {