/src/php-src/ext/opcache/zend_accelerator_hash.h
Line | Count | Source |
1 | | /* |
2 | | +----------------------------------------------------------------------+ |
3 | | | Zend OPcache | |
4 | | +----------------------------------------------------------------------+ |
5 | | | Copyright © The PHP Group and Contributors. | |
6 | | +----------------------------------------------------------------------+ |
7 | | | This source file is subject to the Modified BSD License that is | |
8 | | | bundled with this package in the file LICENSE, and is available | |
9 | | | through the World Wide Web at <https://www.php.net/license/>. | |
10 | | | | |
11 | | | SPDX-License-Identifier: BSD-3-Clause | |
12 | | +----------------------------------------------------------------------+ |
13 | | | Authors: Andi Gutmans <andi@php.net> | |
14 | | | Zeev Suraski <zeev@php.net> | |
15 | | | Stanislav Malyshev <stas@zend.com> | |
16 | | | Dmitry Stogov <dmitry@php.net> | |
17 | | +----------------------------------------------------------------------+ |
18 | | */ |
19 | | |
20 | | #ifndef ZEND_ACCELERATOR_HASH_H |
21 | | #define ZEND_ACCELERATOR_HASH_H |
22 | | |
23 | | #include "zend.h" |
24 | | |
25 | | /* |
26 | | zend_accel_hash - is a hash table allocated in shared memory and |
27 | | distributed across simultaneously running processes. The hash tables have |
28 | | fixed sizen selected during construction by zend_accel_hash_init(). All the |
29 | | hash entries are preallocated in the 'hash_entries' array. 'num_entries' is |
30 | | initialized by zero and grows when new data is added. |
31 | | zend_accel_hash_update() just takes the next entry from 'hash_entries' |
32 | | array and puts it into appropriate place of 'hash_table'. |
33 | | Hash collisions are resolved by separate chaining with linked lists, |
34 | | however, entries are still taken from the same 'hash_entries' array. |
35 | | 'key' and 'data' passed to zend_accel_hash_update() must be already |
36 | | allocated in shared memory. Few keys may be resolved to the same data. |
37 | | using 'indirect' entries, that point to other entries ('data' is actually |
38 | | a pointer to another zend_accel_hash_entry). |
39 | | zend_accel_hash_update() requires exclusive lock, however, |
40 | | zend_accel_hash_find() does not. |
41 | | */ |
42 | | |
43 | | typedef struct _zend_accel_hash_entry zend_accel_hash_entry; |
44 | | |
45 | | struct _zend_accel_hash_entry { |
46 | | zend_ulong hash_value; |
47 | | zend_string *key; |
48 | | zend_accel_hash_entry *next; |
49 | | void *data; |
50 | | bool indirect; |
51 | | }; |
52 | | |
53 | | typedef struct _zend_accel_hash { |
54 | | zend_accel_hash_entry **hash_table; |
55 | | zend_accel_hash_entry *hash_entries; |
56 | | uint32_t num_entries; |
57 | | uint32_t max_num_entries; |
58 | | uint32_t num_direct_entries; |
59 | | } zend_accel_hash; |
60 | | |
61 | | BEGIN_EXTERN_C() |
62 | | |
63 | | void zend_accel_hash_init(zend_accel_hash *accel_hash, uint32_t hash_size); |
64 | | void zend_accel_hash_clean(zend_accel_hash *accel_hash); |
65 | | |
66 | | zend_accel_hash_entry* zend_accel_hash_update( |
67 | | zend_accel_hash *accel_hash, |
68 | | zend_string *key, |
69 | | bool indirect, |
70 | | void *data); |
71 | | |
72 | | void* zend_accel_hash_find( |
73 | | const zend_accel_hash *accel_hash, |
74 | | zend_string *key); |
75 | | |
76 | | zend_accel_hash_entry* zend_accel_hash_find_entry( |
77 | | const zend_accel_hash *accel_hash, |
78 | | zend_string *key); |
79 | | |
80 | | zend_result zend_accel_hash_unlink( |
81 | | zend_accel_hash *accel_hash, |
82 | | zend_string *key); |
83 | | |
84 | | static inline bool zend_accel_hash_is_full(const zend_accel_hash *accel_hash) |
85 | 50.2k | { |
86 | 50.2k | if (accel_hash->num_entries == accel_hash->max_num_entries) { |
87 | 0 | return true; |
88 | 50.2k | } else { |
89 | | return false; |
90 | 50.2k | } |
91 | 50.2k | } Unexecuted instantiation: shared_alloc_mmap.c:zend_accel_hash_is_full Unexecuted instantiation: shared_alloc_posix.c:zend_accel_hash_is_full Unexecuted instantiation: shared_alloc_shm.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_api.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_blacklist.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_debug.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_hash.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_module.c:zend_accel_hash_is_full Unexecuted instantiation: zend_accelerator_util_funcs.c:zend_accel_hash_is_full Unexecuted instantiation: zend_file_cache.c:zend_accel_hash_is_full Unexecuted instantiation: zend_persist_calc.c:zend_accel_hash_is_full Unexecuted instantiation: zend_persist.c:zend_accel_hash_is_full Unexecuted instantiation: zend_shared_alloc.c:zend_accel_hash_is_full ZendAccelerator.c:zend_accel_hash_is_full Line | Count | Source | 85 | 50.2k | { | 86 | 50.2k | if (accel_hash->num_entries == accel_hash->max_num_entries) { | 87 | 0 | return true; | 88 | 50.2k | } else { | 89 | | return false; | 90 | 50.2k | } | 91 | 50.2k | } |
Unexecuted instantiation: zend_jit_vm_helpers.c:zend_accel_hash_is_full Unexecuted instantiation: zend_jit.c:zend_accel_hash_is_full Unexecuted instantiation: main.c:zend_accel_hash_is_full |
92 | | |
93 | | END_EXTERN_C() |
94 | | |
95 | | #endif /* ZEND_ACCELERATOR_HASH_H */ |