From 99d65b14b4ec3a546a28b6b17b3b4553eaf27b2f Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 5 Jun 2007 04:25:10 +0000 Subject: * compile.c, dir.c, eval.c, eval_jump.h, eval_method.h, numeric.c, pack.c, parse.y, re.c, thread.c, vm.c, vm_dump.c, call_cfunc.ci, thread_pthread.ci, thread_win32.ci: fixed indentation. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- thread.c | 214 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 107 insertions(+), 107 deletions(-) (limited to 'thread.c') diff --git a/thread.c b/thread.c index d0434d286b..763b48ec6b 100644 --- a/thread.c +++ b/thread.c @@ -361,7 +361,7 @@ thread_create_core(VALUE klass, VALUE args, VALUE (*fn)(ANYARGS), void *arg) * call-seq: * Thread.start([args]*) {|args| block } => thread * Thread.fork([args]*) {|args| block } => thread - * + * * Basically the same as Thread::new. However, if class * Thread is subclassed, then calling start in that * subclass will not invoke the subclass's initialize method. @@ -390,7 +390,7 @@ thread_join(rb_thread_t *target_th, double delay) { rb_thread_t *th = GET_THREAD(); double now, limit = timeofday() + delay; - + thread_debug("thread_join (thid: %p)\n", target_th->thread_id); if (target_th->status != THREAD_KILLED) { @@ -440,39 +440,39 @@ thread_join(rb_thread_t *target_th, double delay) * call-seq: * thr.join => thr * thr.join(limit) => thr - * + * * The calling thread will suspend execution and run thr. Does not * return until thr exits or until limit seconds have passed. If * the time limit expires, nil will be returned, otherwise * thr is returned. - * + * * Any threads not joined will be killed when the main program exits. If * thr had previously raised an exception and the * abort_on_exception and $DEBUG flags are not set * (so the exception has not yet been processed) it will be processed at this * time. - * + * * a = Thread.new { print "a"; sleep(10); print "b"; print "c" } * x = Thread.new { print "x"; Thread.pass; print "y"; print "z" } * x.join # Let x thread finish, a will be killed on exit. - * + * * produces: - * + * * axyz - * + * * The following example illustrates the limit parameter. - * + * * y = Thread.new { 4.times { sleep 0.1; puts 'tick... ' }} * puts "Waiting" until y.join(0.15) - * + * * produces: - * + * * tick... * Waiting * tick... * Waitingtick... - * - * + * + * * tick... */ @@ -482,7 +482,7 @@ thread_join_m(int argc, VALUE *argv, VALUE self) rb_thread_t *target_th; double delay = DELAY_INFTY; VALUE limit; - + GetThreadPtr(self, target_th); rb_scan_args(argc, argv, "01", &limit); @@ -495,10 +495,10 @@ thread_join_m(int argc, VALUE *argv, VALUE self) /* * call-seq: * thr.value => obj - * + * * Waits for thr to complete (via Thread#join) and returns * its value. - * + * * a = Thread.new { 2 + 2 } * a.value #=> 4 */ @@ -651,9 +651,9 @@ rb_thread_blocking_region( /* * call-seq: * Thread.pass => nil - * + * * Invokes the thread scheduler to pass execution to another thread. - * + * * a = Thread.new { print "a"; Thread.pass; * print "b"; Thread.pass; * print "c" } @@ -662,9 +662,9 @@ rb_thread_blocking_region( * print "z" } * a.join * b.join - * + * * produces: - * + * * axbycz */ @@ -807,16 +807,16 @@ rb_thread_fd_close(int fd) /* * call-seq: * thr.raise(exception) - * + * * Raises an exception (see Kernel::raise) from thr. The * caller does not have to be thr. - * + * * Thread.abort_on_exception = true * a = Thread.new { sleep(200) } * a.raise("Gotcha") - * + * * produces: - * + * * prog.rb:3: Gotcha (RuntimeError) * from prog.rb:2:in `initialize' * from prog.rb:2:in `new' @@ -838,7 +838,7 @@ thread_raise_m(int argc, VALUE *argv, VALUE self) * thr.exit => thr or nil * thr.kill => thr or nil * thr.terminate => thr or nil - * + * * Terminates thr and schedules another thread to be run. If this thread * is already marked to be killed, exit returns the * Thread. If this is the main thread, or the last thread, exits @@ -875,9 +875,9 @@ rb_thread_kill(VALUE thread) /* * call-seq: * Thread.kill(thread) => thread - * + * * Causes the given thread to exit (see Thread::exit). - * + * * count = 0 * a = Thread.new { loop { count += 1 } } * sleep(0.1) #=> 0 @@ -896,7 +896,7 @@ rb_thread_s_kill(VALUE obj, VALUE th) /* * call-seq: * Thread.exit => thread - * + * * Terminates the currently running thread and schedules another thread to be * run. If this thread is already marked to be killed, exit * returns the Thread. If this is the main thread, or the last @@ -913,15 +913,15 @@ rb_thread_exit(void) /* * call-seq: * thr.wakeup => thr - * + * * Marks thr as eligible for scheduling (it may still remain blocked on * I/O, however). Does not invoke the scheduler (see Thread#run). - * + * * c = Thread.new { Thread.stop; puts "hey!" } * c.wakeup - * + * * produces: - * + * * hey! */ @@ -942,18 +942,18 @@ rb_thread_wakeup(VALUE thread) /* * call-seq: * thr.run => thr - * + * * Wakes up thr, making it eligible for scheduling. If not in a critical * section, then invokes the scheduler. - * + * * a = Thread.new { puts "a"; Thread.stop; puts "c" } * Thread.pass * puts "Got here" * a.run * a.join - * + * * produces: - * + * * a * Got here * c @@ -971,19 +971,19 @@ rb_thread_run(VALUE thread) /* * call-seq: * Thread.stop => nil - * + * * Stops execution of the current thread, putting it into a ``sleep'' state, * and schedules execution of another thread. Resets the ``critical'' condition * to false. - * + * * a = Thread.new { print "a"; Thread.stop; print "c" } * Thread.pass * print "b" * a.run * a.join - * + * * produces: - * + * * abc */ @@ -1006,11 +1006,11 @@ thread_list_i(st_data_t key, st_data_t val, void *data) GetThreadPtr((VALUE)key, th); switch (th->status) { - case THREAD_RUNNABLE: - case THREAD_STOPPED: - case THREAD_TO_KILL: + case THREAD_RUNNABLE: + case THREAD_STOPPED: + case THREAD_TO_KILL: rb_ary_push(ary, th->self); - default: + default: break; } return ST_CONTINUE; @@ -1021,17 +1021,17 @@ thread_list_i(st_data_t key, st_data_t val, void *data) /* * call-seq: * Thread.list => array - * + * * Returns an array of Thread objects for all threads that are * either runnable or stopped. - * + * * Thread.new { sleep(200) } * Thread.new { 1000000.times {|i| i*i } } * Thread.new { Thread.stop } * Thread.list.each {|t| p t} - * + * * produces: - * + * * # * # * # @@ -1055,9 +1055,9 @@ rb_thread_current(void) /* * call-seq: * Thread.current => thread - * + * * Returns the currently executing thread. - * + * * Thread.current #=> # */ @@ -1083,7 +1083,7 @@ rb_thread_s_main(VALUE klass) /* * call-seq: * Thread.abort_on_exception => true or false - * + * * Returns the status of the global ``abort on exception'' condition. The * default is false. When set to true, or if the * global $DEBUG flag is true (perhaps because the @@ -1102,10 +1102,10 @@ rb_thread_s_abort_exc(void) /* * call-seq: * Thread.abort_on_exception= boolean => true or false - * + * * When set to true, all threads will abort if an exception is * raised. Returns the new state. - * + * * Thread.abort_on_exception = true * t1 = Thread.new do * puts "In new thread" @@ -1113,9 +1113,9 @@ rb_thread_s_abort_exc(void) * end * sleep(1) * puts "not reached" - * + * * produces: - * + * * In new thread * prog.rb:4: Exception from thread (RuntimeError) * from prog.rb:2:in `initialize' @@ -1135,7 +1135,7 @@ rb_thread_s_abort_exc_set(VALUE self, VALUE val) /* * call-seq: * thr.abort_on_exception => true or false - * + * * Returns the status of the thread-local ``abort on exception'' condition for * thr. The default is false. See also * Thread::abort_on_exception=. @@ -1153,7 +1153,7 @@ rb_thread_abort_exc(VALUE thread) /* * call-seq: * thr.abort_on_exception= boolean => true or false - * + * * When set to true, causes all threads (including the main * program) to abort if an exception is raised in thr. The process will * effectively exit(0). @@ -1174,10 +1174,10 @@ rb_thread_abort_exc_set(VALUE thread, VALUE val) /* * call-seq: * thr.group => thgrp or nil - * + * * Returns the ThreadGroup which contains thr, or nil if * the thread is not a member of any group. - * + * * Thread.main.group #=> # */ @@ -1199,15 +1199,15 @@ static const char * thread_status_name(enum rb_thread_status status) { switch (status) { - case THREAD_RUNNABLE: + case THREAD_RUNNABLE: return "run"; - case THREAD_STOPPED: + case THREAD_STOPPED: return "sleep"; - case THREAD_TO_KILL: + case THREAD_TO_KILL: return "aborting"; - case THREAD_KILLED: + case THREAD_KILLED: return "dead"; - default: + default: return "unknown"; } } @@ -1222,13 +1222,13 @@ rb_thread_dead(rb_thread_t *th) /* * call-seq: * thr.status => string, false or nil - * + * * Returns the status of thr: ``sleep'' if thr is * sleeping or waiting on I/O, ``run'' if thr is executing, * ``aborting'' if thr is aborting, false if * thr terminated normally, and nil if thr * terminated with an exception. - * + * * a = Thread.new { raise("die now") } * b = Thread.new { Thread.stop } * c = Thread.new { Thread.exit } @@ -1262,9 +1262,9 @@ rb_thread_status(VALUE thread) /* * call-seq: * thr.alive? => true or false - * + * * Returns true if thr is running or sleeping. - * + * * thr = Thread.new { } * thr.join #=> # * Thread.current.alive? #=> true @@ -1285,9 +1285,9 @@ rb_thread_alive_p(VALUE thread) /* * call-seq: * thr.stop? => true or false - * + * * Returns true if thr is dead or sleeping. - * + * * a = Thread.new { Thread.stop } * b = Thread.current * a.stop? #=> true @@ -1310,10 +1310,10 @@ rb_thread_stop_p(VALUE thread) /* * call-seq: * thr.safe_level => integer - * + * * Returns the safe level in effect for thr. Setting thread-local safe * levels can help when implementing sandboxes which run insecure code. - * + * * thr = Thread.new { $SAFE = 3; sleep } * Thread.current.safe_level #=> 0 * thr.safe_level #=> 3 @@ -1373,18 +1373,18 @@ rb_thread_local_aref(VALUE thread, ID id) /* * call-seq: * thr[sym] => obj or nil - * + * * Attribute Reference---Returns the value of a thread-local variable, using * either a symbol or a string name. If the specified variable does not exist, * returns nil. - * + * * a = Thread.new { Thread.current["name"] = "A"; Thread.stop } * b = Thread.new { Thread.current[:name] = "B"; Thread.stop } * c = Thread.new { Thread.current["name"] = "C"; Thread.stop } * Thread.list.each {|x| puts "#{x.inspect}: #{x[:name]}" } - * + * * produces: - * + * * #: C * #: B * #: A @@ -1423,7 +1423,7 @@ rb_thread_local_aset(VALUE thread, ID id, VALUE val) /* * call-seq: * thr[sym] = obj => obj - * + * * Attribute Assignment---Sets or creates the value of a thread-local variable, * using either a symbol or a string. See also Thread#[]. */ @@ -1437,10 +1437,10 @@ rb_thread_aset(VALUE self, ID id, VALUE val) /* * call-seq: * thr.key?(sym) => true or false - * + * * Returns true if the given string (or symbol) exists as a * thread-local variable. - * + * * me = Thread.current * me[:oliver] = "a" * me.key?(:oliver) #=> true @@ -1483,9 +1483,9 @@ rb_thread_alone() /* * call-seq: * thr.keys => array - * + * * Returns an an array of the names of the thread-local variables (as Symbols). - * + * * thr = Thread.new do * Thread.current[:cat] = 'meow' * Thread.current["dog"] = 'woof' @@ -1531,16 +1531,16 @@ rb_thread_priority(VALUE thread) /* * call-seq: * thr.priority= integer => thr - * + * * Sets the priority of thr to integer. Higher-priority threads * will run before lower-priority threads. - * + * * count1 = count2 = 0 * a = Thread.new do * loop { count1 += 1 } * end * a.priority = -1 - * + * * b = Thread.new do * loop { count2 += 1 } * end @@ -1660,7 +1660,7 @@ cmp_tv(const struct timeval *a, const struct timeval *b) return (d != 0) ? d : (a->tv_usec - b->tv_usec); } -static int +static int subst(struct timeval *rest, const struct timeval *wait) { while (rest->tv_usec < wait->tv_usec) { @@ -1915,7 +1915,7 @@ struct thgroup { * threads as a group. A Thread can belong to only one * ThreadGroup at a time; adding a thread to a new group will * remove it from any previous group. - * + * * Newly created threads belong to the same group as the thread from which they * were created. */ @@ -1957,10 +1957,10 @@ thgroup_list_i(st_data_t key, st_data_t val, st_data_t data) /* * call-seq: * thgrp.list => array - * + * * Returns an array of all existing Thread objects that belong to * this group. - * + * * ThreadGroup::Default.list #=> [#] */ @@ -1979,11 +1979,11 @@ thgroup_list(VALUE group) /* * call-seq: * thgrp.enclose => thgrp - * + * * Prevents threads from being added to or removed from the receiving * ThreadGroup. New threads can still be started in an enclosed * ThreadGroup. - * + * * ThreadGroup::Default.enclose #=> # * thr = Thread::new { Thread.stop } #=> # * tg = ThreadGroup::new #=> # @@ -2009,7 +2009,7 @@ thgroup_enclose(VALUE group) /* * call-seq: * thgrp.enclosed? => true or false - * + * * Returns true if thgrp is enclosed. See also * ThreadGroup#enclose. */ @@ -2029,10 +2029,10 @@ thgroup_enclosed_p(VALUE group) /* * call-seq: * thgrp.add(thread) => thgrp - * + * * Adds the given thread to this group, removing it from any other * group to which it may have previously belonged. - * + * * puts "Initial group is #{ThreadGroup::Default.list}" * tg = ThreadGroup.new * t1 = Thread.new { sleep } @@ -2042,9 +2042,9 @@ thgroup_enclosed_p(VALUE group) * tg.add(t1) * puts "Initial group now #{ThreadGroup::Default.list}" * puts "tg group now #{tg.list}" - * + * * produces: - * + * * Initial group is # * t1 is # * t2 is # @@ -2291,7 +2291,7 @@ rb_mutex_sleep(VALUE self, VALUE timeout) * mutex.sleep(timeout = nil) => self * * Releases the lock and sleeps +timeout+ seconds if it is given and - * non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by + * non-nil or forever. Raises +ThreadError+ if +mutex+ wasn't locked by * the current thread. */ static VALUE @@ -2668,7 +2668,7 @@ rb_clear_trace_func(void) * call-seq: * set_trace_func(proc) => proc * set_trace_func(nil) => nil - * + * * Establishes _proc_ as the handler for tracing, or disables * tracing if the parameter is +nil+. _proc_ takes up * to six parameters: an event name, a filename, a line number, an @@ -2764,23 +2764,23 @@ static char * get_event_name(rb_event_flag_t event) { switch (event) { - case RUBY_EVENT_LINE: + case RUBY_EVENT_LINE: return "line"; - case RUBY_EVENT_CLASS: + case RUBY_EVENT_CLASS: return "class"; - case RUBY_EVENT_END: + case RUBY_EVENT_END: return "end"; - case RUBY_EVENT_CALL: + case RUBY_EVENT_CALL: return "call"; - case RUBY_EVENT_RETURN: + case RUBY_EVENT_RETURN: return "return"; - case RUBY_EVENT_C_CALL: + case RUBY_EVENT_C_CALL: return "c-call"; - case RUBY_EVENT_C_RETURN: + case RUBY_EVENT_C_RETURN: return "c-return"; - case RUBY_EVENT_RAISE: + case RUBY_EVENT_RAISE: return "raise"; - default: + default: return "unknown"; } } @@ -2826,7 +2826,7 @@ call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klas /* * +Thread+ encapsulates the behavior of a thread of * execution, including the main thread of the Ruby script. - * + * * In the descriptions of the methods in this class, the parameter _sym_ * refers to a symbol, which is either a quoted string or a * +Symbol+ (such as :name). -- cgit v1.2.3