Example #1
0
File: lab2.c Project: jdebr/os460
int main(){
	// Initialize random num generator
	srand((unsigned) time(&t));
	// Make an initial buffer of 3 nodes
	initialize_buffer();
	print_buffer();
	
	// Start threads 
	pthread_t thread1, thread2, thread3, thread4;
	int tid1 = pthread_create(&thread1,NULL,(void *)produce1, (void *)0);
	if (tid1 < 0 ) printf("1st thread_create failure.\n");
	int tid2 = pthread_create(&thread2,NULL,(void *)produce2, (void *)0);
	if (tid2 < 0 ) printf("2nd thread_create failure.\n");
	int tid3 = pthread_create(&thread3,NULL,(void *)consume1, (void *)0);
	if (tid3 < 0 ) printf("3rd thread_create failure.\n");
	int tid4 = pthread_create(&thread4,NULL,(void *)consume2, (void *)0);
	if (tid4 < 0 ) printf("4th thread_create failure.\n");
	
	// Wait for threads to finish
	pthread_join(thread1,NULL);
	pthread_join(thread2,NULL);
	pthread_join(thread3,NULL);
	pthread_join(thread4,NULL);
	
	// Release mutex variable
	pthread_mutex_destroy(&mymutex);
	
	// Exit
	return 0;
	
}
Example #2
0
int load_data(char *filename, char *entidad){
  FILE * entity_file;
  FILE * block_file;
  struct record_t *record;
  struct file_header * file_header;
  struct block_t * current_block;
  char * buffer;
  int res;

  /* Entity file */
  entity_file = open_file_to_parse(filename);
  if (!entity_file){
    return BAD_NAME_FILE;
  }
  /* Block and header file */
  block_file = open_block_file(entidad, 1);
  if(!block_file){
    return BAD_NAME_FILE;
  }else{
    file_header = (struct file_header*) malloc(sizeof(struct file_header));
    if(!file_header)
      return ALLOCATE_FAIL;
    else{
      initialize_file_header(file_header);
      write_header(block_file, file_header);
    }
  }

  /* Allocate buffer and record */
  buffer = (char*) malloc (RECORD_MAX_SIZE);
  record = (struct record_t*) malloc(sizeof(struct record_t));
  current_block = (struct block_t *) malloc(sizeof(struct block_t));

  if(!buffer || !record || !current_block)
    return ALLOCATE_FAIL;

  initialize_buffer(buffer);
  initialize_block(current_block, 1);
  initialize_record(record);

  /* Read text file */
  while(fgets(buffer, RECORD_MAX_SIZE, entity_file) != NULL){
    res = parse_line(buffer, record, RECORD_MAX_SIZE);
    if(res == RES_OK){
      res = find_and_write_block(block_file, file_header, record, current_block);
      initialize_record(record);
      free(record->content);
    };
  };
  write_to_file(block_file, file_header, current_block);
  print_header(file_header);

  free(record);
  free(buffer);
  free(file_header);
  free(current_block);
  close_entity_file(entity_file);
  close_block_file(block_file);
  return res;
}
Example #3
0
static void
blockdev_write_read(uint32_t data_length, int pattern, uint64_t offset,
		    int expected_rc)
{
	struct io_target *target;
	char	*tx_buf = NULL;
	char	*rx_buf = NULL;
	int	rc;

	target = g_io_targets;
	while (target != NULL) {
		if (data_length < target->bdev->blocklen) {
			target = target->next;
			continue;
		}

		initialize_buffer(&tx_buf, pattern, data_length);
		initialize_buffer(&rx_buf, 0, data_length);

		blockdev_write(target, tx_buf, offset, data_length);

		if (expected_rc == 0) {
			CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_SUCCESS);
		} else {
			CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_FAILED);
		}

		blockdev_read(target, rx_buf, offset, data_length);

		if (expected_rc == 0) {
			CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_SUCCESS);
		} else {
			CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_FAILED);
		}

		if (g_completion_status == SPDK_BDEV_IO_STATUS_SUCCESS) {
			rc = blockdev_write_read_data_match(rx_buf, tx_buf, data_length);
			/* Assert the write by comparing it with values read
			 * from each blockdev */
			CU_ASSERT_EQUAL(rc, 0);
		}

		target = target->next;
	}
}
/**
 * Initializes the internal data buffer if it is not already initialized for this thread.
 */
