mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* cont.c (stackgrowdirection): removed duplicated code, use
STACK_UPPER macro instead. * gc.h (STACK_DIR_UPPER): moved from thread_pthread.c. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27682 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ffde073b0c
commit
89cc2aef81
4 changed files with 32 additions and 71 deletions
|
@ -1,3 +1,10 @@
|
|||
Sun May 9 01:15:18 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* cont.c (stackgrowdirection): removed duplicated code, use
|
||||
STACK_UPPER macro instead.
|
||||
|
||||
* gc.h (STACK_DIR_UPPER): moved from thread_pthread.c.
|
||||
|
||||
Sun May 9 00:35:56 2010 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||
|
||||
* test/dl/test_base.rb (libc_so, libm_so): supports solaris.
|
||||
|
|
68
cont.c
68
cont.c
|
@ -45,9 +45,6 @@
|
|||
#define PAGE_SIZE (pagesize)
|
||||
#define PAGE_MASK (~(PAGE_SIZE - 1))
|
||||
static long pagesize;
|
||||
static long stackgrowdirection;
|
||||
#define STACK_GROW_DOWNWARD 1
|
||||
#define STACK_GROW_UPWARD 2
|
||||
#define FIBER_MACHINE_STACK_ALLOCATION_SIZE (0x10000 / sizeof(VALUE))
|
||||
#endif
|
||||
|
||||
|
@ -498,20 +495,10 @@ static void
|
|||
fiber_set_stack_location(void)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
unsigned long ptr;
|
||||
VALUE ptr;
|
||||
|
||||
SET_MACHINE_STACK_END((VALUE**)(&ptr));
|
||||
switch (stackgrowdirection) {
|
||||
case STACK_GROW_DOWNWARD:
|
||||
th->machine_stack_start = (void*)((ptr & PAGE_MASK) + PAGE_SIZE);
|
||||
break;
|
||||
case STACK_GROW_UPWARD:
|
||||
th->machine_stack_start = (void*)(ptr & PAGE_MASK);
|
||||
break;
|
||||
default:
|
||||
rb_bug("fiber_get_stacck_location: should not be reached");
|
||||
break;
|
||||
}
|
||||
SET_MACHINE_STACK_END(&ptr);
|
||||
th->machine_stack_start = (void*)((ptr & PAGE_MASK) + STACK_UPPER(&ptr, 0, PAGE_SIZE));
|
||||
}
|
||||
|
||||
static VOID CALLBACK
|
||||
|
@ -539,26 +526,15 @@ fiber_machine_stack_alloc(size_t size)
|
|||
}
|
||||
}
|
||||
else {
|
||||
STACK_GROW_DIR_DETECTION;
|
||||
ptr = (VALUE*)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
if ((int)ptr == -1) {
|
||||
if (ptr == (VALUE*)(SIGNED_VALUE)-1) {
|
||||
rb_raise(rb_eFiberError, "can't alloc machine stack to fiber");
|
||||
}
|
||||
switch (stackgrowdirection) {
|
||||
case STACK_GROW_DOWNWARD:
|
||||
if (mprotect(ptr, PAGE_SIZE, PROT_READ | PROT_WRITE) < 0) {
|
||||
rb_raise(rb_eFiberError, "mprotect failed");
|
||||
}
|
||||
break;
|
||||
case STACK_GROW_UPWARD:
|
||||
if (mprotect(ptr + (size - PAGE_SIZE) / sizeof(VALUE),
|
||||
if (mprotect(ptr + STACK_DIR_UPPER((size - PAGE_SIZE) / sizeof(VALUE), 0),
|
||||
PAGE_SIZE, PROT_READ | PROT_WRITE) < 0) {
|
||||
rb_raise(rb_eFiberError, "mprotect failed");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
rb_bug("fiber_machine_stack_alloc: should not be reached");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ptr;
|
||||
|
@ -575,6 +551,7 @@ fiber_initialize_machine_stack_context(rb_fiber_t *fib, size_t size)
|
|||
#else /* not WIN32 */
|
||||
ucontext_t *context = &fib->context;
|
||||
VALUE *ptr;
|
||||
STACK_GROW_DIR_DETECTION;
|
||||
|
||||
getcontext(context);
|
||||
ptr = fiber_machine_stack_alloc(size);
|
||||
|
@ -582,17 +559,7 @@ fiber_initialize_machine_stack_context(rb_fiber_t *fib, size_t size)
|
|||
context->uc_stack.ss_sp = ptr;
|
||||
context->uc_stack.ss_size = size;
|
||||
makecontext(context, rb_fiber_start, 0);
|
||||
switch (stackgrowdirection) {
|
||||
case STACK_GROW_DOWNWARD:
|
||||
sth->machine_stack_start = ptr + size / sizeof(VALUE);
|
||||
break;
|
||||
case STACK_GROW_UPWARD:
|
||||
sth->machine_stack_start = ptr;
|
||||
break;
|
||||
default:
|
||||
rb_bug("fiber_initialize_stackcontext: should not be reached");
|
||||
break;
|
||||
}
|
||||
sth->machine_stack_start = ptr + STACK_DIR_UPPER(0, size / sizeof(VALUE));
|
||||
#endif
|
||||
|
||||
sth->machine_stack_maxsize = size;
|
||||
|
@ -622,18 +589,13 @@ fiber_setcontext(rb_fiber_t *newfib, rb_fiber_t *oldfib)
|
|||
/* save oldfib's machine stack */
|
||||
if (oldfib->status != TERMINATED) {
|
||||
SET_MACHINE_STACK_END(&th->machine_stack_end);
|
||||
switch (stackgrowdirection) {
|
||||
case STACK_GROW_DOWNWARD:
|
||||
if (STACK_DIR_UPPER(0, 1)) {
|
||||
oldfib->cont.machine_stack_size = th->machine_stack_start - th->machine_stack_end;
|
||||
oldfib->cont.machine_stack = th->machine_stack_end;
|
||||
break;
|
||||
case STACK_GROW_UPWARD:
|
||||
}
|
||||
else {
|
||||
oldfib->cont.machine_stack_size = th->machine_stack_end - th->machine_stack_start;
|
||||
oldfib->cont.machine_stack = th->machine_stack_start;
|
||||
break;
|
||||
default:
|
||||
rb_bug("fiber_get_stacck_location: should not be reached");
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* exchange machine_stack_start between oldfib and newfib */
|
||||
|
@ -1451,14 +1413,6 @@ Init_Cont(void)
|
|||
pagesize = sysconf(_SC_PAGESIZE);
|
||||
#endif
|
||||
SET_MACHINE_STACK_END(&th->machine_stack_end);
|
||||
if (th->machine_stack_start > th->machine_stack_end) {
|
||||
/* stack grows downward */
|
||||
stackgrowdirection = STACK_GROW_DOWNWARD;
|
||||
}
|
||||
else {
|
||||
/* stack grows upward */
|
||||
stackgrowdirection = STACK_GROW_UPWARD;
|
||||
}
|
||||
#endif
|
||||
|
||||
rb_cFiber = rb_define_class("Fiber", rb_cObject);
|
||||
|
|
8
gc.h
8
gc.h
|
@ -74,4 +74,12 @@ int ruby_get_stack_grow_direction(volatile VALUE *addr);
|
|||
# define STACK_UPPER(x, a, b) (stack_growup_p(x) ? a : b)
|
||||
#endif
|
||||
|
||||
#if STACK_GROW_DIRECTION
|
||||
#define STACK_GROW_DIR_DETECTION
|
||||
#define STACK_DIR_UPPER(a,b) STACK_UPPER(0, a, b)
|
||||
#else
|
||||
#define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection
|
||||
#define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, a, b)
|
||||
#endif
|
||||
|
||||
#endif /* RUBY_GC_H */
|
||||
|
|
|
@ -185,14 +185,6 @@ native_thread_destroy(rb_thread_t *th)
|
|||
|
||||
#define USE_THREAD_CACHE 0
|
||||
|
||||
#if STACK_GROW_DIRECTION
|
||||
#define STACK_GROW_DIR_DETECTION
|
||||
#define STACK_DIR_UPPER(a,b) STACK_UPPER(0, a, b)
|
||||
#else
|
||||
#define STACK_GROW_DIR_DETECTION VALUE stack_grow_dir_detection
|
||||
#define STACK_DIR_UPPER(a,b) STACK_UPPER(&stack_grow_dir_detection, a, b)
|
||||
#endif
|
||||
|
||||
#if defined HAVE_PTHREAD_GETATTR_NP || defined HAVE_PTHREAD_ATTR_GET_NP
|
||||
#define STACKADDR_AVAILABLE 1
|
||||
#elif defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP
|
||||
|
|
Loading…
Reference in a new issue