Ejemplo n.º 1
0
static VALUE
run_thread(VALUE thread)
{
    thread = wake_thread(thread);
    if (RTEST(thread) && !rb_thread_critical)
	rb_thread_schedule();
    return thread;
}
Ejemplo n.º 2
0
static void
assert_no_survivors(List *waiting, const char *label, void *addr)
{
    Entry *entry;
    for (entry = waiting->entries; entry; entry = entry->next) {
        if (RTEST(wake_thread(entry->value))) {
            rb_bug("%s %p freed with live thread(s) waiting", label, addr);
        }
    }
}
Ejemplo n.º 3
0
static VALUE
wake_one(List *list)
{
    VALUE waking;

    waking = Qnil;
    while (list->entries && !RTEST(waking)) {
        waking = wake_thread(shift_list(list));
    }

    return waking;
}
Ejemplo n.º 4
0
static void
wait_condvar(ConditionVariable *condvar, Mutex *mutex)
{
    VALUE waking;

    rb_thread_critical = 1;
    if (rb_thread_current() != mutex->owner) {
        rb_thread_critical = 0;
        rb_raise(rb_eThreadError, "not owner of the synchronization mutex");
    }
    waking = unlock_mutex_inner(mutex);
    if (RTEST(waking)) {
	wake_thread(waking);
    }
    rb_ensure(wait_list, (VALUE)&condvar->waiting, lock_mutex, (VALUE)mutex);
}
Ejemplo n.º 5
0
int destroy_thread(unsigned int id)
{
    struct thread_struct *t = get_thread(id);

    if(t == NULL)
    {
        printk("tried to destory an invalid thread. id = %i\n",id);
        return -1;
    }

    /* notify listeners */
    if(t->waiting_thread != 0)
        wake_thread(t->waiting_thread);

    // kfree(threads[id])

    threads[id-1] = NULL;
    nthreads--;
    return 0;
}
Ejemplo n.º 6
0
Archivo: msg.c Proyecto: herumi/kernel
void sys_send (struct msg *m, options_t options){

  if(get_current_tid() == Posts[post].owner){

  if(Threads[Posts[m->dest].owner].vm == Threads[Posts[m->from].owner].vm){
    if(m->dest > POST_NUM_MAX || Posts[m->dest].owner == 0){
      // TODO: send a error msg
    }

    prepend_to_list(Posts[m->dest].received, m);
    wake_thread(Posts[m->dest].owner);

  }else{
    // TODO: move a page of a message to dest
    if(Posts[m->dest].handler == NULL){
      // TODO: prepend_to_list(Posts[m->dest].received, m);
    }else{
      // TODO: create thread and call handler
    }
  }
}


struct msg *sys_recv (post_id_t post, options_t options){
  struct msg *m;

  if(get_current_tid() != Posts[post].owner)
    return NULL;

  if(is_list_empty(Posts[post].received)){
    if(options & MSG_NOWAIT)
      return NULL;

    // wait for a message
    sleep_thread(Posts[m->dest].owner);
  }

  Posts[post].received = pop_from_list(Posts[post].received, (void *) &m);
  return m;
}


void sys_await (post_id_t post, void (*handler)(struct msg *m), uintmax_t max_thread_num){

  if(get_current_tid() != Posts[post].owner)
    return;

  Posts[post].handler = handler;
  Posts[post].max_thread_num = max_thread_max;
}


struct msg *compose (size_t body_size){

  return allocate_memory_block(sizeof(struct msg) + body_size);
}


void discard (struct msg *m){

  free_memory_block(m);
}