void log_client::check_buffer()
{
    // if the buffer has not been initialized for this thread...
    if(m_buffer.get() == nullptr)
    {
        // ...  then initialize it.
        initialize_buffer();
    }
}
Example #5
0
static void
blockdev_write_read_offset_plus_nbytes_gt_bdev_size(void)
{
	struct io_target *target;
	struct spdk_bdev *bdev;
	char	*tx_buf = NULL;
	char	*rx_buf = NULL;
	int	data_length;
	uint64_t offset;
	int pattern;

	/* Tests the overflow condition of the blockdevs. */
	data_length = 4096;
	CU_ASSERT_TRUE(data_length < BUFFER_SIZE);
	pattern = 0xA3;

	target = g_io_targets;
	while (target != NULL) {
		bdev = target->bdev;

		/* The start offset has been set to a valid value
		 * but offset + nbytes is greater than the Total size
		 * of the blockdev. The test should fail. */
		offset = ((bdev->blockcnt * bdev->blocklen) - 1024);

		initialize_buffer(&tx_buf, pattern, data_length);
		initialize_buffer(&rx_buf, 0, data_length);

		blockdev_write(target, tx_buf, offset, data_length);
		CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_FAILED);

		blockdev_read(target, rx_buf, offset, data_length);
		CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_FAILED);

		target = target->next;
	}
}
Example #6
0
static void
blockdev_write_read_offset_plus_nbytes_equals_bdev_size(void)
{
	struct io_target *target;
	struct spdk_bdev *bdev;
	char	*tx_buf = NULL;
	char	*rx_buf = NULL;
	uint64_t offset;
	int rc;

	target = g_io_targets;
	while (target != NULL) {
		bdev = target->bdev;

		/* The start offset has been set to a marginal value
		 * such that offset + nbytes == Total size of
		 * blockdev. */
		offset = ((bdev->blockcnt - 1) * bdev->blocklen);

		initialize_buffer(&tx_buf, 0xA3, bdev->blocklen);
		initialize_buffer(&rx_buf, 0, bdev->blocklen);

		blockdev_write(target, tx_buf, offset, bdev->blocklen);
		CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_SUCCESS);

		blockdev_read(target, rx_buf, offset, bdev->blocklen);
		CU_ASSERT_EQUAL(g_completion_status, SPDK_BDEV_IO_STATUS_SUCCESS);

		rc = blockdev_write_read_data_match(rx_buf, tx_buf, bdev->blocklen);
		/* Assert the write by comparing it with values read
		 * from each blockdev */
		CU_ASSERT_EQUAL(rc, 0);

		target = target->next;
	}
}
/**
 * processes a log file (lf) stream manipulator.
 * @param _lf Path identifying file to write XML to.
 * @returns always returns *this
 **/
