Esempio n. 1
0
static char *test_q_transfer() {
  packet *q = q_create();
  packet *rq = q_create();
  packet p = pkt_create(DATA, 1, 2, 3, 4);
  packet p2;
  q_write(p, 0, rq, 4);
  q_transfer(rq, q, 4);
  q_read(&p2, 0, q, 4);
  mu_assert("FAIL: test_q_transfer", (p.x == p2.x) && (p.y == p2.y));
  q_destroy(q);
  q_destroy(rq);
  return NULL;
}
Esempio n. 2
0
void saal_okay(SIG_ENTITY *sig)
{
    SOCKET *curr;

    trace_msg("SAAL came up");
#ifdef THOMFLEX
    /*
     * Some versions of the Thomson Thomflex 5000 won't do any signaling before
     * they get a RESTART. Whenever SAAL comes up, this may indicate that the
     * switch got booted, so we send that RESTART. We also have to clear all
     * pending connections, which isn't that nice ... Note that the rest of the
     * RESTART state machine is not implemented, so the RESTART ACKNOWLEDGE
     * will yield a warning.
     */
    {
	Q_DSC dsc;
	int size;

	clear_all_calls(sig);
	q_create(&dsc,q_buffer,MAX_Q_MSG);
	q_assign(&dsc,QF_msg_type,QMSG_RESTART);
	q_assign(&dsc,QF_call_ref,0);
	q_assign(&dsc,QF_rst_class,ATM_RST_ALL_VC);
	if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size);
    }
#endif
    if (!t309) return;
    stop_timer(t309);
    t309 = NULL;
    for (curr = sockets; curr; curr = curr->next)
	if (curr->sig == sig && curr->call_state != cs_null)
	    send_status_enq(curr);
}
Esempio n. 3
0
int send_call_proceeding(SOCKET *sock)
{
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_CALL_PROC);
    q_assign(&dsc,QF_call_ref,sock->call_ref);
    if (sock->sig->mode == sm_net) {
	int vpci,vci;

	sock->pvc.sap_family = AF_ATMPVC;
	vpci = sock->sig->signaling_pvc.sap_addr.itf;
	sock->pvc.sap_addr.itf = get_itf(sock->sig,&vpci);
	sock->pvc.sap_addr.vpi = vpci;
	vci = get_vci(sock->pvc.sap_addr.itf);
	if (vci < 0) {
	    (void) q_close(&dsc);
	    return vci;
	}
	sock->pvc.sap_addr.vci = vci;
    }
    if (sock->sig->mode != sm_user) {
	q_assign(&dsc,QF_vpi,sock->pvc.sap_addr.vpi);
	q_assign(&dsc,QF_vci,sock->pvc.sap_addr.vci);
    }
    if (sock->ep_ref >= 0) q_assign(&dsc,QF_ep_ref,sock->ep_ref);
    if ((size = q_close(&dsc)) >= 0) to_signaling(sock->sig,q_buffer,size);
    return 0;
}
Esempio n. 4
0
/*
 * Setup function
 */
void
scheduler_bootstrap(void)
{
	runqueue = q_create(32);
	if (runqueue == NULL) {
		panic("scheduler: Could not create run queue\n");
	}
}
Esempio n. 5
0
int root_thread_init (void)

{
    u_long err, args[4];

    err = q_create("CNSQ",16,Q_LIMIT|Q_FIFO,&message_qid);
    args[0] = message_qid;

    if (err != SUCCESS)
	{
	xnprintf("q_create() failed, errno %lu",err);
	return err;
	}

    err = t_create("CONS",
		   CONSUMER_TASK_PRI,
		   CONSUMER_SSTACK_SIZE,
		   CONSUMER_USTACK_SIZE,
		   0,
		   &consumer_tid);

    if (err != SUCCESS)
	{
	xnprintf("t_create() failed, errno %lu",err);
	return err;
	}

    err = t_start(consumer_tid,0,consumer_task,args);

    if (err != SUCCESS)
	{
	xnprintf("t_start() failed, errno %lu",err);
	return err;
	}

    err = t_create("PROD",
		   PRODUCER_TASK_PRI,
		   PRODUCER_SSTACK_SIZE,
		   PRODUCER_USTACK_SIZE,
		   0,
		   &producer_tid);

    if (err != SUCCESS)
	{
	xnprintf("t_create() failed, errno %lu",err);
	return err;
	}

    err = t_start(producer_tid,0,producer_task,args);

    if (err != SUCCESS)
	{
	xnprintf("t_start() failed, errno %lu",err);
	return err;
	}

    return 0;
}
Esempio n. 6
0
void coremap_finalize(void){
	coremap_lock = lock_create("coremap lock");
	id_not_used = q_create(num_frames);

	if (coremap_lock == NULL || id_not_used == NULL){
		panic("Not enough memory for the base system!!!!\n");
	}
	booting = false;
}
/*
 * Setup function
 */
