From b3aebda9eaf55706af2e21178f229a171725a168 Mon Sep 17 00:00:00 2001 From: krakjoe Date: Sat, 20 Sep 2014 20:22:14 +0100 Subject: native tls initial patch --- Zend/zend_gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_gc.c') diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index b331f979fd..a848e8eb58 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -26,7 +26,7 @@ #define GC_ROOT_BUFFER_MAX_ENTRIES 10001 #ifdef ZTS -ZEND_API int gc_globals_id; +TSRMG_D(zend_gc_globals, gc_globals_id); #else ZEND_API zend_gc_globals gc_globals; #endif @@ -82,7 +82,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC) ZEND_API void gc_globals_ctor(TSRMLS_D) { #ifdef ZTS - ts_allocate_id(&gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); + TSRMG_ALLOCATE(gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); #else gc_globals_ctor_ex(&gc_globals); #endif -- cgit v1.2.1 From d11734b4b00f57de80d931ad1c522e00082443af Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 25 Sep 2014 18:48:27 +0200 Subject: reworked the patch, less new stuff but worky TLS is already used in TSRM, the way exporting the tsrm cache through a thread local variable is not portable. Additionally, the current patch suffers from bugs which are hard to find, but prevent it to be worky with apache. What is done here is mainly uses the idea from the RFC patch, but - __thread variable is removed - offset math and declarations are removed - extra macros and definitions are removed What is done merely is - use an inline function to access the tsrm cache. The function uses the portable tsrm_tls_get macro which is cheap - all the TSRM_* macros are set to placebo. Thus this opens the way remove them later Except that, the logic is old. TSRMLS_FETCH will have to be done once per thread, then tsrm_get_ls_cache() can be used. Things seeming to be worky are cli, cli server and apache. I also tried to enable bz2 shared and it has worked out of the box. The change is yet minimal diffing to the current master bus is a worky start, IMHO. Though will have to recheck the other previously done SAPIs - embed and cgi. The offsets can be added to the tsrm_resource_type struct, then it'll not be needed to declare them in the userspace. Even the "done" member type can be changed to int16 or smaller, then adding the offset as int16 will not change the struct size. As well on the todo might be removing the hashed storage, thread_id != thread_id and linked list logic in favour of the explicit TLS operations. --- Zend/zend_gc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zend/zend_gc.c') diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index a848e8eb58..b331f979fd 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -26,7 +26,7 @@ #define GC_ROOT_BUFFER_MAX_ENTRIES 10001 #ifdef ZTS -TSRMG_D(zend_gc_globals, gc_globals_id); +ZEND_API int gc_globals_id; #else ZEND_API zend_gc_globals gc_globals; #endif @@ -82,7 +82,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC) ZEND_API void gc_globals_ctor(TSRMLS_D) { #ifdef ZTS - TSRMG_ALLOCATE(gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); + ts_allocate_id(&gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); #else gc_globals_ctor_ex(&gc_globals); #endif -- cgit v1.2.1 From bdeb220f48825642f84cdbf3ff23a30613c92e86 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Sat, 13 Dec 2014 23:06:14 +0100 Subject: first shot remove TSRMLS_* things --- Zend/zend_gc.c | 98 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) (limited to 'Zend/zend_gc.c') diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index f6aad866a7..671a306843 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -32,9 +32,9 @@ ZEND_API zend_gc_globals gc_globals; #endif #define GC_REMOVE_FROM_ROOTS(current) \ - gc_remove_from_roots((current) TSRMLS_CC) + gc_remove_from_roots((current)) -static zend_always_inline void gc_remove_from_roots(gc_root_buffer *root TSRMLS_DC) +static zend_always_inline void gc_remove_from_roots(gc_root_buffer *root) { root->next->prev = root->prev; root->prev->next = root->next; @@ -43,7 +43,7 @@ static zend_always_inline void gc_remove_from_roots(gc_root_buffer *root TSRMLS_ GC_BENCH_DEC(root_buf_length); } -static void root_buffer_dtor(zend_gc_globals *gc_globals TSRMLS_DC) +static void root_buffer_dtor(zend_gc_globals *gc_globals) { if (gc_globals->buf) { free(gc_globals->buf); @@ -51,7 +51,7 @@ static void root_buffer_dtor(zend_gc_globals *gc_globals TSRMLS_DC) } } -static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC) +static void gc_globals_ctor_ex(zend_gc_globals *gc_globals) { gc_globals->gc_enabled = 0; gc_globals->gc_active = 0; @@ -79,7 +79,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals TSRMLS_DC) #endif } -ZEND_API void gc_globals_ctor(TSRMLS_D) +ZEND_API void gc_globals_ctor(void) { #ifdef ZTS ts_allocate_id(&gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); @@ -88,14 +88,14 @@ ZEND_API void gc_globals_ctor(TSRMLS_D) #endif } -ZEND_API void gc_globals_dtor(TSRMLS_D) +ZEND_API void gc_globals_dtor(void) { #ifndef ZTS - root_buffer_dtor(&gc_globals TSRMLS_DC); + root_buffer_dtor(&gc_globals); #endif } -ZEND_API void gc_reset(TSRMLS_D) +ZEND_API void gc_reset(void) { GC_G(gc_runs) = 0; GC_G(collected) = 0; @@ -126,16 +126,16 @@ ZEND_API void gc_reset(TSRMLS_D) } } -ZEND_API void gc_init(TSRMLS_D) +ZEND_API void gc_init(void) { if (GC_G(buf) == NULL && GC_G(gc_enabled)) { GC_G(buf) = (gc_root_buffer*) malloc(sizeof(gc_root_buffer) * GC_ROOT_BUFFER_MAX_ENTRIES); GC_G(last_unused) = &GC_G(buf)[GC_ROOT_BUFFER_MAX_ENTRIES]; - gc_reset(TSRMLS_C); + gc_reset(); } } -ZEND_API void gc_possible_root(zend_refcounted *ref TSRMLS_DC) +ZEND_API void gc_possible_root(zend_refcounted *ref) { GC_BENCH_INC(zval_possible_root); @@ -156,7 +156,7 @@ ZEND_API void gc_possible_root(zend_refcounted *ref TSRMLS_DC) return; } GC_REFCOUNT(ref)++; - gc_collect_cycles(TSRMLS_C); + gc_collect_cycles(); GC_REFCOUNT(ref)--; newRoot = GC_G(unused); if (!newRoot) { @@ -182,7 +182,7 @@ ZEND_API void gc_possible_root(zend_refcounted *ref TSRMLS_DC) } } -ZEND_API void gc_remove_from_buffer(zend_refcounted *ref TSRMLS_DC) +ZEND_API void gc_remove_from_buffer(zend_refcounted *ref) { gc_root_buffer *root; @@ -197,7 +197,7 @@ ZEND_API void gc_remove_from_buffer(zend_refcounted *ref TSRMLS_DC) } } -static void gc_scan_black(zend_refcounted *ref TSRMLS_DC) +static void gc_scan_black(zend_refcounted *ref) { HashTable *ht; uint idx; @@ -219,7 +219,7 @@ tail_call: HashTable *props; ZVAL_OBJ(&tmp, obj); - props = get_gc(&tmp, &table, &n TSRMLS_CC); + props = get_gc(&tmp, &table, &n); while (n > 0 && !Z_REFCOUNTED(table[n-1])) n--; for (i = 0; i < n; i++) { if (Z_REFCOUNTED(table[i])) { @@ -231,7 +231,7 @@ tail_call: if (!props && i == n - 1) { goto tail_call; } else { - gc_scan_black(ref TSRMLS_CC); + gc_scan_black(ref); } } } @@ -273,13 +273,13 @@ tail_call: if (idx == ht->nNumUsed-1) { goto tail_call; } else { - gc_scan_black(ref TSRMLS_CC); + gc_scan_black(ref); } } } } -static void gc_mark_grey(zend_refcounted *ref TSRMLS_DC) +static void gc_mark_grey(zend_refcounted *ref) { HashTable *ht; uint idx; @@ -303,7 +303,7 @@ tail_call: HashTable *props; ZVAL_OBJ(&tmp, obj); - props = get_gc(&tmp, &table, &n TSRMLS_CC); + props = get_gc(&tmp, &table, &n); while (n > 0 && !Z_REFCOUNTED(table[n-1])) n--; for (i = 0; i < n; i++) { @@ -315,7 +315,7 @@ tail_call: if (!props && i == n - 1) { goto tail_call; } else { - gc_mark_grey(ref TSRMLS_CC); + gc_mark_grey(ref); } } } @@ -355,25 +355,25 @@ tail_call: if (idx == ht->nNumUsed-1) { goto tail_call; } else { - gc_mark_grey(ref TSRMLS_CC); + gc_mark_grey(ref); } } } } -static void gc_mark_roots(TSRMLS_D) +static void gc_mark_roots(void) { gc_root_buffer *current = GC_G(roots).next; while (current != &GC_G(roots)) { if (GC_GET_COLOR(GC_INFO(current->ref)) == GC_PURPLE) { - gc_mark_grey(current->ref TSRMLS_CC); + gc_mark_grey(current->ref); } current = current->next; } } -static void gc_scan(zend_refcounted *ref TSRMLS_DC) +static void gc_scan(zend_refcounted *ref) { HashTable *ht; uint idx; @@ -383,7 +383,7 @@ tail_call: if (GC_GET_COLOR(GC_INFO(ref)) == GC_GREY) { ht = NULL; if (GC_REFCOUNT(ref) > 0) { - gc_scan_black(ref TSRMLS_CC); + gc_scan_black(ref); } else { GC_SET_COLOR(GC_INFO(ref), GC_WHITE); if (GC_TYPE(ref) == IS_OBJECT && EG(objects_store).object_buckets) { @@ -398,7 +398,7 @@ tail_call: HashTable *props; ZVAL_OBJ(&tmp, obj); - props = get_gc(&tmp, &table, &n TSRMLS_CC); + props = get_gc(&tmp, &table, &n); while (n > 0 && !Z_REFCOUNTED(table[n-1])) n--; for (i = 0; i < n; i++) { if (Z_REFCOUNTED(table[i])) { @@ -406,7 +406,7 @@ tail_call: if (!props && i == n - 1) { goto tail_call; } else { - gc_scan(ref TSRMLS_CC); + gc_scan(ref); } } } @@ -441,23 +441,23 @@ tail_call: if (idx == ht->nNumUsed-1) { goto tail_call; } else { - gc_scan(ref TSRMLS_CC); + gc_scan(ref); } } } } -static void gc_scan_roots(TSRMLS_D) +static void gc_scan_roots(void) { gc_root_buffer *current = GC_G(roots).next; while (current != &GC_G(roots)) { - gc_scan(current->ref TSRMLS_CC); + gc_scan(current->ref); current = current->next; } } -static int gc_collect_white(zend_refcounted *ref TSRMLS_DC) +static int gc_collect_white(zend_refcounted *ref) { int count = 0; HashTable *ht; @@ -513,7 +513,7 @@ tail_call: HashTable *props; ZVAL_OBJ(&tmp, obj); - props = get_gc(&tmp, &table, &n TSRMLS_CC); + props = get_gc(&tmp, &table, &n); while (n > 0 && !Z_REFCOUNTED(table[n-1])) { /* count non-refcounted for compatibility ??? */ if (Z_TYPE(table[n-1]) != IS_UNDEF) { @@ -530,7 +530,7 @@ tail_call: if (!props && i == n - 1) { goto tail_call; } else { - count += gc_collect_white(ref TSRMLS_CC); + count += gc_collect_white(ref); } /* count non-refcounted for compatibility ??? */ } else if (Z_TYPE(table[i]) != IS_UNDEF) { @@ -576,14 +576,14 @@ tail_call: if (idx == ht->nNumUsed-1) { goto tail_call; } else { - count += gc_collect_white(ref TSRMLS_CC); + count += gc_collect_white(ref); } } } return count; } -static int gc_collect_roots(TSRMLS_D) +static int gc_collect_roots(void) { int count = 0; gc_root_buffer *current = GC_G(roots).next; @@ -601,7 +601,7 @@ static int gc_collect_roots(TSRMLS_D) while (current != &GC_G(roots)) { if (GC_GET_COLOR(GC_INFO(current->ref)) == GC_WHITE) { GC_REFCOUNT(current->ref)++; - count += gc_collect_white(current->ref TSRMLS_CC); + count += gc_collect_white(current->ref); } current = current->next; } @@ -613,7 +613,7 @@ static int gc_collect_roots(TSRMLS_D) GC_SET_BLACK(GC_INFO(current->ref)); current = current->next; } - gc_reset(TSRMLS_C); + gc_reset(); return 0; } @@ -639,7 +639,7 @@ static int gc_collect_roots(TSRMLS_D) return count; } -static void gc_remove_nested_data_from_buffer(zend_refcounted *ref TSRMLS_DC) +static void gc_remove_nested_data_from_buffer(zend_refcounted *ref) { HashTable *ht = NULL; uint idx; @@ -661,7 +661,7 @@ tail_call: HashTable *props; ZVAL_OBJ(&tmp, obj); - props = get_gc(&tmp, &table, &n TSRMLS_CC); + props = get_gc(&tmp, &table, &n); while (n > 0 && !Z_REFCOUNTED(table[n-1])) n--; for (i = 0; i < n; i++) { @@ -670,7 +670,7 @@ tail_call: if (!props && i == n - 1) { goto tail_call; } else { - gc_remove_nested_data_from_buffer(ref TSRMLS_CC); + gc_remove_nested_data_from_buffer(ref); } } } @@ -700,13 +700,13 @@ tail_call: if (idx == ht->nNumUsed-1) { goto tail_call; } else { - gc_remove_nested_data_from_buffer(ref TSRMLS_CC); + gc_remove_nested_data_from_buffer(ref); } } } } -ZEND_API int gc_collect_cycles(TSRMLS_D) +ZEND_API int gc_collect_cycles(void) { int count = 0; @@ -720,9 +720,9 @@ ZEND_API int gc_collect_cycles(TSRMLS_D) } GC_G(gc_runs)++; GC_G(gc_active) = 1; - gc_mark_roots(TSRMLS_C); - gc_scan_roots(TSRMLS_C); - count = gc_collect_roots(TSRMLS_C); + gc_mark_roots(); + gc_scan_roots(); + count = gc_collect_roots(); GC_G(gc_active) = 0; if (GC_G(to_free).next == &GC_G(to_free)) { @@ -764,7 +764,7 @@ ZEND_API int gc_collect_cycles(TSRMLS_D) GC_FLAGS(obj) |= IS_OBJ_DESTRUCTOR_CALLED; if (obj->handlers->dtor_obj) { GC_REFCOUNT(obj)++; - obj->handlers->dtor_obj(obj TSRMLS_CC); + obj->handlers->dtor_obj(obj); GC_REFCOUNT(obj)--; } } @@ -777,7 +777,7 @@ ZEND_API int gc_collect_cycles(TSRMLS_D) while (current != &to_free) { GC_G(next_to_free) = current->next; if (GC_REFCOUNT(current->ref) > current->refcount) { - gc_remove_nested_data_from_buffer(current->ref TSRMLS_CC); + gc_remove_nested_data_from_buffer(current->ref); } current = GC_G(next_to_free); } @@ -797,7 +797,7 @@ ZEND_API int gc_collect_cycles(TSRMLS_D) GC_FLAGS(obj) |= IS_OBJ_FREE_CALLED; if (obj->handlers->free_obj) { GC_REFCOUNT(obj)++; - obj->handlers->free_obj(obj TSRMLS_CC); + obj->handlers->free_obj(obj); GC_REFCOUNT(obj)--; } } @@ -821,7 +821,7 @@ ZEND_API int gc_collect_cycles(TSRMLS_D) if (EG(objects_store).object_buckets && IS_OBJ_VALID(EG(objects_store).object_buckets[obj->handle])) { - zend_objects_store_free(obj TSRMLS_CC); + zend_objects_store_free(obj); } } else { GC_REMOVE_FROM_BUFFER(p); -- cgit v1.2.1