Skip to content

Commit

Permalink
Redesigned thread safety mechanism - nua nua
Browse files Browse the repository at this point in the history
  • Loading branch information
zsuraski committed Jul 28, 2001
1 parent adb1fa5 commit 633a1c3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 50 deletions.
30 changes: 15 additions & 15 deletions TSRM/TSRM.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
# include "tsrm_config.h"
#endif


#ifdef TSRM_WIN32
# ifdef TSRM_EXPORTS
# define TSRM_API __declspec(dllexport)
# else
# define TSRM_API __declspec(dllimport)
# endif
#else
# define TSRM_API
#endif

/* Only compile multi-threading functions if we're in ZTS mode */
#ifdef ZTS

Expand All @@ -36,17 +47,6 @@

typedef int ts_rsrc_id;

#ifdef TSRM_WIN32
# ifdef TSRM_EXPORTS
# define TSRM_API __declspec(dllexport)
# else
# define TSRM_API __declspec(dllimport)
# endif
#else
# define TSRM_API
#endif


/* Define THREAD_T and MUTEX_T */
#ifdef TSRM_WIN32
# define THREAD_T DWORD
Expand Down Expand Up @@ -115,8 +115,8 @@ TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(TH
#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)
#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)

#define TSRMLS_FETCH() void ***tsrm_ls = ts_resource_ex(0, NULL)
#define TSRMG(id, type, element) (((type) (*tsrm_ls)[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
#define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, NULL)
#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
#define TSRMLS_D void ***tsrm_ls
#define TSRMLS_DC , TSRMLS_D
#define TSRMLS_C tsrm_ls
Expand All @@ -126,13 +126,13 @@ TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(TH
}
#endif

#else
#else /* non ZTS */

#define TSRMLS_FETCH()
#define TSRMLS_D
#define TSRMLS_DC
#define TSRMLS_C
#define TSRMLS_CC
#define TSRMLS_FETCH()

#endif /* ZTS */

Expand Down
40 changes: 21 additions & 19 deletions TSRM/tsrm_virtual_cwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

#define VIRTUAL_CWD_DEBUG 0

#ifdef ZTS
#include "TSRM.h"
#endif

/* Only need mutex for popen() in Windows because it doesn't chdir() on UNIX */
#if defined(TSRM_WIN32) && defined(ZTS)
Expand Down Expand Up @@ -201,7 +203,7 @@ CWD_API void virtual_cwd_shutdown(void)
CWD_API char *virtual_getcwd_ex(size_t *length)
{
cwd_state *state;
CWDLS_FETCH();
TSRMLS_FETCH();

state = &CWDG(cwd);

Expand Down Expand Up @@ -405,7 +407,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func

CWD_API int virtual_chdir(const char *path)
{
CWDLS_FETCH();
TSRMLS_FETCH();

return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0;
}
Expand Down Expand Up @@ -446,7 +448,7 @@ CWD_API char *virtual_realpath(const char *path, char *real_path)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
retval = virtual_file_ex(&new_state, path, NULL);
Expand All @@ -465,7 +467,7 @@ CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_f
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
retval = virtual_file_ex(&new_state, path, verify_path);
Expand All @@ -485,7 +487,7 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode)
{
cwd_state new_state;
FILE *f;
CWDLS_FETCH();
TSRMLS_FETCH();

if (path[0] == '\0') { /* Fail to open empty path */
return NULL;
Expand All @@ -505,7 +507,7 @@ CWD_API int virtual_utime(const char *filename, struct utimbuf *buf)
{
cwd_state new_state;
int ret;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, filename, NULL);
Expand All @@ -521,7 +523,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode)
{
cwd_state new_state;
int ret;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, filename, NULL);
Expand All @@ -537,7 +539,7 @@ CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group)
{
cwd_state new_state;
int ret;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, filename, NULL);
Expand All @@ -553,7 +555,7 @@ CWD_API int virtual_open(const char *path, int flags, ...)
{
cwd_state new_state;
int f;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, path, NULL);
Expand All @@ -578,7 +580,7 @@ CWD_API int virtual_creat(const char *path, mode_t mode)
{
cwd_state new_state;
int f;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, path, NULL);
Expand All @@ -594,7 +596,7 @@ CWD_API int virtual_rename(char *oldname, char *newname)
cwd_state old_state;
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&old_state, &CWDG(cwd));
virtual_file_ex(&old_state, oldname, NULL);
Expand All @@ -616,7 +618,7 @@ CWD_API int virtual_stat(const char *path, struct stat *buf)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, path, NULL);
Expand All @@ -633,7 +635,7 @@ CWD_API int virtual_lstat(const char *path, struct stat *buf)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, path, NULL);
Expand All @@ -650,7 +652,7 @@ CWD_API int virtual_unlink(const char *path)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, path, NULL);
Expand All @@ -665,7 +667,7 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t mode)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, pathname, NULL);
Expand All @@ -683,7 +685,7 @@ CWD_API int virtual_rmdir(const char *pathname)
{
cwd_state new_state;
int retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, pathname, NULL);
Expand All @@ -702,7 +704,7 @@ CWD_API DIR *virtual_opendir(const char *pathname)
{
cwd_state new_state;
DIR *retval;
CWDLS_FETCH();
TSRMLS_FETCH();

CWD_STATE_COPY(&new_state, &CWDG(cwd));
virtual_file_ex(&new_state, pathname, NULL);
Expand All @@ -721,7 +723,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type)
char *command_line;
char *ptr;
FILE *retval;
CWDLS_FETCH();
TSRMLS_FETCH();

command_length = strlen(command);

Expand Down Expand Up @@ -760,7 +762,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type)
char prev_cwd[MAXPATHLEN];
char *getcwd_result;
FILE *retval;
CWDLS_FETCH();
TSRMLS_FETCH();

getcwd_result = getcwd(prev_cwd, MAXPATHLEN);
if (!getcwd_result) {
Expand Down
12 changes: 1 addition & 11 deletions TSRM/tsrm_virtual_cwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,9 @@ typedef struct _virtual_cwd_globals {
} virtual_cwd_globals;

#ifdef ZTS
# define CWDLS_D virtual_cwd_globals *cwd_globals
# define CWDLS_DC , CWDLS_D
# define CWDLS_C cwd_globals
# define CWDLS_CC , CWDLS_C
# define CWDG(v) (cwd_globals->v)
# define CWDLS_FETCH() virtual_cwd_globals *cwd_globals = ts_resource(cwd_globals_id)
# define CWDG(v) TSRMG(cwd_globals_id, virtual_cwd_globals *, v)
#else
# define CWDLS_D void
# define CWDLS_DC
# define CWDLS_C
# define CWDLS_CC
# define CWDG(v) (cwd_globals.v)
# define CWDLS_FETCH()
#endif

/* The actual macros to be used in programs using TSRM
Expand Down
4 changes: 2 additions & 2 deletions TSRM/tsrm_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static ProcessPair* process_get(FILE *stream)
{
ProcessPair* ptr;
ProcessPair* newptr;
TWLS_FETCH();
TSRMLS_FETCH();

for (ptr = TWG(process); ptr < (TWG(process) + TWG(process_size)); ptr++) {
if (ptr->stream == stream) {
Expand Down Expand Up @@ -112,7 +112,7 @@ TSRM_API FILE* popen(const char *command, const char *type)
HANDLE in, out;
char *cmd;
ProcessPair *proc;
TWLS_FETCH();
TSRMLS_FETCH();

security.nLength = sizeof(SECURITY_ATTRIBUTES);
security.bInheritHandle = TRUE;
Expand Down
5 changes: 2 additions & 3 deletions TSRM/tsrm_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ typedef struct {
} tsrm_win32_globals;

#ifdef ZTS
# define TWG(v) (win32_globals->v)
# define TWLS_FETCH() tsrm_win32_globals *win32_globals = ts_resource(win32_globals_id)
# define TWG(v) TSRMG(win32_globals_id, tsrm_win32_globals *, v)
#else
# define TWG(v) (win32_globals.v)
# define TWLS_FETCH()
#endif

#endif

TSRM_API void tsrm_win32_startup(void);
Expand Down

0 comments on commit 633a1c3

Please sign in to comment.