Sha256: 8dfdc49181f6a6a8f390ee8f3aede2a403732b583fd409cb12dd8e92aad611af

Contents?: true

Size: 1.57 KB

Versions: 19

Compression:

Stored size: 1.57 KB

Contents

#include "byebug.h"

/**
 * A simple linked list containing locked threads, FIFO style.
 */

typedef struct locked_thread_t
{
  VALUE thread;
  struct locked_thread_t *next;
} locked_thread_t;

static locked_thread_t *locked_head = NULL;
static locked_thread_t *locked_tail = NULL;

static int
is_in_locked(VALUE thread)
{
  locked_thread_t *node;

  if (!locked_head)
    return 0;

  for (node = locked_head; node != locked_tail; node = node->next)
    if (node->thread == thread)
      return 1;

  return 0;
}

extern void
add_to_locked(VALUE thread)
{
  locked_thread_t *node;

  if (is_in_locked(thread))
    return;

  node = ALLOC(locked_thread_t);
  node->thread = thread;
  node->next = NULL;

  if (locked_tail)
    locked_tail->next = node;

  locked_tail = node;

  if (!locked_head)
    locked_head = node;
}

extern VALUE
pop_from_locked()
{
  VALUE thread;
  locked_thread_t *node;

  if (!locked_head)
    return Qnil;

  node = locked_head;
  locked_head = locked_head->next;

  if (locked_tail == node)
    locked_tail = NULL;

  thread = node->thread;
  xfree(node);

  return thread;
}

extern void
remove_from_locked(VALUE thread)
{
  locked_thread_t *node;
  locked_thread_t *next_node;

  if (NIL_P(thread) || !locked_head || !is_in_locked(thread))
    return;

  if (locked_head->thread == thread)
  {
    pop_from_locked();
    return;
  }

  for (node = locked_head; node != locked_tail; node = node->next)
    if (node->next && node->next->thread == thread)
    {
      next_node = node->next;
      node->next = next_node->next;
      xfree(next_node);
      return;
    }
}

Version data entries

19 entries across 18 versions & 4 rubygems

Version Path
jets-0.5.5 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/ext/byebug/locker.c
jets-0.5.4 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/ext/byebug/locker.c
jets-0.5.3 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/ext/byebug/locker.c
jets-0.5.2 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/ext/byebug/locker.c
jets-0.5.1 vendor/lambdagem/bundled/gems/ruby/2.5.0/gems/byebug-10.0.0/ext/byebug/locker.c
byebug-10.0.1 ext/byebug/locker.c
byebug-10.0.0 ext/byebug/locker.c
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/byebug-9.1.0/ext/byebug/locker.c
tdiary-5.0.6 vendor/bundle/gems/byebug-9.1.0/ext/byebug/locker.c
byebug-9.1.0 ext/byebug/locker.c
tdiary-5.0.5 vendor/bundle/gems/byebug-9.0.6/ext/byebug/locker.c
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/byebug-9.0.6/ext/byebug/locker.c
tdiary-5.0.4 vendor/bundle/gems/byebug-9.0.6/ext/byebug/locker.c
byebug-9.0.6 ext/byebug/locker.c
byebug-9.0.5 ext/byebug/locker.c
byebug-9.0.4 ext/byebug/locker.c
byebug-9.0.3 ext/byebug/locker.c
byebug-9.0.2 ext/byebug/locker.c
byebug-9.0.1 ext/byebug/locker.c