void
scheduler_bootstrap(void)
{
	runqueue = q_create(32);
	if (runqueue == NULL) {
		panic("scheduler: Could not create run queue\n");
	}
	kprintf("Round Robin Scheduler in use\n");
}
Esempio n. 8
0
/* 
 * The simulation driver will call this function once before starting
 * the simulation
 *
 * You can use it to initialize synchronization and other variables.
 * 
 */
void
intersection_sync_init(void)
{
  /* replace this default implementation with your own implementation */

  // intersectionSem = sem_create("intersectionSem",1);
  intersection_lock = lock_create("intersectionlock"); 
  
  next_lights = q_create(4);

  // // Direction x = north;
  // n = south;
  // Direction *x_p = &n;
  // // Direction x1 = south;
  // Direction *x1_p = &n;
  // // Direction x2 = east;
  // Direction *x2_p = &n;

  north_dir = north;
  south_dir = south;
  east_dir = east;
  west_dir = west;
  num_vehicles_waiting_north = 0;
  num_vehicles_waiting_south = 0;
  num_vehicles_waiting_east = 0;
  num_vehicles_waiting_west = 0;
  num_vehicles_waiting_b = 0;
  // Direction *x3_p = &n;
  
  // q_addtail(next_lights, x_p);
  // q_addtail(next_lights, x1_p);
  // q_addtail(next_lights, x2_p);
  // q_addtail(next_lights, x3_p);
  // current_light = q_peek(next_lights);
  // n = north;
  // current_light = &n;
  //*num_vehicles_waiting = 0;
  is_waiting = false;
  cv_south_go = cv_create("cv_south");
  cv_north_go = cv_create("cv_north");
  cv_east_go = cv_create("cv_east");
  cv_west_go = cv_create("cv_west");
  // if (intersectionSem == NULL) {
  //   panic("could not create intersection semaphore");
  // }

  if (intersection_lock == NULL) {
    panic("could not create intersection lock");
  }

  if (cv_south_go == NULL || cv_north_go == NULL || cv_east_go == NULL || cv_west_go == NULL) {
    panic("could not create intersection cv lock");
  }

  return;
}
Esempio n. 9
0
static char *test_q_set_last_op() {
  packet *q = q_create();
  q_set_last_op(WRITE, 0, 0, q, N);
  mu_assert("FAIL: test_q_set_last_op [1]", q_last_op_is_write(0, 0, q, N));
  q_set_last_op(READ, 4, 0, q, N);
  mu_assert("FAIL: test_q_set_last_op [2]", !q_last_op_is_write(4, 0, q, N));
  mu_assert("FAIL: test_q_set_last_op [3]", q_last_op_is_read(4, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 10
0
static char *test_q_set_tail_index() {
  packet *q = q_create();
  q_set_tail_index(10, 0, 0, q, N);
  mu_assert("FAIL: test_q_set_tail_index [1]", q_get_tail_index(0, 0, q, N) == 10);
  q_set_tail_index(0, 0, 0, q, N);
  mu_assert("FAIL: test_q_set_tail_index [2]", q_get_tail_index(0, 0, q, N) == 0);
  mu_assert("FAIL: test_q_set_tail_index [3]", q_get_tail_index(1, 0, q, N) == 0);
  q_destroy(q);
  return NULL;
}
Esempio n. 11
0
static char *test_q_get_head_index() {
  packet *q = q_create();
  packet i;
  mu_assert("FAIL: test_q_get_head_index [1]", q_get_head_index(0, 0, q, N) == 0);
  q_write(i, 0, q, N);
  q_read(&i, 0, q, N);
  mu_assert("FAIL: test_q_get_head_index [2]", q_get_head_index(0, 0, q, N) == 1);
  q_destroy(q);
  return NULL;
}
Esempio n. 12
0
static void send_conn_avail(SOCKET *sock)
{
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_CONN_AVAIL);
    q_assign(&dsc,QF_call_ref,sock->call_ref);
    if ((size = q_close(&dsc)) >= 0) to_signaling(sock->sig,q_buffer,size);
}
Esempio n. 13
0
static char *test_q_is_empty() {
  packet *q = q_create();
  packet p = pkt_create(ERROR, 0, 0, 0, 0);
  mu_assert("FAIL: test_q_is_empty [1]", q_is_empty(0, 0, q, N));
  q_write(p, 0, q, N);
  mu_assert("FAIL: test_q_is_empty [2]", !q_is_empty(0, 0, q, N));
  q_read(&p, 0, q, N);
  mu_assert("FAIL: test_q_is_empty [3]", q_is_empty(0, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 14
0
static void send_status_enq(SOCKET *sock)
{
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_STATUS_ENQ);
    q_assign(&dsc,QF_call_ref,sock->call_ref);
    if (sock->ep_ref >= 0) q_assign(&dsc,QF_ep_ref,sock->ep_ref);
    if ((size = q_close(&dsc)) >= 0) to_signaling(sock->sig,q_buffer,size);
    /* @@@ should start T322 */
}
Esempio n. 15
0
static char *test_q_read() {
  packet *q = q_create();
  packet p = pkt_create(REFERENCE, 0, 0, 0, 0);
  packet p2 = pkt_create(ERROR, 0, 0, 0, 0);
  q_write(p, 0, q, N);
  q_read(&p2, 0, q, N);
  mu_assert("FAIL: test_q_read [1]", (p.x == p2.x) && (p.y == p2.y));
  q_read(&p2, 0, q, N);
  mu_assert("FAIL: test_q_read [2]", !q_read(&p2, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 16
0
static char *test_q_is_full() {
  packet *q = q_create();
  packet p = pkt_create(ERROR, 0, 0, 0, 0);
  mu_assert("FAIL: test_q_is_full [1]", !q_is_full(0, 0, q, N));
  for (int i = 0; i < 16; i++) {
    q_write(p, 0, q, N);
  }
  mu_assert("FAIL: test_q_is_full [2]", q_is_full(0, 0, q, N));
  q_read(&p, 0, q, N);
  mu_assert("FAIL: test_q_is_full [3]", !q_is_full(0, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 17
0
static char *test_q_last_op_is_read() {
  packet *q = q_create();
  q_set_last_op(READ, 0, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_read [1]", q_last_op_is_read(0, 0, q, N));
  q_set_last_op(READ, 1, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_read [2]", q_last_op_is_read(1, 0, q, N));
  q_set_last_op(READ, 2, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_read [3]", q_last_op_is_read(2, 0, q, N));
  q_set_last_op(WRITE, 3, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_read [4]", !q_last_op_is_read(3, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 18
0
static void send_drop_party_ack(SIG_ENTITY *sig,unsigned long call_ref,
  unsigned short ep_ref,unsigned char cause)
{
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_DROP_PARTY_ACK);
    q_assign(&dsc,QF_call_ref,call_ref);
    q_assign(&dsc,QF_ep_ref,ep_ref);
    q_assign(&dsc,QF_cause,cause);
    if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size);
}
Esempio n. 19
0
static char *test_q_last_op_is_write() {
  packet *q = q_create();
  q_set_last_op(WRITE, 0, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_write [1]", q_last_op_is_write(0, 0, q, N));
  q_set_last_op(WRITE, 1, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_write [2]", q_last_op_is_write(1, 0, q, N));
  q_set_last_op(WRITE, 2, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_write [3]", q_last_op_is_write(2, 0, q, N));
  q_set_last_op(READ, 3, 0, q, N);
  mu_assert("FAIL: test_q_last_op_is_write [4]", !q_last_op_is_write(3, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 20
0
static char *test_q_size() {
  packet *q = q_create();
  packet p = pkt_create(ERROR, 0, 0, 0, 0);
  mu_assert("FAIL: test_q_size [1]", q_size(0, 0, q, N) == 0);
  for (int i = 0; i < 20; i++) {
    q_write(p, 0, q, N);
  }
  mu_assert("FAIL: test_q_size [2]", q_size(0, 0, q, N) == 16);
  q_read(&p, 0, q, N);
  mu_assert("FAIL: test_q_size [3]", q_size(0, 0, q, N) == 15);
  q_destroy(q);
  return NULL;
}
Esempio n. 21
0
/*
 * Suspend execution for n seconds.
 */
void
clocksleep(int num_secs)
{
	int s;

    if(first) {lbolt = q_create(1); TQInit(&lboltq);}
    first = 0;
	s = splhigh();
	while (num_secs > 0) {
		thread_sleep(&lboltq);
		num_secs--;
	}
	splx(s);
}
Esempio n. 22
0
static char *test_q_write() {
  packet *q = q_create();
  packet p = pkt_create(DATA, 1, 2, 3, 4);
  q_write(p, 0, q, N);
  mu_assert("FAIL: test_q_write [1]", !q_is_empty(0, 0, q, N));
  q_write(p, 0, q, N);
  mu_assert("FAIL: test_q_write [2]", q_size(0, 0, q, N) == 2);
  for (int i = 0; i < 14; i++) {
    q_write(p, 0, q, N);
  }
  mu_assert("FAIL: test_q_write [3]", !q_write(p, 0, q, N));
  q_destroy(q);
  return NULL;
}
Esempio n. 23
0
/*
 * Setup function
 */
void
scheduler_bootstrap(void)
{
	runqueue = q_create(32);
	if (runqueue == NULL) {
		panic("scheduler: Could not create run queue\n");
	}

	// Print the scheduler type
	if(scheduler_type == SCHEDULER_FIFO)
		kprintf("\n\n***Using FIFO Scheduler Algorithm***\n\n");
	if(scheduler_type == SCHEDULER_RANDOM)
		kprintf("\n\n***Using Random Scheduler Algorithm***\n\n");
	if(scheduler_type == SCHEDULER_RANDOM)
		kprintf("\n\n***Using Multi-Level Feedback Queue Scheduler Algorithm***\n\n");
}
Esempio n. 24
0
int main(int argc, char *argv[])
{
	u_long args[] = { 1, 2, 3, 4 }, msgbuf[4], count;
	int ret, n;

	copperplate_init(argc, argv);

	traceobj_init(&trobj, argv[0], sizeof(tseq) / sizeof(int));

	ret = q_create("QUEUE", Q_NOLIMIT, 0, &qid);
	traceobj_assert(&trobj, ret == SUCCESS);

	ret = t_create("TSKA", 21, 0, 0, 0, &tidA);
	traceobj_assert(&trobj, ret == SUCCESS);

	ret = t_create("TSKB", 20, 0, 0, 0, &tidB);
	traceobj_assert(&trobj, ret == SUCCESS);

	ret = t_start(tidA, 0, task_A, args);
	traceobj_assert(&trobj, ret == SUCCESS);

	ret = t_start(tidB, 0, task_B, args);
	traceobj_assert(&trobj, ret == SUCCESS);

	for (n = 0; n < 3; n++) {
		msgbuf[0] = n + 1;
		msgbuf[1] = n + 2;
		msgbuf[2] = n + 3;
		msgbuf[3] = n + 4;
		count = 0;
		traceobj_mark(&trobj, 7);
		ret = q_broadcast(qid, msgbuf, &count);
		traceobj_assert(&trobj, ret == SUCCESS && count == 2);
	}

	traceobj_mark(&trobj, 8);

	traceobj_join(&trobj);

	traceobj_verify(&trobj, tseq, sizeof(tseq) / sizeof(int));

	ret = q_delete(qid);
	traceobj_assert(&trobj, ret == SUCCESS);

	exit(0);
}
Esempio n. 25
0
static void send_restart_ack(SIG_ENTITY *sig,unsigned long call_ref,int vpi,
  int vci)
{
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_REST_ACK);
    q_assign(&dsc,QF_call_ref,call_ref);
    if (!vpi && !vci) q_assign(&dsc,QF_rst_class,ATM_RST_ALL_VC);
    else {
	q_assign(&dsc,QF_rst_class,ATM_RST_IND_VC);
	q_assign(&dsc,QF_vpi,vpi);
	q_assign(&dsc,QF_vci,vci);
    }
    if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size);
}
Esempio n. 26
0
void
hardclock(void)
{
	/*
	 * Collect statistics here as desired.
	 */


    if(first) {lbolt = q_create(1); TQInit(&lboltq);}
    first = 0;
	lbolt_counter++;
	if (lbolt_counter >= HZ) {
		lbolt_counter = 0;
		thread_wakeup(&lboltq);
	}

	thread_yield();
}
Esempio n. 27
0
void test_q()
{
    printf("\ntesting queue\n");

    int capacity = 128;
    struct qnode* q = q_create(capacity);
    
    int num = 200;
    for (int i = 0; i < num; ++i) {
        q_enqueue(q, i);
    }

    while (!q_empty(q)) {
        printf("%d ", q_dequeue(q));
    }

    q_destroy(q);
}
Esempio n. 28
0
/*
 * Create an interpreter pool.
 * One worker will adaptively be available for each client.
 * The remainder are taken from the GDKnr_threads argument and
 * typically is equal to the number of cores
 * The workers are assembled in a local table to enable debugging.
 */
static int
DFLOWinitialize(void)
{
	int i, limit;
	int created = 0;

	MT_lock_set(&mal_contextLock, "DFLOWinitialize");
	if (todo) {
		/* somebody else beat us to it */
		MT_lock_unset(&mal_contextLock, "DFLOWinitialize");
		return 0;
	}
	todo = q_create(2048, "todo");
	if (todo == NULL) {
		MT_lock_unset(&mal_contextLock, "DFLOWinitialize");
		return -1;
	}
	for (i = 0; i < THREADS; i++)
		MT_sema_init(&workers[i].s, 0, "DFLOWinitialize");
	limit = GDKnr_threads ? GDKnr_threads - 1 : 0;
#ifdef NEED_MT_LOCK_INIT
	ATOMIC_INIT(exitingLock, "exitingLock");
	MT_lock_init(&dataflowLock, "dataflowLock");
#endif
	MT_lock_set(&dataflowLock, "DFLOWinitialize");
	for (i = 0; i < limit; i++) {
		workers[i].flag = RUNNING;
		workers[i].cntxt = NULL;
		if (MT_create_thread(&workers[i].id, DFLOWworker, (void *) &workers[i], MT_THR_JOINABLE) < 0)
			workers[i].flag = IDLE;
		else
			created++;
	}
	MT_lock_unset(&dataflowLock, "DFLOWinitialize");
	if (created == 0) {
		/* no threads created */
		q_destroy(todo);
		todo = NULL;
		MT_lock_unset(&mal_contextLock, "DFLOWinitialize");
		return -1;
	}
	MT_lock_unset(&mal_contextLock, "DFLOWinitialize");
	return 0;
}
Esempio n. 29
0
static void send_status(SIG_ENTITY *sig,SOCKET *sock,unsigned long call_ref,
  unsigned char cause,...)
{
    va_list ap;
    Q_DSC dsc;
    int size;

    q_create(&dsc,q_buffer,MAX_Q_MSG);
    q_assign(&dsc,QF_msg_type,ATM_MSG_STATUS);
    if (sock) {
	q_assign(&dsc,QF_call_ref,sock->call_ref);
	q_assign(&dsc,QF_call_state,(int) sock->call_state);
	if (sock->ep_ref >= 0) {
	    q_assign(&dsc,QF_ep_ref,sock->ep_ref);
	    q_assign(&dsc,QF_ep_state,eps_map[sock->call_state]);
	}
    }
    else {
	q_assign(&dsc,QF_call_ref,call_ref);
	q_assign(&dsc,QF_call_state,0); /* U0 - Null / REST 0 - Null */
    }
    q_assign(&dsc,QF_cause,cause);
    va_start(ap,cause);
    switch (cause) {
	case ATM_CV_UNKNOWN_MSG_TYPE:
	case ATM_CV_INCOMP_MSG:
	    q_assign(&dsc,QF_bad_msg_type,va_arg(ap,unsigned int));
	    break;
	case ATM_CV_MAND_IE_MISSING:
	case ATM_CV_INVALID_IE:
	    {
		unsigned char ie;

		ie = va_arg(ap,unsigned int);
		q_write(&dsc,QF_ie_id6,&ie,1);
		break;
	    }
	default:
	    ;
    }
    va_end(ap);
    if ((size = q_close(&dsc)) >= 0) to_signaling(sig,q_buffer,size);
}
Esempio n. 30
0
void Connect(void)
{
	// initialize variables
	TX_TICKET hConnectionStateChangedTicket = TX_INVALID_TICKET;
	TX_TICKET hEventHandlerTicket = TX_INVALID_TICKET;
	BOOL success;

	// create data stack
	q_create();

	// initialize and enable the context that is our link to the EyeX Engine.
	success = txInitializeEyeX(TX_EYEXCOMPONENTOVERRIDEFLAG_NONE, NULL, NULL, NULL, NULL) == TX_RESULT_OK;
	success &= txCreateContext(&hContext, TX_FALSE) == TX_RESULT_OK;
	success &= InitializeGlobalInteractorSnapshot(hContext);
	success &= txRegisterConnectionStateChangedHandler(hContext, &hConnectionStateChangedTicket, OnEngineConnectionStateChanged, NULL) == TX_RESULT_OK;
	success &= txRegisterEventHandler(hContext, &hEventHandlerTicket, HandleEvent, NULL) == TX_RESULT_OK;
	success &= txEnableConnection(hContext) == TX_RESULT_OK;
	
	// short pause to try and ensure that the callbacks are fired and the printf messages sent to Matlab before this function terminates
	Sleep(100);
}