Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4da0da7

Browse files
Implement GH-10854: TSRM should set a smarter value for expected_threads (#10867)
The tsrm_startup() function is currently always called with expected_threads = 1. This means that the hashtable used in the TSRM will only contain a single bucket, and all thread resources will therefore be in the same linked list. So it's not really a hashtable right now, even though it's supposed to be. This patch adds a function tsrm_startup_ex() which takes the expected thread count as an argument. It also keeps the tsrm_startup() function so there are no BC breaks. In the Apache SAPI we query how many threads we have, and pass that to the tsrm_startup_ex() function.
1 parent 31ccfbd commit 4da0da7

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

‎main/main.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,13 +2647,18 @@ PHPAPI void php_reserve_tsrm_memory(void)
26472647
}
26482648
/* }}} */
26492649

2650-
/* {{{ php_tsrm_startup */
2651-
PHPAPI bool php_tsrm_startup(void)
2650+
PHPAPI bool php_tsrm_startup_ex(int expected_threads)
26522651
{
2653-
bool ret = tsrm_startup(1, 1, 0, NULL);
2652+
bool ret = tsrm_startup(expected_threads, 1, 0, NULL);
26542653
php_reserve_tsrm_memory();
26552654
(void)ts_resource(0);
26562655
return ret;
26572656
}
2657+
2658+
/* {{{ php_tsrm_startup */
2659+
PHPAPI bool php_tsrm_startup(void)
2660+
{
2661+
return php_tsrm_startup_ex(1);
2662+
}
26582663
/* }}} */
26592664
#endif

‎main/php_main.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ extern int php_shutdown_environ(void);
4747

4848
#ifdef ZTS
4949
PHPAPI void php_reserve_tsrm_memory(void);
50+
PHPAPI bool php_tsrm_startup_ex(int expected_threads);
5051
PHPAPI bool php_tsrm_startup(void);
5152

5253
#define PHP_ZTS 1

‎sapi/apache2handler/sapi_apache2.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,16 @@ php_apache_server_startup(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp
485485
apache2_sapi_module.php_ini_path_override = apache2_php_ini_path_override;
486486
}
487487
#ifdef ZTS
488-
php_tsrm_startup();
488+
int expected_threads;
489+
#ifdef AP_MPMQ_MAX_THREADS
490+
if (ap_mpm_query(AP_MPMQ_MAX_THREADS, &expected_threads) != APR_SUCCESS) {
491+
expected_threads = 1;
492+
}
493+
#else
494+
expected_threads = 1;
495+
#endif
496+
497+
php_tsrm_startup_ex(expected_threads);
489498
# ifdef PHP_WIN32
490499
ZEND_TSRMLS_CACHE_UPDATE();
491500
# endif

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /