]> granicus.if.org Git - php/commitdiff
Redesigned thread safety mechanism - nua nua
authorZeev Suraski <zeev@php.net>
Sat, 28 Jul 2001 10:46:11 +0000 (10:46 +0000)
committerZeev Suraski <zeev@php.net>
Sat, 28 Jul 2001 10:46:11 +0000 (10:46 +0000)
TSRM/TSRM.h
TSRM/tsrm_virtual_cwd.c
TSRM/tsrm_virtual_cwd.h
TSRM/tsrm_win32.c
TSRM/tsrm_win32.h

index 2e6c481d46318928f19066a385249786d6e46d4b..9cfc9820e86ceaa83556e041003a9fcf03fdd056 100644 (file)
 # 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
 
 
 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
@@ -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
@@ -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 */
 
index 2c899ee667ddc30a13e3049eb94f0608fb7eb85c..ce2e75a0e70d5be5a1f3de7e3f7f0dadd49728a1 100644 (file)
@@ -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)
@@ -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);
 
@@ -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;
 }
@@ -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);
@@ -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);
@@ -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;
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
 
@@ -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) {
index 4b1fa2d5560d43fa1e76f7744fd3c578b212cc1b..d1b27eb5131e514fa9a4d5e3995abf472626e5e6 100644 (file)
@@ -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
index 7a1554afbd8575b43a025a5960f07ebc45e822ec..f8d2b7d7412d3d1c3fcbec2270cd8e26d97415bf 100644 (file)
@@ -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) {
@@ -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;
index 95cdd99a826709b4ec8ef4819700669c66de5358..cb0978668236d4897a8a51f571e589b947a69f63 100644 (file)
@@ -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);