Skip to content

Commit 66dc7a7

Browse files
committed
ext/opcache/ZendAccelerator: move duplicate code to zend_accel_discard_script()
1 parent 78bdecb commit 66dc7a7

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,40 @@ zend_string *accel_make_persistent_key(zend_string *str)
13421342
return str;
13431343
}
13441344

1345+
/**
1346+
* Discard a #zend_persistent_script currently stored in shared
1347+
* memory.
1348+
*
1349+
* Caller must lock shared memory via zend_shared_alloc_lock().
1350+
*/
1351+
static void zend_accel_discard_script(zend_persistent_script *persistent_script)
1352+
{
1353+
if (persistent_script->corrupted) {
1354+
/* already discarded */
1355+
return;
1356+
}
1357+
1358+
persistent_script->corrupted = true;
1359+
persistent_script->timestamp = 0;
1360+
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
1361+
if (ZSMMG(memory_exhausted)) {
1362+
zend_accel_restart_reason reason =
1363+
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
1364+
zend_accel_schedule_restart_if_necessary(reason);
1365+
}
1366+
}
1367+
1368+
/**
1369+
* Wrapper for zend_accel_discard_script() which locks shared memory
1370+
* via zend_shared_alloc_lock().
1371+
*/
1372+
static void zend_accel_lock_discard_script(zend_persistent_script *persistent_script)
1373+
{
1374+
zend_shared_alloc_lock();
1375+
zend_accel_discard_script(persistent_script);
1376+
zend_shared_alloc_unlock();
1377+
}
1378+
13451379
int zend_accel_invalidate(zend_string *filename, bool force)
13461380
{
13471381
zend_string *realpath;
@@ -1372,18 +1406,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
13721406
do_validate_timestamps(persistent_script, &file_handle) == FAILURE) {
13731407
HANDLE_BLOCK_INTERRUPTIONS();
13741408
SHM_UNPROTECT();
1375-
zend_shared_alloc_lock();
1376-
if (!persistent_script->corrupted) {
1377-
persistent_script->corrupted = true;
1378-
persistent_script->timestamp = 0;
1379-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
1380-
if (ZSMMG(memory_exhausted)) {
1381-
zend_accel_restart_reason reason =
1382-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
1383-
zend_accel_schedule_restart_if_necessary(reason);
1384-
}
1385-
}
1386-
zend_shared_alloc_unlock();
1409+
zend_accel_lock_discard_script(persistent_script);
13871410
SHM_PROTECT();
13881411
HANDLE_UNBLOCK_INTERRUPTIONS();
13891412
}
@@ -2078,18 +2101,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20782101
/* If script is found then validate_timestamps if option is enabled */
20792102
if (persistent_script && ZCG(accel_directives).validate_timestamps) {
20802103
if (validate_timestamp_and_record(persistent_script, file_handle) == FAILURE) {
2081-
zend_shared_alloc_lock();
2082-
if (!persistent_script->corrupted) {
2083-
persistent_script->corrupted = true;
2084-
persistent_script->timestamp = 0;
2085-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
2086-
if (ZSMMG(memory_exhausted)) {
2087-
zend_accel_restart_reason reason =
2088-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
2089-
zend_accel_schedule_restart_if_necessary(reason);
2090-
}
2091-
}
2092-
zend_shared_alloc_unlock();
2104+
zend_accel_lock_discard_script(persistent_script);
20932105
persistent_script = NULL;
20942106
}
20952107
}
@@ -2103,18 +2115,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
21032115
/* The checksum is wrong */
21042116
zend_accel_error(ACCEL_LOG_INFO, "Checksum failed for '%s': expected=0x%08x, found=0x%08x",
21052117
ZSTR_VAL(persistent_script->script.filename), persistent_script->dynamic_members.checksum, checksum);
2106-
zend_shared_alloc_lock();
2107-
if (!persistent_script->corrupted) {
2108-
persistent_script->corrupted = true;
2109-
persistent_script->timestamp = 0;
2110-
ZSMMG(wasted_shared_memory) += persistent_script->dynamic_members.memory_consumption;
2111-
if (ZSMMG(memory_exhausted)) {
2112-
zend_accel_restart_reason reason =
2113-
zend_accel_hash_is_full(&ZCSG(hash)) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM;
2114-
zend_accel_schedule_restart_if_necessary(reason);
2115-
}
2116-
}
2117-
zend_shared_alloc_unlock();
2118+
zend_accel_lock_discard_script(persistent_script);
21182119
persistent_script = NULL;
21192120
}
21202121
}

0 commit comments

Comments
 (0)