Skip to content

Commit d9258da

Browse files
author
Sascha Schumann
committed
@- Made pageinfo.c thread-safe (Sascha)
1 parent f30278b commit d9258da

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

ext/standard/basic_functions.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ PHP_RINIT_FUNCTION(basic)
400400
BG(locale_string) = NULL;
401401
BG(user_compare_func_name) = NULL;
402402
BG(array_walk_func_name) = NULL;
403+
BG(page_uid) = -1;
404+
BG(page_inode) = -1;
405+
BG(page_mtime) = -1;
403406
#ifdef HAVE_PUTENV
404407
if (zend_hash_init(&BG(putenv_ht), 1, NULL, (int (*)(void *)) _php3_putenv_destructor, 0) == FAILURE) {
405408
return FAILURE;

ext/standard/basic_functions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ typedef struct {
113113
char str_ebuf[40];
114114
zval **array_walk_func_name;
115115
zval **user_compare_func_name;
116+
long page_uid;
117+
long page_inode;
118+
long page_mtime;
116119
} php_basic_globals;
117120

118121
#ifdef ZTS

ext/standard/pageinfo.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,17 @@
3838
#include <process.h>
3939
#endif
4040

41-
#ifndef THREAD_SAFE
42-
static long page_uid = -1;
43-
static long page_inode = -1;
44-
static long page_mtime = -1;
45-
#endif
41+
#include "ext/standard/basic_functions.h"
4642

4743
static void _php3_statpage(void)
4844
{
4945
#if !APACHE
5046
char *path;
5147
struct stat sb;
48+
BLS_FETCH();
5249
#else
5350
request_rec *r;
51+
BLS_FETCH();
5452
SLS_FETCH();
5553

5654
r = ((request_rec *) SG(server_context));
@@ -62,11 +60,11 @@ static void _php3_statpage(void)
6260
values. We can afford it, and it means we don't have to
6361
worry about resetting the static variables after every
6462
hit. */
65-
page_uid = r ->finfo.st_uid;
66-
page_inode = r->finfo.st_ino;
67-
page_mtime = r->finfo.st_mtime;
63+
BG(page_uid) = r ->finfo.st_uid;
64+
BG(page_inode) = r->finfo.st_ino;
65+
BG(page_mtime) = r->finfo.st_mtime;
6866
#else
69-
if (page_uid == -1) {
67+
if (BG(page_uid) == -1) {
7068
SLS_FETCH();
7169

7270
path = SG(request_info).path_translated;
@@ -75,18 +73,20 @@ static void _php3_statpage(void)
7573
php_error(E_WARNING, "Unable to find file: '%s'", path);
7674
return;
7775
}
78-
page_uid = sb.st_uid;
79-
page_inode = sb.st_ino;
80-
page_mtime = sb.st_mtime;
76+
BG(page_uid) = sb.st_uid;
77+
BG(page_inode) = sb.st_ino;
78+
BG(page_mtime) = sb.st_mtime;
8179
}
8280
}
8381
#endif
8482
}
8583

8684
long _php3_getuid(void)
8785
{
86+
BLS_FETCH();
87+
8888
_php3_statpage();
89-
return (page_uid);
89+
return (BG(page_uid));
9090
}
9191

9292
/* {{{ proto int getmyuid(void)
@@ -123,11 +123,13 @@ PHP_FUNCTION(getmypid)
123123
Get the inode of the current script being parsed */
124124
PHP_FUNCTION(getmyinode)
125125
{
126+
BLS_FETCH();
127+
126128
_php3_statpage();
127-
if (page_inode < 0) {
129+
if (BG(page_inode) < 0) {
128130
RETURN_FALSE;
129131
} else {
130-
RETURN_LONG(page_inode);
132+
RETURN_LONG(BG(page_inode));
131133
}
132134
}
133135
/* }}} */
@@ -136,11 +138,13 @@ PHP_FUNCTION(getmyinode)
136138
Get time of last page modification */
137139
PHP_FUNCTION(getlastmod)
138140
{
141+
BLS_FETCH();
142+
139143
_php3_statpage();
140-
if (page_mtime < 0) {
144+
if (BG(page_mtime) < 0) {
141145
RETURN_FALSE;
142146
} else {
143-
RETURN_LONG(page_mtime);
147+
RETURN_LONG(BG(page_mtime));
144148
}
145149
}
146150
/* }}} */

0 commit comments

Comments
 (0)