[前][次][番号順一覧][スレッド一覧]

ruby-changes:13049

From: nobu <ko1@a...>
Date: Wed, 9 Sep 2009 00:27:46 +0900 (JST)
Subject: [ruby-changes:13049] Ruby:r24796 (trunk): * cont.c (cont_data_type, fiber_data_type): typed.

nobu	2009-09-09 00:27:31 +0900 (Wed, 09 Sep 2009)

  New Revision: 24796

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=24796

  Log:
    * cont.c (cont_data_type, fiber_data_type): typed.

  Modified files:
    trunk/ChangeLog
    trunk/cont.c
    trunk/version.h

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24795)
+++ ChangeLog	(revision 24796)
@@ -1,3 +1,7 @@
+Wed Sep  9 00:27:29 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* cont.c (cont_data_type, fiber_data_type): typed.
+
 Tue Sep  8 22:37:59 2009  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/tempfile.rb, lib/tmpdir.rb (Tmpname): extracted new module.
Index: cont.c
===================================================================
--- cont.c	(revision 24795)
+++ cont.c	(revision 24796)
@@ -58,16 +58,17 @@
     struct rb_fiber_struct *next_fiber;
 } rb_fiber_t;
 
+static const rb_data_type_t cont_data_type, fiber_data_type;
 static VALUE rb_cContinuation;
 static VALUE rb_cFiber;
 static VALUE rb_eFiberError;
 
 #define GetContPtr(obj, ptr)  \
-  Data_Get_Struct(obj, rb_context_t, ptr)
+    TypedData_Get_Struct(obj, rb_context_t, &cont_data_type, ptr)
 
 #define GetFiberPtr(obj, ptr)  do {\
-  ptr = (rb_fiber_t*)DATA_PTR(obj);\
-  if (!ptr) rb_raise(rb_eFiberError, "uninitialized fiber");\
+    TypedData_Get_Struct(obj, rb_fiber_t, &fiber_data_type, ptr); \
+    if (!ptr) rb_raise(rb_eFiberError, "uninitialized fiber"); \
 } while(0)
 
 NOINLINE(static VALUE cont_capture(volatile int *stat));
@@ -126,6 +127,35 @@
     RUBY_FREE_LEAVE("cont");
 }
 
+static size_t
+cont_memsize(void *ptr)
+{
+    rb_context_t *cont = ptr;
+    size_t size = 0;
+    if (cont) {
+	size = sizeof(*cont);
+	if (cont->vm_stack) {
+#ifdef CAPTURE_JUST_VALID_VM_STACK
+	    size_t n = (cont->vm_stack_slen + cont->vm_stack_clen);
+#else
+	    size_t n = cont->saved_thread.stack_size;
+#endif
+	    size += n * sizeof(*cont->vm_stack);
+	}
+
+	if (cont->machine_stack) {
+	    size += cont->machine_stack_size * sizeof(*cont->machine_stack);
+	}
+#ifdef __ia64
+	if (cont->machine_register_stack) {
+	    size += (cont->machine_register_stack + cont->machine_register_stack_size) *
+		sizeof(*cont->machine_register_stack);
+	}
+#endif
+    }
+    return size;
+}
+
 static void
 fiber_mark(void *ptr)
 {
@@ -176,6 +206,21 @@
     RUBY_FREE_LEAVE("fiber");
 }
 
+static size_t
+fiber_memsize(void *ptr)
+{
+    rb_fiber_t *fib = ptr;
+    size_t size = 0;
+    if (ptr) {
+	size = sizeof(*fib);
+	if (fib->cont.type != ROOT_FIBER_CONTEXT) {
+	    size += st_memsize(fib->cont.saved_thread.local_storage);
+	}
+	size += cont_memsize(&fib->cont);
+    }
+    return 0;
+}
+
 static void
 cont_save_machine_stack(rb_thread_t *th, rb_context_t *cont)
 {
@@ -226,6 +271,11 @@
 #endif
 }
 
+static const rb_data_type_t cont_data_type = {
+    "continuation",
+    cont_mark, cont_free, cont_memsize,
+};
+
 static void
 cont_init(rb_context_t *cont)
 {
@@ -241,7 +291,7 @@
     rb_context_t *cont;
     volatile VALUE contval;
 
-    contval = Data_Make_Struct(klass, rb_context_t, cont_mark, cont_free, cont);
+    contval = TypedData_Make_Struct(klass, rb_context_t, &cont_data_type, cont);
     cont->self = contval;
     cont_init(cont);
     return cont;
@@ -653,10 +703,15 @@
 
 #define FIBER_VM_STACK_SIZE (4 * 1024)
 
+static const rb_data_type_t fiber_data_type = {
+    "fiber",
+    fiber_mark, fiber_free, fiber_memsize,
+};
+
 static VALUE
 fiber_alloc(VALUE klass)
 {
-    return Data_Wrap_Struct(klass, fiber_mark, fiber_free, 0);
+    return TypedData_Wrap_Struct(klass, &fiber_data_type, 0);
 }
 
 static rb_fiber_t*
Index: version.h
===================================================================
--- version.h	(revision 24795)
+++ version.h	(revision 24796)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.2"
-#define RUBY_RELEASE_DATE "2009-09-08"
+#define RUBY_RELEASE_DATE "2009-09-09"
 #define RUBY_PATCHLEVEL -1
 #define RUBY_BRANCH_NAME "trunk"
 
@@ -8,7 +8,7 @@
 #define RUBY_VERSION_TEENY 1
 #define RUBY_RELEASE_YEAR 2009
 #define RUBY_RELEASE_MONTH 9
-#define RUBY_RELEASE_DAY 8
+#define RUBY_RELEASE_DAY 9
 
 #include "ruby/version.h"
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]