Author: ahristov
Date: 2007-03-28 15:28:43 +0200 (Wed, 28 Mar 2007)
New Revision: 285
Modified:
trunk/ext/mysqli/mysqli.c
trunk/ext/mysqli/mysqlnd/mysqlnd.c
trunk/ext/mysqli/mysqlnd/mysqlnd.h
trunk/ext/mysqli/mysqlnd/mysqlnd_palloc.c
trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c
trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.c
trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.h
Log:
Refactor the code "a bit"
Modified: trunk/ext/mysqli/mysqli.c
===================================================================
--- trunk/ext/mysqli/mysqli.c 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqli.c 2007-03-28 13:28:43 UTC (rev 285)
@@ -546,6 +546,7 @@
#ifdef HAVE_MYSQLND
mysqlnd_library_init();
MyG(mysqlnd_zval_cache) = mysqlnd_palloc_init_cache(MyG(cache_size));
+ MyG(mysqlnd_qcache) = mysqlnd_qcache_init_cache();
#endif
memcpy(&mysqli_object_handlers, zend_get_std_object_handlers(),
sizeof(zend_object_handlers));
@@ -729,6 +730,7 @@
zend_hash_destroy(&classes);
#ifdef HAVE_MYSQLND
mysqlnd_palloc_free_cache_reference(&(MyG(mysqlnd_zval_cache)));
+ mysqlnd_qcache_free_cache_reference(&(MyG(mysqlnd_qcache)));
mysqlnd_library_end();
#endif
UNREGISTER_INI_ENTRIES();
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd.c 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd.c 2007-03-28 13:28:43 UTC (rev 285)
@@ -95,15 +95,15 @@
/* {{{ php_mysqlnd_free_field_metadata */
static
-void php_mysqlnd_free_field_metadata(MYSQLND_FIELD *meta)
+void php_mysqlnd_free_field_metadata(MYSQLND_FIELD *meta, zend_bool persistent)
{
if (meta) {
if (meta->root) {
- efree(meta->root);
+ pefree(meta->root, persistent);
meta->root = NULL;
}
if (meta->def) {
- efree(meta->def);
+ pefree(meta->def, persistent);
meta->def = NULL;
}
}
@@ -156,24 +156,27 @@
/* {{{ mysqlnd_free_buffered_data */
void mysqlnd_free_buffered_data(MYSQLND_RES *result TSRMLS_DC)
{
- zval **current_row;
- zend_uchar *current_buffer;
+ MYSQLND_ZVAL_PCACHE *zval_cache = result->zval_cache;
MYSQLND_RES_BUFFERED *set = result->data;
- int i, j;
+ enum_mysqlnd_res_type result_type = result->type;
+ unsigned int field_count = result->field_count;
+ unsigned int row;
- for (i = 0; i < result->data->row_count; i++) {
- current_row = set->data[i];
- current_buffer = set->row_buffers[i];
- for (j = 0; j < result->field_count; j++) {
- if (result->type == MYSQLND_RES_PS) {
+ for (row = 0; row < result->data->row_count; row++) {
+ unsigned int col;
+ zval **current_row = current_row = set->data[row];
+ zend_uchar *current_buffer = set->row_buffers[row];
+
+ for (col = 0; col < field_count; col++) {
+ if (result_type == MYSQLND_RES_PS) {
/* For now PS always does create copies when fetching data */
- zval_ptr_dtor(¤t_row[j]);
+ zval_ptr_dtor(¤t_row[col]);
MYSQLND_INC_CONN_STATISTIC(NULL, STAT_COPY_ON_WRITE_PERFORMED);
} else {
zend_bool copy_ctor_called;
/* Free only if we haven't referenced it */
- mysqlnd_palloc_zval_ptr_dtor(&(current_row[j]), result->zval_cache,
+ mysqlnd_palloc_zval_ptr_dtor(&(current_row[col]), zval_cache,
FALSE, ©_ctor_called TSRMLS_CC);
MYSQLND_INC_CONN_STATISTIC(NULL, copy_ctor_called? STAT_COPY_ON_WRITE_PERFORMED:
@@ -189,7 +192,9 @@
set->row_buffers = NULL;
set->data_cursor = NULL;
set->row_count = 0;
-
+ if (set->persistent) {
+ mysqlnd_qcache_free_cache_reference(&set->qcache);
+ }
pefree(set, set->persistent);
result->data = NULL;
}
@@ -220,40 +225,34 @@
/* {{{ mysqlnd_internal_free_result_metadata */
static
-void mysqlnd_internal_free_result_metadata(MYSQLND_RES *result TSRMLS_DC)
+void mysqlnd_internal_free_result_metadata(MYSQLND_RES_METADATA *meta, zend_bool
persistent TSRMLS_DC)
{
int i;
- MYSQLND_RES_METADATA *meta = result->meta;
MYSQLND_FIELD *fields;
- if (!meta) {
- return;
- }
-
if ((fields = meta->fields)) {
- i = result->field_count;
+ i = meta->field_count;
while (i--) {
- php_mysqlnd_free_field_metadata(fields++);
+ php_mysqlnd_free_field_metadata(fields++, persistent);
}
- efree(meta->fields);
+ pefree(meta->fields, persistent);
meta->fields = NULL;
}
if (meta->zend_hash_keys) {
#if PHP_MAJOR_VERSION >= 6
if (UG(unicode)) {
- for (i = 0; i < result->field_count; i++) {
+ for (i = 0; i < meta->field_count; i++) {
if (meta->zend_hash_keys[i].ustr.v) {
- efree(meta->zend_hash_keys[i].ustr.v);
+ pefree(meta->zend_hash_keys[i].ustr.v, persistent);
}
}
}
#endif
- efree(meta->zend_hash_keys);
+ pefree(meta->zend_hash_keys, persistent);
meta->zend_hash_keys = NULL;
}
- efree(result->meta);
- result->meta = NULL;
+ pefree(meta, persistent);
}
/* }}} */
@@ -275,7 +274,10 @@
result->conn = NULL;
- mysqlnd_internal_free_result_metadata(result TSRMLS_CC);
+ if (result->meta) {
+ mysqlnd_internal_free_result_metadata(result->meta, FALSE TSRMLS_CC);
+ result->meta = NULL;
+ }
if (result->zval_cache) {
mysqlnd_palloc_free_cache_reference(&result->zval_cache);
@@ -394,6 +396,10 @@
mysqlnd_palloc_free_cache_reference(&conn->zval_cache);
conn->zval_cache = NULL;
}
+ if (conn->qcache) {
+ mysqlnd_qcache_free_cache_reference(&conn->qcache);
+ conn->qcache = NULL;
+ }
if (conn->net.cmd_buffer.buffer) {
pefree(conn->net.cmd_buffer.buffer, conn->persistent);
conn->net.cmd_buffer.buffer = NULL;
@@ -928,10 +934,14 @@
(select *) with altered table. Also for statements which skip the PS
infrastructure.
*/
- mysqlnd_internal_free_result_metadata(result TSRMLS_CC);
+ if (result->meta) {
+ mysqlnd_internal_free_result_metadata(result->meta, FALSE TSRMLS_CC);
+ result->meta = NULL;
+ }
/* +1 is to have empty marker at the end */
result->meta = ecalloc(1, sizeof(MYSQLND_RES_METADATA));
+ result->meta->field_count = result->field_count;
result->meta->fields = ecalloc(result->field_count + 1, sizeof(MYSQLND_FIELD));
result->meta->zend_hash_keys = ecalloc(result->field_count,
sizeof(struct mysqlnd_field_hash_key));
@@ -1397,7 +1407,7 @@
result->row_packet->field_count = result->field_count;
result->row_packet->binary_protocol = FALSE;
result->row_packet->fields_metadata = result->meta->fields;
- result->lengths = emalloc(result->field_count * sizeof(unsigned long));
+ result->lengths = ecalloc(result->field_count, sizeof(unsigned long));
/* No multithreading issues as we don't share the connection :) */
@@ -1514,7 +1524,7 @@
conn->state = CONN_FETCHING_DATA;
- result->lengths = emalloc(result->field_count * sizeof(unsigned long));
+ result->lengths = ecalloc(result->field_count, sizeof(unsigned long));
/* Create room for 'next_extend' rows */
@@ -1523,7 +1533,10 @@
result->data->data = pemalloc(next_extend * sizeof(zval **), to_cache);
result->data->row_buffers = pemalloc(next_extend * sizeof(zend_uchar *),
to_cache);
result->data->persistent = to_cache;
+ result->data->qcache = to_cache?
mysqlnd_qcache_get_cache_reference(conn->qcache):NULL;
+ result->data->references = 1;
+
free_rows = next_extend;
PACKET_INIT_ALLOCA(row_packet, PROT_ROW_PACKET);
@@ -1583,7 +1596,15 @@
conn->upsert_status.server_status = row_packet.server_status;
}
PACKET_FREE_ALLOCA(row_packet);
- /* We can realloc here to save some memory, if free_rows > 0 ?*/
+ /* save some memory */
+ if (free_rows) {
+ result->data->data = perealloc(result->data->data,
+ result->data->row_count * sizeof(zval **),
+ to_cache);
+ result->data->row_buffers = perealloc(result->data->row_buffers,
+ result->data->row_count * sizeof(zend_uchar *),
+ to_cache);
+ }
if (conn->upsert_status.server_status & SERVER_MORE_RESULTS_EXISTS) {
conn->state = CONN_NEXT_RESULT_PENDING;
@@ -2551,6 +2572,61 @@
/* }}} */
+/* {{{ mysqlnd_result_metadata_clone_metadata */
+static
+MYSQLND_RES_METADATA * _mysqlnd_clone_metadata(const MYSQLND_RES_METADATA * const meta,
zend_bool persistent)
+{
+ unsigned int i;
+ /* +1 is to have empty marker at the end */
+ MYSQLND_RES_METADATA *new_meta = pemalloc(sizeof(MYSQLND_RES_METADATA), persistent);
+ MYSQLND_FIELD *new_fields = pecalloc(meta->field_count + 1, sizeof(MYSQLND_FIELD),
persistent);
+ MYSQLND_FIELD *original_fields = meta->fields;
+ size_t len = meta->field_count * sizeof(struct mysqlnd_field_hash_key);
+
+ new_meta->zend_hash_keys = pemalloc(len, persistent);
+ memcpy(new_meta->zend_hash_keys, meta->zend_hash_keys, len);
+
+ /*
+ This will copy also the strings and the root, which we will have
+ to adjust in the loop
+ */
+ memcpy(new_fields, original_fields, (meta->field_count) * sizeof(MYSQLND_FIELD));
+ for (i = 0; i < meta->field_count; i++) {
+ /* First copy the root, then field by field adjust the pointers */
+ new_fields[i].root = pemalloc(original_fields[i].root_len, persistent);
+ memcpy(new_fields[i].root, original_fields[i].root, new_fields[i].root_len);
+
+ new_fields[i].name = new_fields[i].root + (original_fields[i].name -
original_fields[i].root);
+ new_fields[i].org_name = new_fields[i].root + (original_fields[i].org_name -
original_fields[i].root);
+
+ new_fields[i].table = new_fields[i].root + (original_fields[i].table -
original_fields[i].root);
+ new_fields[i].org_table = new_fields[i].root + (original_fields[i].org_table -
original_fields[i].root);
+
+ new_fields[i].db = new_fields[i].root + (original_fields[i].db -
original_fields[i].root);
+ new_fields[i].catalog = new_fields[i].root + (original_fields[i].catalog -
original_fields[i].root);
+ /* def is not on the root, if allocated at all */
+ if (original_fields[i].def) {
+ new_fields[i].def = pemalloc(original_fields[i].def_length + 1, persistent);
+ /* copy the trailing \0 too */
+ memcpy(new_fields[i].def, original_fields[i].def, original_fields[i].def_length + 1);
+ }
+#if PHP_MAJOR_VERSION >= 6
+ if (new_meta->zend_hash_keys[i].ustr.u) {
+ new_meta->zend_hash_keys[i].ustr.u =
+ eustrndup(new_meta->zend_hash_keys[i].ustr.u,
new_meta->zend_hash_keys[i].ulen);
+ }
+#endif
+ }
+ new_meta->current_field = 0;
+ new_meta->field_count = meta->field_count;
+
+ new_meta->fields = new_fields;
+
+ return new_meta;
+}
+/* }}} */
+
+
MYSQLND_STMT * _mysqlnd_stmt_init(MYSQLND * const conn);
@@ -2628,6 +2704,7 @@
ret->field_count = field_count;
ret->zval_cache = cache;
ret->m.free_result = _mysqlnd_free_result;
+ ret->m.clone_metadata = _mysqlnd_clone_metadata;
ret->m.free_result_buffers = mysqlnd_internal_free_result_buffers;
ret->m.seek_data = _mysqlnd_data_seek;
ret->m.skip_result = _mysqlnd_unbuffered_skip_result;
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.h
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd.h 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd.h 2007-03-28 13:28:43 UTC (rev 285)
@@ -478,7 +478,11 @@
typedef struct st_mysqlnd_result_bind MYSQLND_RESULT_BIND;
+typedef struct st_mysqlnd_result_metadata MYSQLND_RES_METADATA;
+typedef struct st_mysqlnd_buffered_result MYSQLND_RES_BUFFERED;
+typedef struct st_mysqlnd_unbuffered_result MYSQLND_RES_UNBUFFERED;
+
typedef MYSQLND_RES* (*mysqlnd_stmt_use_or_store_func)(MYSQLND_STMT * const TSRMLS_DC);
typedef enum_func_status (*mysqlnd_fetch_row_func)(MYSQLND_RES *result,
void *param,
@@ -576,6 +580,8 @@
unsigned long * (*fetch_lengths)(MYSQLND_RES * const result);
void (*free_result_buffers)(MYSQLND_RES * result TSRMLS_DC); /* private */
enum_func_status (*free_result)(MYSQLND_RES * result, zend_bool implicit TSRMLS_DC);
+
+ MYSQLND_RES_METADATA * (*clone_metadata)(const MYSQLND_RES_METADATA * const meta,
zend_bool persistent);/* private */
};
@@ -678,6 +684,9 @@
/* zval cache */
MYSQLND_ZVAL_PCACHE *zval_cache;
+ /* qcache */
+ MYSQLND_QCACHE *qcache;
+
/* stats */
MYSQLND_STATS stats;
@@ -697,30 +706,34 @@
};
-typedef struct st_mysqlnd_result_metadata {
+struct st_mysqlnd_result_metadata {
MYSQLND_FIELD *fields;
struct mysqlnd_field_hash_key *zend_hash_keys;
unsigned int current_field;
-} MYSQLND_RES_METADATA;
+ unsigned int field_count;
+};
-typedef struct st_mysqlnd_buffered_result {
+struct st_mysqlnd_buffered_result {
zval ***data;
zval ***data_cursor;
zend_uchar **row_buffers;
mynd_ulonglong row_count;
zend_bool persistent;
-} MYSQLND_RES_BUFFERED;
+ MYSQLND_QCACHE *qcache;
+ unsigned int references;
+};
-typedef struct st_mysqlnd_unbuffered_result {
+
+struct st_mysqlnd_unbuffered_result {
/* For unbuffered (both normal and PS) */
zval **last_row_data;
zend_uchar *last_row_buffer;
mynd_ulonglong row_count;
zend_bool eof_reached;
-} MYSQLND_RES_UNBUFFERED;
+};
@@ -1006,6 +1019,36 @@
void * mysqlnd_palloc_get_zval(MYSQLND_ZVAL_PCACHE * const cache, zend_bool
*allocated);
void mysqlnd_palloc_zval_ptr_dtor(zval **zv, MYSQLND_ZVAL_PCACHE * const cache,
zend_bool ps,
zend_bool *copy_ctor_called TSRMLS_DC);
+
+
+
+/* ---------------------- QUERY CACHE ---------------*/
+struct st_mysqlnd_qcache {
+ HashTable *ht;
+ unsigned int references;
+#ifdef ZTS
+ MUTEX_T LOCK_access;
+#endif
+};
+
+
+typedef struct st_mysqlnd_qcache_element {
+ MYSQLND_RES_BUFFERED *data;
+ MYSQLND_RES_METADATA *meta;
+ const char * query;
+ size_t query_len;
+} MYSQLND_QCACHE_ELEMENT;
+
+
+PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_init_cache();
+PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache);
+PHPAPI void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache);
+PHPAPI void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval
*return_value);
+MYSQLND_RES * mysqlnd_qcache_get(MYSQLND_QCACHE * const cache, const char * query,
+ size_t query_len);
+void mysqlnd_qcache_put(MYSQLND_QCACHE * const cache, char * query, size_t query_len,
+ MYSQLND_RES_BUFFERED * const result, MYSQLND_RES_METADATA * const meta);
+
#endif /* MYSQLND_H */
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_palloc.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_palloc.c 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_palloc.c 2007-03-28 13:28:43 UTC (rev 285)
@@ -130,19 +130,20 @@
/* {{{ mysqlnd_palloc_free_cache_reference */
PHPAPI void mysqlnd_palloc_free_cache_reference(MYSQLND_ZVAL_PCACHE **cache)
{
+ if (*cache) {
+ zend_bool to_free;
#ifndef MYSQLND_SILENT
- php_printf("[mysqlnd_palloc_free_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
+ php_printf("[mysqlnd_palloc_free_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
#endif
- LOCK_PCACHE(*cache);
- if (*cache && --(*cache)->references == 0) {
+ LOCK_PCACHE(*cache);
+ to_free = --(*cache)->references == 0;
/* Unlock before destroying */
UNLOCK_PCACHE(*cache);
- mysqlnd_palloc_free_cache(*cache);
- } else {
- UNLOCK_PCACHE(*cache);
- }
-
- *cache = NULL;
+ if (to_free) {
+ mysqlnd_palloc_free_cache(*cache);
+ }
+ *cache = NULL;
+ }
}
/* }}} */
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_ps.c 2007-03-28 13:28:43 UTC (rev 285)
@@ -1153,61 +1153,6 @@
/* }}} */
-/* {{{ mysqlnd_result_metadata_clone_metadata */
-static
-MYSQLND_RES_METADATA * mysqlnd_result_metadata_clone_metadata(MYSQLND_RES * const result)
-{
- unsigned int i;
- /* +1 is to have empty marker at the end */
- MYSQLND_RES_METADATA *ret = emalloc(sizeof(MYSQLND_RES_METADATA));
- MYSQLND_FIELD *new_meta = ecalloc(result->field_count + 1, sizeof(MYSQLND_FIELD));
- MYSQLND_FIELD *original_meta = result->meta->fields;
- size_t len = result->field_count * sizeof(struct mysqlnd_field_hash_key);
-
- ret->zend_hash_keys = emalloc(len);
- memcpy(ret->zend_hash_keys, result->meta->zend_hash_keys, len);
-
- /*
- This will copy also the strings and the root, which we will have
- to adjust in the loop
- */
- memcpy(new_meta, original_meta, (result->field_count) * sizeof(MYSQLND_FIELD));
- for (i = 0; i < result->field_count; i++) {
- /* First copy the root, then field by field adjust the pointers */
- new_meta[i].root = emalloc(original_meta[i].root_len);
- memcpy(new_meta[i].root, original_meta[i].root, new_meta[i].root_len);
-
- new_meta[i].name = new_meta[i].root + (original_meta[i].name - original_meta[i].root);
- new_meta[i].org_name = new_meta[i].root + (original_meta[i].org_name -
original_meta[i].root);
-
- new_meta[i].table = new_meta[i].root + (original_meta[i].table -
original_meta[i].root);
- new_meta[i].org_table = new_meta[i].root + (original_meta[i].org_table -
original_meta[i].root);
-
- new_meta[i].db = new_meta[i].root + (original_meta[i].db - original_meta[i].root);
- new_meta[i].catalog = new_meta[i].root + (original_meta[i].catalog -
original_meta[i].root);
- /* def is not on the root, if allocated at all */
- if (original_meta[i].def) {
- new_meta[i].def = emalloc(original_meta[i].def_length + 1);
- /* copy the trailing \0 too */
- memcpy(new_meta[i].def, original_meta[i].def, original_meta[i].def_length + 1);
- }
-#if PHP_MAJOR_VERSION >= 6
- if (result->meta->zend_hash_keys[i].ustr.u) {
- ret->zend_hash_keys[i].ustr.u =
eustrndup(result->meta->zend_hash_keys[i].ustr.u,
- result->meta->zend_hash_keys[i].ulen);
- }
-#endif
- }
- ret->current_field = 0;
-
- ret->fields = new_meta;
-
-
- return ret;
-}
-/* }}} */
-
-
/* {{{ _mysqlnd_stmt_param_metadata */
static
MYSQLND_RES * _mysqlnd_stmt_result_metadata(MYSQLND_STMT * const stmt)
@@ -1232,7 +1177,7 @@
result->m.fetch_row = result->m.fetch_row_normal_unbuffered;
result->unbuf = ecalloc(1, sizeof(MYSQLND_RES_UNBUFFERED));
result->unbuf->eof_reached = TRUE;
- result->meta = mysqlnd_result_metadata_clone_metadata(stmt->result);
+ result->meta = stmt->result->m.clone_metadata(stmt->result->meta, FALSE);
return result;
}
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.c 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.c 2007-03-28 13:28:43 UTC (rev 285)
@@ -25,6 +25,8 @@
#include "mysqlnd_statistics.h"
#include "mysqlnd_qcache.h"
+#define MYSQLND_SILENT
+
#ifdef ZTS
#define LOCK_QCACHE(cache) tsrm_mutex_lock((cache)->LOCK_access)
#define UNLOCK_QCACHE(cache) tsrm_mutex_unlock((cache)->LOCK_access)
@@ -35,26 +37,32 @@
/* {{{ mysqlnd_qcache_init_cache */
-MYSQLND_QCACHE * mysqlnd_qcache_init_cache(unsigned int cache_size)
+PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_init_cache()
{
- MYSQLND_QCACHE *ret = calloc(1, sizeof(MYSQLND_QCACHE));
+ MYSQLND_QCACHE *cache = calloc(1, sizeof(MYSQLND_QCACHE));
#ifndef MYSQLND_SILENT
- php_printf("[mysqlnd_qcache_init_cache %p]\n", ret);
+ php_printf("[mysqlnd_qcache_init_cache %p]\n", cache);
#endif
+ cache->references = 1;
#ifdef ZTS
- ret->LOCK_access = tsrm_mutex_alloc();
+ cache->LOCK_access = tsrm_mutex_alloc();
#endif
+ cache->ht = malloc(sizeof(HashTable));
+ zend_hash_init(cache->ht, 10 /* init_elements */, NULL, NULL, TRUE /*pers*/);
- return ret;
+ return cache;
}
/* }}} */
/* {{{ mysqlnd_qcache_get_cache_reference */
-MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache)
+PHPAPI MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache)
{
if (cache) {
+#ifndef MYSQLND_SILENT
+ php_printf("[mysqlnd_qcache_get_cache_reference %p will become %d]\n", cache,
cache->references+1);
+#endif
LOCK_QCACHE(cache);
cache->references++;
UNLOCK_QCACHE(cache);
@@ -82,34 +90,36 @@
#ifdef ZTS
tsrm_mutex_free(cache->LOCK_access);
#endif
- /* free(this_and_that); */
+ zend_hash_destroy(cache->ht);
+ free(cache->ht);
free(cache);
}
/* }}} */
/* {{{ mysqlnd_qcache_free_cache_reference */
-void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache)
+PHPAPI void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache)
{
+ if (*cache) {
+ zend_bool to_free;
#ifndef MYSQLND_SILENT
- php_printf("[mysqlnd_qcache_free_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
+ php_printf("[mysqlnd_qcache_free_cache_reference %p] refs=%d\n", *cache,
(*cache)->references);
#endif
- LOCK_QCACHE(*cache);
- if (*cache && --(*cache)->references == 0) {
+ LOCK_QCACHE(*cache);
+ to_free = --(*cache)->references == 0;
/* Unlock before destroying */
UNLOCK_QCACHE(*cache);
- mysqlnd_qcache_free_cache(*cache);
- } else {
- UNLOCK_QCACHE(*cache);
+ if (to_free) {
+ mysqlnd_qcache_free_cache(*cache);
+ }
+ *cache = NULL;
}
-
- *cache = NULL;
}
/* }}} */
/* {{{ mysqlnd_qcache_free_cache_reference */
-void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval *return_value)
+PHPAPI void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval *return_value)
{
if (cache) {
LOCK_QCACHE(cache);
Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.h
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.h 2007-03-28 10:02:37 UTC (rev 284)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_qcache.h 2007-03-28 13:28:43 UTC (rev 285)
@@ -19,17 +19,3 @@
*/
/* $Id: header,v 1.17 2006/01/01 13:09:48 sniper Exp $ */
-
-struct st_mysqlnd_qcache {
- HashTable *cache;
- unsigned int references;
-#ifdef ZTS
- MUTEX_T LOCK_access;
-#endif
-};
-
-
-MYSQLND_QCACHE * mysqlnd_qcache_init_cache(unsigned int cache_size);
-MYSQLND_QCACHE * mysqlnd_qcache_get_cache_reference(MYSQLND_QCACHE * const cache);
-void mysqlnd_qcache_free_cache_reference(MYSQLND_QCACHE **cache);
-void mysqlnd_qcache_stats(const MYSQLND_QCACHE * const cache, zval *return_value);
| Thread |
|---|
| • PHP mysqlnd svn commit: r285 - in trunk/ext/mysqli: . mysqlnd | ahristov | 28 Mar |