@@ -1342,6 +1342,39 @@ zend_string *accel_make_persistent_key(zend_string *str)
1342
1342
return str ;
1343
1343
}
1344
1344
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
+ persistent_script -> corrupted = true;
1358
+ persistent_script -> timestamp = 0 ;
1359
+ ZSMMG (wasted_shared_memory ) += persistent_script -> dynamic_members .memory_consumption ;
1360
+ if (ZSMMG (memory_exhausted )) {
1361
+ zend_accel_restart_reason reason =
1362
+ zend_accel_hash_is_full (& ZCSG (hash )) ? ACCEL_RESTART_HASH : ACCEL_RESTART_OOM ;
1363
+ zend_accel_schedule_restart_if_necessary (reason );
1364
+ }
1365
+ }
1366
+
1367
+ /**
1368
+ * Wrapper for zend_accel_discard_script() which locks shared memory
1369
+ * via zend_shared_alloc_lock().
1370
+ */
1371
+ static void zend_accel_lock_discard_script (zend_persistent_script * persistent_script )
1372
+ {
1373
+ zend_shared_alloc_lock ();
1374
+ zend_accel_discard_script (persistent_script );
1375
+ zend_shared_alloc_unlock ();
1376
+ }
1377
+
1345
1378
int zend_accel_invalidate (zend_string * filename , bool force )
1346
1379
{
1347
1380
zend_string * realpath ;
@@ -1372,18 +1405,7 @@ int zend_accel_invalidate(zend_string *filename, bool force)
1372
1405
do_validate_timestamps (persistent_script , & file_handle ) == FAILURE ) {
1373
1406
HANDLE_BLOCK_INTERRUPTIONS ();
1374
1407
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 ();
1408
+ zend_accel_lock_discard_script (persistent_script );
1387
1409
SHM_PROTECT ();
1388
1410
HANDLE_UNBLOCK_INTERRUPTIONS ();
1389
1411
}
@@ -2078,18 +2100,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2078
2100
/* If script is found then validate_timestamps if option is enabled */
2079
2101
if (persistent_script && ZCG (accel_directives ).validate_timestamps ) {
2080
2102
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 ();
2103
+ zend_accel_lock_discard_script (persistent_script );
2093
2104
persistent_script = NULL ;
2094
2105
}
2095
2106
}
@@ -2103,18 +2114,7 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
2103
2114
/* The checksum is wrong */
2104
2115
zend_accel_error (ACCEL_LOG_INFO , "Checksum failed for '%s': expected=0x%08x, found=0x%08x" ,
2105
2116
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 ();
2117
+ zend_accel_lock_discard_script (persistent_script );
2118
2118
persistent_script = NULL ;
2119
2119
}
2120
2120
}
0 commit comments