php-src/ext/opcache/zend_accelerator_hash.h

98 lines
3.7 KiB
C
Raw Normal View History

2013-02-13 12:26:47 +00:00
/*
+----------------------------------------------------------------------+
| Zend OPcache |
2013-02-13 12:26:47 +00:00
+----------------------------------------------------------------------+
2019-02-05 07:33:28 +00:00
| Copyright (c) The PHP Group |
2013-02-13 12:26:47 +00:00
+----------------------------------------------------------------------+
| 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 |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
2013-02-13 12:26:47 +00:00
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
2018-11-01 16:30:28 +00:00
| Authors: Andi Gutmans <andi@php.net> |
| Zeev Suraski <zeev@php.net> |
2013-02-13 12:26:47 +00:00
| Stanislav Malyshev <stas@zend.com> |
2018-11-01 16:30:28 +00:00
| Dmitry Stogov <dmitry@php.net> |
2013-02-13 12:26:47 +00:00
+----------------------------------------------------------------------+
*/
#ifndef ZEND_ACCELERATOR_HASH_H
#define ZEND_ACCELERATOR_HASH_H
#include "zend.h"
2013-02-13 12:26:47 +00:00
/*
zend_accel_hash - is a hash table allocated in shared memory and
distributed across simultaneously running processes. The hash tables have
fixed sizen selected during construction by zend_accel_hash_init(). All the
hash entries are preallocated in the 'hash_entries' array. 'num_entries' is
initialized by zero and grows when new data is added.
zend_accel_hash_update() just takes the next entry from 'hash_entries'
array and puts it into appropriate place of 'hash_table'.
Hash collisions are resolved by separate chaining with linked lists,
however, entries are still taken from the same 'hash_entries' array.
'key' and 'data' passed to zend_accel_hash_update() must be already
allocated in shared memory. Few keys may be resolved to the same data.
2013-03-11 18:49:05 +00:00
using 'indirect' entries, that point to other entries ('data' is actually
2013-02-13 12:26:47 +00:00
a pointer to another zend_accel_hash_entry).
zend_accel_hash_update() requires exclusive lock, however,
zend_accel_hash_find() does not.
*/
typedef struct _zend_accel_hash_entry zend_accel_hash_entry;
struct _zend_accel_hash_entry {
2014-08-25 17:24:55 +00:00
zend_ulong hash_value;
2021-03-22 11:56:16 +00:00
zend_string *key;
2013-02-13 12:26:47 +00:00
zend_accel_hash_entry *next;
void *data;
2021-03-22 11:56:16 +00:00
bool indirect;
2013-02-13 12:26:47 +00:00
};
typedef struct _zend_accel_hash {
zend_accel_hash_entry **hash_table;
zend_accel_hash_entry *hash_entries;
2014-08-25 17:28:33 +00:00
uint32_t num_entries;
uint32_t max_num_entries;
uint32_t num_direct_entries;
2013-02-13 12:26:47 +00:00
} zend_accel_hash;
2022-03-17 18:28:34 +00:00
BEGIN_EXTERN_C()
2014-08-25 17:28:33 +00:00
void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size);
2013-02-13 12:26:47 +00:00
void zend_accel_hash_clean(zend_accel_hash *accel_hash);
zend_accel_hash_entry* zend_accel_hash_update(
zend_accel_hash *accel_hash,
2021-03-22 11:56:16 +00:00
zend_string *key,
bool indirect,
2013-02-13 12:26:47 +00:00
void *data);
void* zend_accel_hash_find(
2015-03-06 13:26:40 +00:00
zend_accel_hash *accel_hash,
zend_string *key);
zend_accel_hash_entry* zend_accel_hash_find_entry(
zend_accel_hash *accel_hash,
zend_string *key);
2013-02-13 12:26:47 +00:00
int zend_accel_hash_unlink(
zend_accel_hash *accel_hash,
2021-03-22 11:56:16 +00:00
zend_string *key);
2013-02-13 12:26:47 +00:00
static inline bool zend_accel_hash_is_full(zend_accel_hash *accel_hash)
2013-02-13 12:26:47 +00:00
{
if (accel_hash->num_entries == accel_hash->max_num_entries) {
return 1;
} else {
return 0;
}
}
2022-03-17 18:28:34 +00:00
END_EXTERN_C()
2013-02-13 12:26:47 +00:00
#endif /* ZEND_ACCELERATOR_HASH_H */