Пример #1
0
void client_init(int taskid, int num_tasks)
{
    ASSERT(max_ep > 0);

    /* Create data structure to track all clients */
    MALLOC_ALIGN(client_table, sizeof(client_t) * max_ep, CACHELINE_SIZE);

    PMPI_Barrier(MPI_COMM_WORLD);

    /* Initialize command queues */
    cqueue_init(max_ep);

    /* Spawn server */
    server_create();

    /* Create client data-structure */
    for (int clientid = 0; clientid < max_ep; clientid++)
    {
        client_t* myclient = &client_table[clientid];
        myclient->clientid = clientid;
        myclient->taskid = taskid;
        /* Attach client to a command queue */
        myclient->cqueue = cqueue_attach(clientid);
        memory_set_cqueue(clientid, myclient->cqueue);
    }
    PMPI_Barrier(MPI_COMM_WORLD);

    if (use_mem_hooks) set_mem_hooks = 1;
}
Пример #2
0
Файл: test.c Проект: Zolok/refos
static int
test_cqueue(void)
{
    test_start("cqueue");
    cqueue_t q;
    cqueue_init(&q, 62);
    for (int k = 0; k < 100; k++) {
        for (int i = 0; i < 60; i++) {
            cqueue_push(&q, (cqueue_item_t) i);
        }
        for (int i = 0; i < 60; i++) {
            int item = (int) cqueue_pop(&q);
            test_assert(item == i);
        }
    }
    cqueue_free(&q);
    return test_success();
}
Пример #3
0
EC_BOOL cconnp_init(CCONNP *cconnp)
{
    if(NULL_PTR != cconnp)
    {
        CCONNP_SRV_IPADDR(cconnp)              = CMPI_ERROR_IPADDR;
        CCONNP_SRV_PORT(cconnp)                = CMPI_ERROR_SRVPORT;

        CCONNP_SRV_TCID(cconnp)                = CMPI_ERROR_TCID;
        CCONNP_SRV_COMM(cconnp)                = CMPI_ERROR_COMM;
        CCONNP_SRV_SIZE(cconnp)                = 0;

        CCONNP_TIMEOUT_MSEC(cconnp)            = 0;
        CCONNP_EXPIRED_MSEC(cconnp)            = 0;

        CCONNP_DATA_NEW_HANDLER(cconnp)        = NULL_PTR;
        CCONNP_DATA_FREE_HANDLER(cconnp)       = NULL_PTR;

        CCONNP_CONNECT_HANDLER(cconnp)         = NULL_PTR;
        CCONNP_SEND_HANDLER(cconnp)            = NULL_PTR;
        CCONNP_RECV_HANDLER(cconnp)            = NULL_PTR;
        CCONNP_CLOSE_HANDLER(cconnp)           = NULL_PTR;
        CCONNP_TIMEOUT_HANDLER(cconnp)         = NULL_PTR;

        CCONNP_SHAKEHAND_SEND_HANDLER(cconnp)  = NULL_PTR;
        CCONNP_SHAKEHAND_RECV_HANDLER(cconnp)  = NULL_PTR;
     
        CCONNP_BEFORE_SEND_HANDLER(cconnp)     = NULL_PTR;
        CCONNP_AFTER_SEND_HANDLER(cconnp)      = NULL_PTR;
     
        CCONNP_HEALTH_CHECKER_HANDLER(cconnp)  = NULL_PTR;

        clist_init(CCONNP_SEND_DATA_LIST(cconnp), MM_IGNORE, LOC_CCONNP_0002);

        cqueue_init(CCONNP_IDLE_CONN_QUEUE(cconnp), MM_CSOCKET_CNODE, LOC_CCONNP_0003);
    }

    return (EC_TRUE);
}
Пример #4
0
int main()
{
	int ch=1,dt;
	uint16_t i,sz;
	uint8_t data;

	#ifndef WIN32
	system("clear");
	#else
	system("cls");
	#endif
	if(cqueue_init(&cqn,dir,MAX)!=STATUS_SUCCESS)
	{
		printf("\n Error in Initializing ");
		exit(1);
	}
	while(ch!= 0)
	{
		printf("\n ");
		printf("\n 1. Circular Queue INSERT ");
		printf("\n 2. Circular Queue DELETE ");
		printf("\n 3. Circular Queue DISPLAY");
		printf("\n 4. Circular Queue Move");
		printf("\n 5. Circular Queue Move Into Queue(Excess)");
		printf("\n 6. Circular Queue Move Into Queue(Correct)");
		printf("\n 0. EXIT\n");

		printf("\nEnter your choice : ");
		scanf("%d",&ch);
		ch = 0; // Intentional
		switch(ch)
		{
			case 1:
				 printf("\n Enter the Integer Data to be inserted: ");
				 scanf("%d",&dt);
				 data = dt & 0x0FF;
				 dt = cqueue_push(&cqn,data);
				 if(dt!=STATUS_SUCCESS)
				 {
					 printf("\n Could not Insert data Due to %d status",
					 dt);
				 }
				 break;
			case 2:
				if(cqueue_empty(&cqn)==STATUS_SUCCESS)
					printf("\nqueue is empty\n");
				else
				{
					if(cqueue_pop(&cqn,&data)==STATUS_SUCCESS)
						printf("\n the deleted element is: 0x%02X",data);
					else
						printf("\n Error in Receiving Data \n");
				}
				break;
			case 3:
				if(cqueue_empty(&cqn)==STATUS_SUCCESS)
					printf("\nqueue is empty");
				else
				{
				  for(i=0;i<cqn.max;i++)prn[i]=0;
				  if(cqueue_copydata(&cqn,prn,&sz,cqn.max)==STATUS_SUCCESS)
				  {
					  for(i=0;i<sz;i++)
					  printf("\n (%2d)= 0x%02X",i+1,prn[i]);
				  }
				}
				break;
			case 4:
				if(cqueue_empty(&cqn)==STATUS_SUCCESS)
					printf("\nqueue is empty");
				else
				{
				  for(i=0;i<cqn.max;i++)prn[i]=0;
				  if(cqueue_movedata(&cqn,prn,&sz,cqn.max)==STATUS_SUCCESS)
				  {
					  printf("\n Size Copied: %d",sz);
					  for(i=0;i<sz;i++)
					  printf("\n (%2d)= 0x%02X",i+1,prn[i]);
				  }
				}
				break;
			case 5:
				printf("\n The following Data would be copied into Queue:");
				printf("\n uint8_t temp[5]={0x11,0x22,0x33,0x44,0x55};");
				printf("\nStatus would be 3 as only 4 bytes can be inserted");
				dt = cqueue_movetoqueue(&cqn,temp,&sz,cqn.max);
				printf("\n Data Copied: %d",sz);
				printf("\n Status Returned: %d",dt);
				break;
			case 6:
				printf("\n The following Data would be copied into Queue:");
				printf("\n uint8_t temp[5]={0x11,0x22,0x33,0x44,0x55};");
				printf("\nStatus would be 0 as only 4 bytes to insert");
				dt = cqueue_movetoqueue(&cqn,temp,&sz,cqn.max-1);
				printf("\n Data Copied: %d",sz);
				printf("\n Status Returned: %d",dt);
				break;
			}
		}
	getchar();
	return 0;
}
Пример #5
0
int main (int argc, char *argv[])
{
    int i, j, rc;
    pthread_attr_t attr;

    assert(argc == 3);
    student_num = atoi(argv[1]);
    sheet_num = atoi(argv[2]);
    assert(student_num > 0);
    assert(sheet_num > 0);

    srand(time(NULL));

    cqueue_init(&cqueue, sizeof(sheet_array), sheet_num);

    // Initialize and set thread detached attribute
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    pthread_rwlock_init(&rwlock, NULL);

    // prepare sheet_array
    sheet_array = malloc(sizeof(sheet_array[0])*sheet_num);
    assert(sheet_array);
    for(i = 0; i < sheet_num; i++)
    {
        sheet_array[i].array = malloc(sizeof(sheet_array[0].array[0])*student_num);
        assert(sheet_array[i].array);
        memset(sheet_array[i].array, 0, sizeof(sheet_array[0].array[0])*student_num);
        pthread_mutex_init(&(sheet_array[i].mutex), NULL);
        signupsheet_t* psheet = sheet_array + i;
        cqueue_push_back(&cqueue, &psheet);
    }

    // prepare final_sheet
    final_sheet.array = malloc(sizeof(int)*student_num);
    memset(final_sheet.array, 0, sizeof(final_sheet.array[0])*student_num);
    pthread_mutex_init(&(final_sheet.mutex), NULL);

    // prepare the golden data for check()
    golden = malloc(sizeof(int)*student_num);
    assert(golden);

    pthread_barrier_init(&bar, NULL, student_num);

    // initial semaphore attribute
    sem_init(&sem, 0, sheet_num);

    // initial thread creation
    thread_array = (pthread_t*) malloc(sizeof(pthread_t) * student_num);
    assert(thread_array);
    for(i = 0; i < student_num; i++)
    {
        int student_id = 0;
        while(student_id == 0)
            student_id = rand();
        assert(student_id != 0);

        int rc = pthread_create(thread_array+i, &attr, student, (void *)student_id);
        assert(rc == 0);
        golden[i] = student_id;
    }

    for(i = 0; i < student_num; i++)
        pthread_join(thread_array[i], NULL);

    // sort all student autograph
    int signup_count = 0;
    for(i = 0; i < sheet_num; i++)
        for(j = 0; j < student_num; j++)
            if(sheet_array[i].array[j])
                final_sheet.array[signup_count++] = sheet_array[i].array[j];

    printf("signup_count:%d\n", signup_count);
    assert(signup_count == student_num);

    Odd_even_sort(final_sheet.array, student_num);
    //Print_list(final_sheet.array, student_num,
    //"Student autograph Booki (Sorted)");

    check_result();

    return 0;
}