Esempio n. 1
0
/* Set make repeater translator node named NODENAME.  */
static error_t
setrepeater (const char *nodename)
{
  error_t err;
  
  err = console_create_consnode (nodename, &cnode);
  if (err)
    return err;
  
  cnode->read = repeater_read;
  cnode->write = 0;
  cnode->select = repeater_select;
  cnode->open = repeater_open;
  cnode->close = repeater_close;
  cnode->demuxer = 0;
  
  mutex_init (&global_lock);
  
  condition_init (&mousebuf.readcond);
  condition_init (&mousebuf.writecond);
  
  condition_init (&select_alert);
  condition_implies (&mousebuf.readcond, &select_alert);
  
  console_register_consnode (cnode);
  
  return 0;
}
Esempio n. 2
0
static error_t
hurdio_init (void)
{
  condition_init (&hurdio_writer_condition);
  condition_init (&hurdio_assert_dtr_condition);

  cthread_detach (cthread_fork (hurdio_reader_loop, 0));
  cthread_detach (cthread_fork (hurdio_writer_loop, 0));
  return 0;
}
Esempio n. 3
0
struct thread* thread_fork(void(*target)(void*), void* arg) {
	// allocate a new thread control block and stack
	struct thread* new_thread = malloc(sizeof(struct thread));
	new_thread->stack_pointer = malloc(STACK_SIZE) + STACK_SIZE;
	// Set the new thread's initial argument and initial function.
	new_thread->initial_function = target;
	new_thread->initial_argument = arg;
	// 	Set the current thread's state to READY and enqueue it on the ready list.
	if(current_thread->state != BLOCKED)
		current_thread->state = READY;
	thread_enqueue(&ready_list, current_thread);
	// Set the new thread's state to RUNNING.
	new_thread->state = RUNNING;
	// allocate mutex lock and condition
	new_thread->mutexLock = malloc(sizeof(struct mutex));
	new_thread->condList = malloc(sizeof(struct condition));
	mutex_init(new_thread->mutexLock);
	condition_init(new_thread->condList);
	// Save a pointer to the current thread in a temporary variable, then set the current thread to the new thread.
	struct thread* temp = current_thread;
	current_thread = new_thread;
	// Call thread_start with the old current thread as old and the new current thread as new.
	thread_start(temp, current_thread);

	return new_thread;
};
Esempio n. 4
0
/* Initialize mailbox system, called by kernel on startup  */
void mbox_init(void)
{
    int i;

    for (i = 0; i < MAX_MBOX; i++) {
        Q[i].used = 0;
        lock_init(&Q[i].l);
        condition_init(&Q[i].moreSpace);
        condition_init(&Q[i].moreData);
        /*
         * head, tail and count set by open if used == 0 Process X and
         * process Y could both call mbox_close setting count = 0. But
         * the buffer is not flushed.
         */
    }
}
Esempio n. 5
0
void
root_update_init()
{
  mutex_init (&update_lock);
  rwlock_init (&update_rwlock);
  condition_init (&update_wakeup);

  cthread_detach (cthread_fork ( (cthread_fn_t)_root_update_thread, 0));
}
Esempio n. 6
0
//初始化
void threadpool_init(threadpool_t *pool, int threads)
{
	condition_init(&pool -> ready);
	pool -> first = NULL;
	pool -> last = NULL;
	pool -> counter = 0;
	pool -> idle = 0;
	pool -> max_threads = threads;
	pool -> quit = 0;
}
Esempio n. 7
0
/* 初始化线程池 */
void threadpool_init( threadpool_t* pool, int threads ) 
{
   condition_init( &pool->ready ) ; // 初始化条件变量结构体
   pool->first = NULL ; // 设置线程链表头指针
   pool->last = NULL ; // 设置线程链表尾指针
   pool->counter = 0 ; // 设置线程池当前线程数
   pool->idle = 0 ; // 设置线程池当前空闲线程数
   pool->max_threads = threads ; // 设置线程池最大线程数
   pool->quit = 0 ; // quit = 0,线程池运行状态;quit = 1,线程池销毁状态
}
Esempio n. 8
0
void dbcache::loadDB(QSqlDatabase &db, entityviews::dbcs_module_type &dbc)
{
    item_extended_cost_init(db,dbc);
    //disenchant_loot_init(db);
    item_random_property_and_suffix_init(db,dbc);
    lock_type_init(db,dbc);
    condition_init(db);
    npc_text_init(db);
    gossip_menu_init(db);
    gossip_option_init(db);
    gossip_init(db);
}
Esempio n. 9
0
struct bio *bio_alloc(void)
{
	struct bio *bio = kmem_cache_alloc(ide_bio_cache);

	if (!bio)
		return 0;

	memset(bio, 0, sizeof(*bio));
	condition_init(&bio->cond);
	mutex_init(&bio->mutex);
	list_init(&bio->link);
	bio->status = BIO_NONE;
	return bio;
}
Esempio n. 10
0
/**
 * @brief Initialize a message event.
 *
 * @param event Event.
 */
void event_init(Event *event)
{
	int i;

	event->size = 4;
	event->first = 0;
	event->end = 0;
	event->ring = (char**) malloc(event->size * sizeof (char*));
	if (event->ring == NULL) fatal_error("cannot allocate event buffers\n");
	for (i = 0; i < event->size; ++i) event->ring[i] = NULL;
	spin_init(event);
	lock_init(event);
	condition_init(event);

	event->loop = true;
}
Esempio n. 11
0
WA_recursiveLock WA_createLock(const char *name)
{
   CThreadRecursiveLock *lock;

   lock = WOMALLOC(sizeof(CThreadRecursiveLock));
   if (lock)
   {
      mutex_init(&lock->m);
      condition_init(&lock->c);
      lock->lockCount = 0;
      lock->lockingThread = NULL;
      if (name)
         lock->name = name;
      else
         lock->name = unnamedLock;
   }
   return lock;
}
Esempio n. 12
0
struct socket *
sock_alloc (void)
{
  static ino_t nextino;		/* locked by global_lock */
  struct socket *sock;
  struct condition *c;

  sock = malloc (sizeof *sock + sizeof (struct condition));
  if (!sock)
    return 0;
  c = (void *) &sock[1];
  condition_init (c);
  bzero (sock, sizeof *sock);
  sock->state = SS_UNCONNECTED;
  sock->identity = MACH_PORT_NULL;
  sock->refcnt = 1;
  sock->wait = (void *) c;

  if (nextino == 0)
    nextino = 2;
  sock->st_ino = nextino++;

  return sock;
}
Esempio n. 13
0
int 
ldap_pvt_thread_cond_init( ldap_pvt_thread_cond_t *cond )
{
	condition_init( cond );
	return( 0 );
}
Esempio n. 14
0
int waitgroup_init(waitgroup_t *wg) {
    wg->ref = 0;
    if (condition_init(&wg->cond) < 0)
	return -1;
    return mutex_init(&wg->mutex);
}