log_client& log_client::operator<<(lf _lf)
{
    // make sure buffers initialized
    check_buffer();

    // decide how to handle modifier.
    switch(_lf)
    {
        // end entry and flush (lf::end)
        case (lf::end):
        {
            // add the entry to the log schedule and create next entry.
            auto converted_buffer = std::dynamic_pointer_cast<log_entry>(*m_buffer);

            // ensure that the entry type is set...
            if(converted_buffer->entry_type() == category::unspecified)
            {
                // ... else use the fallback type
                converted_buffer->entry_type(default_entry_type());
            }

            // ensure that the entry namespace is set...
            if(converted_buffer->log_namespace() == "")
            {
                // ... else ue the fallback namespace
                converted_buffer->log_namespace(default_namespace());
            }

            // schedule the entry for serialization and re-initialize buffer
            m_output_interface->add_entry(converted_buffer);
            initialize_buffer();

            break;
        }

        // unknown operator
        default:
        {
#ifdef _DEBUG
            // if we are debugging - notify developer that the flow is unrecognized and going unprocessed.
            std::cerr << translate("WARNING: unknown inglenook log flag encountered in stream (inglenook::logging::lf): ") << _lf << std::endl;
#endif
        }
    }

    return *this;
}
bool ScreenSpaceAmbientOcclusionManager::init() {
    //Initialize textures
    initialize_textures(normal_depth_texture);
    initialize_textures(ssao_texture);
    initialize_textures(blurred_ssao_texture_x);
    initialize_textures(blurred_ssao_texture_xy);

    //Initialize buffers
    bool res = true;

    res = initialize_buffer(render_buffer_object, frame_buffer_object, normal_depth_texture);
    if (!res) return false;

    //res = initialize_buffer(render_buffer_object_2, frame_buffer_object_2, ssao_texture);
    //if (!res) return false;

    initialized = true;
    return res;
}
Example #9
0
int main(int argc, char *argv[])
{
    int i,error;
    char word_end_chars[256],*pos;
    POINTER_ARRAY from,to;
    REPLACE *replace;
    MY_INIT(argv[0]);

    if (static_get_options(&argc,&argv))
        exit(1);
    if (get_replace_strings(&argc,&argv,&from,&to))
        exit(1);

    for (i=1,pos=word_end_chars ; i < 256 ; i++)
        if (my_isspace(&my_charset_latin1,i))
            *pos++= (char) i;
    *pos=0;
    if (!(replace=init_replace((char**) from.typelib.type_names,
                               (char**) to.typelib.type_names,
                               (uint) from.typelib.count,word_end_chars)))
        exit(1);
    free_pointer_array(&from);
    free_pointer_array(&to);
    if (initialize_buffer())
        return 1;

    error=0;
    if (argc == 0)
        error=convert_pipe(replace,stdin,stdout);
    else
    {
        while (argc--)
        {
            error=convert_file(replace,*(argv++));
        }
    }
    free_buffer();
    my_free(replace);
    my_end(verbose ? MY_CHECK_ERROR | MY_GIVE_INFO : MY_CHECK_ERROR);
    exit(error ? 2 : 0);
    return 0;					/* No compiler warning */
} /* main */
Example #10
0
int main(void)
{
    /* Begin by initializing the buffer.  This also has the desirable
     * side-effect of warming up the cache.  Always do this before you
     * begin any timing runs.  */
    initialize_buffer();

    /* Time calls to strcat of various lengths. */
    int i = 0, j = 0, k = 0;
    for (i = 0; i < 1; i++) {
        if (i == 0)  {
            timer= func_time;
            printf("regular timer\n");
        }
        else {
            timer= func_time_hw;
            printf("hardware timer\n");
        }

        for (j = 0; j < 3; j++) {
            if (j == 0) {
                concat = optStrcatWrapper;
                printf("optimized strcat\n");
            }
            else if (j == 1) {
                concat= naiveStrcatWrapper;
                printf("naive strcat\n");
            }
            else {
                concat= strcatWrapper;
                printf("glibc strcat\n");
            }


            //do_test(0, 1, 2048, 1, timer_main, concat_main);
            int iterations = 1;
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 1;
            long long miss[100];

            for (k = 0; k < 100; k++) {
                miss[k] = 0;
            }

            for (k = 0; k < iterations; k++) {

                miss[0] += do_cache_test(0, 1, 2048, 4, concat);
                miss[1] += do_cache_test(0, 1, 2048, 4,  concat);
                miss[2] += do_cache_test(0, 1, 2048, 19,  concat);
                miss[3] += do_cache_test(0, 1, 2048, 103,  concat);
                miss[4] += do_cache_test(0, 1, 2048, 1900,  concat);
                miss[5] += do_cache_test(1, 4, 2048, 1,  concat);
                miss[6] += do_cache_test(1, 4, 2048, 4,  concat);
                miss[7] += do_cache_test(1, 4, 2048, 19,  concat);
                miss[8] += do_cache_test(1, 4, 2048, 103,  concat);
                miss[9] += do_cache_test(1, 4, 2048, 1900,  concat);
                miss[10] += do_cache_test(4, 32, 2048, 1,  concat);
                miss[11] += do_cache_test(4, 32, 2048, 4,  concat);
                miss[12] += do_cache_test(4, 32, 2048, 19,  concat);
                miss[13] += do_cache_test(4, 32, 2048, 103,  concat);
                miss[14] += do_cache_test(4, 32, 2048, 1900,  concat);
            }

            for (k = 0; k < 15; k++) {
                printf("miss[%d] = %g\n", k, miss[k]/((double)iterations));
            }



            //do_test(0, 1, 2048, 1, timer_main, concat_main);
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 1;
            long double secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(0, 1, 2048, 4, timer_main, concat_main);
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 4;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(0, 1, 2048, 19, timer_main, concat_main);
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 19;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(0, 1, 2048, 103, timer_main, concat_main);
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 103;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(0, 1, 2048, 1900, timer_main, concat_main);
            dest_start = 0; dest_len = 1; src_start = 2048; src_len = 1900;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(1, 4, 2048, 1, timer_main, concat_main);
            dest_start = 1; dest_len = 4; src_start = 2048; src_len = 1;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(1, 4, 2048, 4, timer_main, concat_main);
            dest_start = 1; dest_len = 4; src_start = 2048; src_len = 4;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(1, 4, 2048, 19, timer_main, concat_main);
            dest_start = 1; dest_len = 4; src_start = 2048; src_len = 19;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(1, 4, 2048, 103, timer_main, concat_main);
            dest_start = 1; dest_len = 4; src_start = 2048; src_len = 103;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(1, 4, 2048, 1900, timer_main, concat_main);
            dest_start = 1; dest_len = 4; src_start = 2048; src_len = 1900;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(4, 32, 2048, 1, timer_main, concat_main);
            dest_start = 4; dest_len = 32; src_start = 2048; src_len = 1;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(4, 32, 2048, 4, timer_main, concat_main);
            dest_start = 4; dest_len = 32; src_start = 2048; src_len = 4;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(4, 32, 2048, 19, timer_main, concat_main);
            dest_start = 4; dest_len = 32; src_start = 2048; src_len = 19;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(4, 32, 2048, 103, timer_main, concat_main);
            dest_start = 4; dest_len = 32; src_start = 2048; src_len = 103;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);

            //do_test(4, 32, 2048, 1900, timer_main, concat_main);
            dest_start = 4; dest_len = 32; src_start = 2048; src_len = 1900;
            secs = timer(doTestWrapper, 0.005) - timer(add_dummy, 0.005);
            printf("number of seconds %Le\n", secs);


            /////////////////////////////////////////////////////////////////////
            printf("****************switching concat*******************\n");
        }
        printf("****************switching timer*******************\n");
    }

    return 0;
}
Example #11
0
int main(int argc, char *argv[]) {
    FILE *output;

    /* TODO fix this so that we can accept a log file */
    output = stdout;

    /* Prepare environment */
    initialize_buffer();
    initialize_card_arrs();

    fprintf(output, "Commencing testing of: %s\n\n", PROG_VER);

    fprintf(output, "%s\n\n", ". indicates success\nF indicates failure");

    /* Sanity checks */
    fprintf(output, "%s\n", "==== Sanity Checks ==========================");
    sanity_checks(output);
    fprintf(output, "%s", "\n");

    /* Log file detection */
    fprintf(output, "%s\n", "==== Log File Tests =========================");
    run_test(output, SELF_LOG);
    fprintf(output, "%s", "\n\n");

    /* Image file detection */
    fprintf(output, "%s\n", "==== Image File Tests =======================");
    run_test(output, IMAGE);
    fprintf(output, "%s", "\n\n");

    /* Binary file detection */
    fprintf(output, "%s\n", "==== Binary File Tests ======================");
    run_test(output, BINARY);
    fprintf(output, "%s", "\n\n");

    /* Image file detection */
    fprintf(output, "%s\n", "==== Default Separator Tests ================");
    run_test(output, SKIPCHARS);
    fprintf(output, "%s", "\n\n");

    /* Compressed files */
    fprintf(output, "%s\n", "==== Compressed files =======================");
    run_test(output, ZIP);
    fprintf(output, "%s", "\n\n");

    /* PDF files */
    fprintf(output, "%s\n", "==== PDF files ==============================");
    run_test(output, PDF);
    fprintf(output, "%s", "\n\n");

    /* .xlsx files */
    fprintf(output, "%s\n", "==== .xlsx files ============================");
    run_test(output, MS_EXCELX);
    fprintf(output, "%s", "\n\n");

    /* .docx files */
    fprintf(output, "%s\n", "==== .docx files ============================");
    run_test(output, MS_WORDX);
    fprintf(output, "%s", "\n\n");

    /* ODS files */
    fprintf(output, "%s\n", "==== ODS files ==============================");
    run_test(output, ODS);
    fprintf(output, "%s", "\n\n");

    /* ODT files */
    fprintf(output, "%s\n", "==== ODT files ==============================");
    run_test(output, ODT);
    return 0;
}
Example #12
0
int ccsrch(char *filename)
{
  FILE  *in = NULL;
  int   infd = 0;
  int   cnt = 0;
  long  byte_offset=1;
  int   k = 0;
  int   counter = 0;
  int   total = 0;
  int   check = 0;
  int   limit_exceeded = 0;
  
#ifdef DEBUG
  printf("Processing file %s\n",filename);
#endif

  memset(&lastfilename,'\0',MAXPATH);
  ccsrch_index=0;
  errno = 0;
  in = fopen(filename, "rb");
  if (in == NULL)
  {
    if (errno==13)
      fprintf(stderr, "ccsrch: Unable to open file %s for reading; Permission Denied\n", filename);
    else
      fprintf(stderr, "ccsrch: Unable to open file %s for reading; errno=%d\n", filename, errno);
    return (-1);
  }
  infd = fileno(in);
  currfilename = filename;
  byte_offset=1;

  file_count++;

  initialize_buffer();

  while (1 && limit_exceeded == 0)
  {
    memset(&ccsrch_buf, '\0', BSIZE);
    cnt = read(infd, &ccsrch_buf, BSIZE - 1);
    if (cnt <= 0)
      break;
    	
    ccsrch_index = 0;

    while (ccsrch_index < cnt && limit_exceeded == 0)
    {
      //check to see if our data is 0...9 (based on ACSII value)
      if ((ccsrch_buf[ccsrch_index] >= 48) && (ccsrch_buf[ccsrch_index] <= 57))
      {
        check = 1;
        cardbuf[counter] = ((int)ccsrch_buf[ccsrch_index])-48;
        counter++;
      } 
      else if ((ccsrch_buf[ccsrch_index] == 0) || (ccsrch_buf[ccsrch_index] == 10) || 
      	(ccsrch_buf[ccsrch_index] == 13) || (ccsrch_buf[ccsrch_index] == 45))
      {
        /*
         * we consider dashes, nulls, new lines, and carriage
         * returns to be noise, so ingore those
         */
        check = 0;
      }
      else
      {
        check = 0;
        initialize_buffer();
        counter=0;
      }

      if (((counter > 12) && (counter < CARDSIZE)) && (check)) 
      {
        switch (counter)
        {
        case 16:
          luhn_check(16,byte_offset-16);
          break;
        case 15:
          luhn_check(15,byte_offset-15);
          break;
        case 14:
          luhn_check(14,byte_offset-14);
          break;
        case 13:
          luhn_check(13,byte_offset-13);
          break;
        }
      } 
      else if ((counter == CARDSIZE) && (check)) 
      {
        for (k = 0; k < counter - 1; k++)
        {
          cardbuf[k] = cardbuf[k + 1];
        }
        cardbuf[k] = (-1);
        luhn_check(13,byte_offset-13);
        luhn_check(14,byte_offset-14);
        luhn_check(15,byte_offset-15);
        luhn_check(16,byte_offset-16);
        counter--;
      }
      byte_offset++;
      ccsrch_index++;
      
      if (newstatus == 1)
      {
      	update_status(currfilename, byte_offset);
      }
      
      //check to see if we've hit the limit for the current file
      if (limit_file_results > 0 && file_hit_count >= limit_file_results)
    	  limit_exceeded = 1;
    }
  }

  fclose(in);

  return (total);
}