Sha256: 9048d76bb9281f5cda0e3a6fa1ad3e914c02e159bed62e92dad58cbb971c0f78

Contents?: true

Size: 1.98 KB

Versions: 1

Compression:

Stored size: 1.98 KB

Contents

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
  <title>detach (Rev::Watcher)</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
</head>
<body class="standalone-code">
  <pre>/**
 *  call-seq:
 *    Rev::Watcher.detach -&gt; Rev::Watcher
 * 
 * Detach the watcher from its current Rev::Loop.
 */
static VALUE Rev_Watcher_detach(VALUE self)
{
  struct Rev_Watcher *watcher_data;
  struct Rev_Loop *loop_data;
  VALUE loop_watchers;

  int i;

  Data_Get_Struct(self, struct Rev_Watcher, watcher_data);

  if(watcher_data-&gt;loop == Qnil)
    rb_raise(rb_eRuntimeError, &quot;not attached to a loop&quot;);

  loop_watchers = rb_iv_get(watcher_data-&gt;loop, &quot;@watchers&quot;);

  /* Remove us from the loop's array of active watchers.  This likely
   * has negative performance and scalability characteristics as this
   * isn't an O(1) operation.  Hopefully there's a better way... */
  rb_ary_delete(loop_watchers, self);

  rb_iv_set(
      watcher_data-&gt;loop, 
      &quot;@active_watchers&quot;,
      INT2NUM(NUM2INT(rb_iv_get(watcher_data-&gt;loop, &quot;@active_watchers&quot;)) - 1)
  );

  Data_Get_Struct(watcher_data-&gt;loop, struct Rev_Loop, loop_data);

  /* Iterate through the events in the loop's event buffer.  If there
   * are any pending events from this watcher, mark them NULL.  The
   * dispatch loop will skip them.  This prevents watchers earlier
   * in the event buffer from detaching others which may have pending
   * events in the buffer but get garbage collected in the meantime */
  for(i = 0; i &lt; loop_data-&gt;events_received; i++) {
    if(loop_data-&gt;eventbuf[i].watcher == self)
      loop_data-&gt;eventbuf[i].watcher = Qnil;
  }

  watcher_data-&gt;loop = Qnil;

  return self;
}</pre>
</body>
</html>

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rev-0.1.2 doc/rdoc/classes/Rev/Watcher.src/M000114.html