void* accepter_thread(void* args){
	printf("\n%s", "===================ACCEPTER THREAD START==================");
	printf("\n%s", "lancio il thread accepter(in accepter)");
	queue_and_list_t* p = (queue_and_list_t*)args;
	pthread_t get_message_queue_thread;
	msg_t* message_read;
	reader_t* new_reader;

	while(1){
		pthread_create(&get_message_queue_thread, NULL, accepter_get_bloccante,(void*)p->requests_queue);
		pthread_join(get_message_queue_thread,(void*)&message_read);
		if(message_read->content)
			printf("\n%s : messaggio letto dall buffer delle richieste(in accepter)", (char*)message_read->content);
		if(message_read == POISON_PILL){
			printf("\n%s", "ricevuta la poison pill(in accepter) TERMINO");
			pthread_exit(2);
		}
		else{
			new_reader = init_reader(message_read->content, SIZE_BUFFER_READER);
			pthread_mutex_lock(&(p->lista_reader_contes->blocco_list_mutex));
				printf("\n%s : aggiungo il reader alla lista (in accepter)\n", new_reader->name);
				addElement(p->lista_reader_contes->reader_list, (void*)new_reader);
			pthread_mutex_unlock(&(p->lista_reader_contes->blocco_list_mutex));

			parametri_reader* parametri = (parametri_reader*)malloc(sizeof(parametri_reader));
			parametri->reader = new_reader;
			parametri->lista_reader_struct = p->lista_reader_contes;
	
			pthread_create(new_reader->tid_reader, NULL, reader_thread,(void*)parametri);
			
			msg_destroy(message_read);
		}
	}

}
/*=============================================================================================*/
int prova_setup(void){
	init_arguments();
	new_reader = init_reader("reader0\0", 10);
	addElement(parm1->reader_list, (void*)new_reader);

	parametri_reader* parametri = (parametri_reader*)malloc(sizeof(parametri_reader));
	parametri->reader = new_reader;
	parametri->lista_reader_struct = parm->lista_reader_contes;
	pthread_create(new_reader->tid_reader, NULL, reader_thread,(void*)parametri);
	
	buffer_provider = buffer_init(10);
	numero_messaggi = 6;
	init_provider_agruments();

	pthread_t provider_thread;
	pthread_create(&provider_thread, NULL,create_messages, (void*)provider_struct);
	

	dispatcher_param = (parametri_dispatcher*)malloc(sizeof(parametri_dispatcher));
	dispatcher_param->provider_struct =  provider_struct;
	dispatcher_param->requests_list_struct = parm;

	pthread_t dispatcher;
	pthread_create(&dispatcher, NULL,dispatcher_thread, (void*)dispatcher_param);
	
	pthread_join(dispatcher,(void*)&codRitThread_dispatcher);
	pthread_join(provider_thread,NULL);
	pthread_join(*(new_reader->tid_reader),&cod_rit_red_thd);
	return 0;
}
Ejemplo n.º 3
0
int main (int argc, const char * argv[]) {
	
	/* initialize the file reader */
	init_reader("../../../resources/sample.lua");
	
	initialize_writer("../../../resources/sample.asm");
	
	/* initialize transducer automata transitions */
	initialize_transitions();
	
	/* initialize semantic */
	initialize_semantic();
	
	/* initialize semantic actions */
	init_semantic_actions();
	
	// start APE machines
	init_ape_machines();
	
	/* call sintatic analyser*/
	run_sintatic();
	
	close_writer();
	return 0;
}
Ejemplo n.º 4
0
FastqReader::FastqReader(const std::string& filename) :
  m_input_stream {}
{
  if (!filename.empty()) {
    init_reader(filename);
  }
}
Ejemplo n.º 5
0
FastqReader::FastqReader(const std::vector<std::string>& filenames) :
  m_input_stream {}
{
  if (filenames.size() > 1)
    throw SingleInputException{"filenames", filenames.size()};
  if (!filenames.empty()) {
    init_reader(filenames.front());
  }
}
Ejemplo n.º 6
0
      int LdbLogsReader::start_new_reader(uint64_t min_number)
      {
        int ret = TAIR_RETURN_SUCCESS;

        clear_reader(min_number);

        leveldb::DBImpl* db = dynamic_cast<leveldb::DBImpl*>(db_);
        leveldb::Env* db_env = db->GetEnv();
        const std::string& db_log_dir = db->DBLogDir();
        std::vector<std::string> filenames;
        leveldb::Status s = db_env->GetChildren(db_log_dir, &filenames);

        uint64_t number = 0;
        leveldb::FileType type;
        std::vector<uint64_t> logs;
        for (size_t i = 0; i < filenames.size(); i++)
        {
          if (leveldb::ParseFileName(filenames[i], &number, &type) && type == leveldb::kLogFile)
          {
            logs.push_back(number);
          }
        }

        uint64_t new_logfile_number = 0;
        uint64_t db_logfile_number = db->LogFileNumber();

        if (!logs.empty())
        {
          std::sort(logs.begin(), logs.end());
          // maybe binary-search..
          for (size_t i = 0; i < logs.size(); ++i)
          {
            if (logs[i] > min_number && logs[i] <= db_logfile_number)
            {
              new_logfile_number = logs[i];
              break;
            }
          }
        }

        if (0 == new_logfile_number)
        {
          log_info("no ldb log for reader");
        }
        else
        {
          ret = init_reader(new_logfile_number);
        }

        return ret;
      }
Ejemplo n.º 7
0
int main ( int argc, char** argv )
{
    SchObj robj,ret;
    int    opt;
    char * fname = 0;
    char * expr = 0;

#ifdef USE_BOEHM_GC
    GC_INIT();
#endif
    ensure_init_symtable();
    init_reader();
    init_port();

    flag_use_profiler = 0;

    while ( (opt = getopt(argc,argv,"pf:e:")) != -1 ) {
        switch ( opt ) {
        case 'p': {
            flag_use_profiler = 1;
        } break;
        case 'f': {
            fname = SCH_MALLOC(strlen(optarg) + 1);
            strcpy(fname,optarg);
        } break;
        case 'e':{
            expr = SCH_MALLOC(strlen(optarg) + 1);
            strcpy(expr,optarg);
        }break;
        };
    }

    if ( expr ) {
        robj = sch_read_string(expr);
        ret  = vm_compile(robj);
        SCH_WRITE(ret);
        SCH_DISPLAY(SCH_CHAR('\n'));
    } else if ( fname ) {
        sch_load(SCH_STRING_OBJ(SCH_STRING(fname)));
    } else {
        while ( 1 ) {
            robj = sch_read(NULL);
            ret  = vm_compile(robj);
            SCH_WRITE(ret);
        }
    }

    return 0;

}
Ejemplo n.º 8
0
static int populate_pcsc_readers(struct pcsc_private *priv)
{
	int i;
	void *reader_mmio_base = priv->mmio_base + PCSC_REG_MAX;
	priv->readers = kmalloc(sizeof(struct pcsc_reader) * priv->num_readers, GFP_KERNEL);
	if (priv->readers == NULL)
		return -ENOMEM;

	for (i = 0; i < priv->num_readers; i++)
	{
		void *mmio_base = reader_mmio_base + i * PCSC_REG_READER_MAX;
		init_reader(priv->readers + i, i, mmio_base);
	}

	return 0;
}
Ejemplo n.º 9
0
int main(int argc, char **argv)
{
	get_args(argc, argv);
	get_files_name();
	
	do_tests();

	FILE *output = fopen(global_args.output_name, "w");
	if (output == NULL)
		die(NULL);

	struct stat input_stat;
	stat(global_args.input_name, &input_stat);
	size_t st_size = input_stat.st_size;

	if (global_args.isdecompress) {
		reader_t *reader;
		init_reader(&reader);
		inflate(reader);
		delete_reader(&reader);
	} else {
		int rc1, rc2;
		pthread_t thread_static, thread_dynamic;

		size_t last_size, size = 0;
		size_t size_static, size_dynamic;

		io *io_static, *io_dynamic, *io_nocom;
		init_io(&io_static);
		init_io(&io_dynamic);
		init_io(&io_nocom);
		io_nocom->output_file = output;

		int k = 1;
		while (size < st_size) {
			printf("k = %d\n", k++);
			if (st_size - size >= BLOCK_SIZE) {
				last_size = BLOCK_SIZE;
			} else {
				last_size = st_size - size;
				io_static->isfinal = true;
				io_dynamic->isfinal = true;
				io_nocom->isfinal = true;
			}

			io_static->offset = size;
			io_static->block_size = last_size;
			io_dynamic->offset = size;
			io_dynamic->block_size = last_size;
			io_nocom->offset = size;
			io_nocom->block_size = last_size;

			rc1 = pthread_create(&thread_static, NULL, 
								 &static_deflate, io_static);
			rc2 = pthread_create(&thread_dynamic, NULL, 
								 &dynamic_deflate, io_dynamic);

			if (rc1 || rc2)
				die("thread creation failed");
			pthread_join(thread_static, NULL);
			pthread_join(thread_dynamic, NULL);
			size_static = io_static->result;
			size_dynamic = io_dynamic->result;

			printf("ss = %d, sd = %d, sn = %d\n", size_static, size_dynamic, last_size);

			if (size_dynamic <= size_static && 
				size_dynamic < last_size) {
				write_to_output(io_dynamic, output);
				copy_last_byte(io_static, io_dynamic);
				copy_last_byte(io_nocom, io_dynamic);
				size += io_dynamic->block_size;
				printf("block_size = %d, size = %d\n", io_dynamic->block_size, size);
			} else if (size_static <= size_dynamic && 
					   size_static < last_size) {
				write_to_output(io_static, output);
				copy_last_byte(io_dynamic, io_static);
				copy_last_byte(io_nocom, io_static);
				size += io_static->block_size;
				printf("block_size = %d, size = %d\n", io_static->block_size, size);
			} else {
				nocompress_deflate(io_nocom);
				copy_last_byte(io_static, io_nocom);
				copy_last_byte(io_dynamic, io_nocom);
				size += io_nocom->block_size;
				printf("block_size = %d, size = %d\n", io_nocom->block_size, size);
			}
		}

		delete_io(&io_static);
		delete_io(&io_dynamic);
		delete_io(&io_nocom);
	}

	free(global_args.output_name);
	fclose(output);
	exit(0);
}
Ejemplo n.º 10
0
int
main(int argc, char *argv[])
{
  fd_set rfds;                  /* the structure for the select call */
  int code;                    /* return code from system calls */
  char out_buff[MAXLINE];       /* from child and stdin */
  int out_flag[MAXLINE] ; /* initialize the output flags */
  char *program;          /* a string to hold the child program invocation */
  char **pargs = 0;             /* holds parts of the command line */
  int not_command = 1;          /* a flag while parsing the command line */



  /* try to get a pseudoterminal to play with */
  if (ptyopen(&contNum, &serverNum, controllerPath, serverPath) == -1) {
    perror("ptyopen failed");
    exit(-1);
  }

  /* call the routine that handles signals */
  catch_signals();

  /* parse the command line arguments - as with the aixterm  the command
     argument -e should be last on the line. */

  while(*++argv && not_command) {
    if(!strcmp(*argv, "-f"))
      load_wct_file(*++argv);
    else if(!strcmp(*argv, "-e")) {
      not_command = 0;
      pargs = ++argv;
    }
    else {
      fprintf(stderr, "usage: clef [-f fname] -e command\n");
      exit(-1);
    }
  }
  skim_wct();

#ifdef log
  sprintf(logpath, "/tmp/cleflog%d", getpid());
  logfd = open(logpath, O_CREAT | O_RDWR, 0666);
#endif

  /* get the original termio settings, so the child has them */

  if(tcgetattr(0,&childbuf) == -1) {
    perror("clef trying to get the initial terminal settings");
    exit(-1);
  }

  /* start the child process */

  child_pid = fork();
  switch(child_pid) {
  case -1 :
    perror("clef can't create a new process");
    exit(-1);
  case 0:
    /* CHILD */
    /* Dissasociate form my parents group so all my child processes
       look at my terminal as the controlling terminal for the group */
    setsid();

    serverNum = open(serverPath,O_RDWR);
    if (serverNum == -1) perror("open serverPath failed");

    /* since I am the child, I can close ptc, and dup pts for all it
       standard descriptors */
    if (dup2(serverNum, 0) == -1) perror("dup2 0 failed");
    if (dup2(serverNum, 1) == -1) perror("dup2 1 failed");
    if (dup2(serverNum, 2) == -1) perror("dup2 2 failed");
    if( (dup2(serverNum, 0) == -1)  ||
        (dup2(serverNum, 1) == -1) ||
        (dup2(serverNum, 2) == -1)  ) {
      perror("clef trying to dup2");
      exit(-1);
    }

    /* since they have been duped, close them */
    close(serverNum);
    close(contNum);


    /* To make sure everything is nice, set off enhedit */
    /*    childbuf.c_line = 0; */

    /* reconfigure the child's terminal get echoing */
    if(tcsetattr(0, TCSAFLUSH, &childbuf) == -1) {
      perror("clef child trying to set child's terminal");
      exit(-1);
    }

    /* fire up the child's process */
    if(pargs){
      execvp( pargs[0], pargs);
      perror("clef trying to execvp its argument");
      fprintf(stderr, "Process --> %s\n", pargs[0]);
    }
    else{
      program = getenv("SHELL");
      if (!program)
        program = strdup("/bin/sh");
      else
        program = strdup (program);
      execlp( program,program, 0);
      perror("clef trying to execlp the default child");
      fprintf(stderr, "Process --> %s\n", program);
    }
    exit(-1);
    break;
    /* end switch */
  }
  /* PARENT */
  /* Since I am the parent, I should start to initialize some stuff.
     I have to close the pts side for it to work properly */

  close(serverNum);
  ppid = getppid();

  /* Iinitialize some stuff for the reading and writing */
  init_flag(out_flag, MAXLINE);
  define_function_keys();
  init_reader();
  PTY = 1;
  init_parent();

  /* Here is the main loop, it simply starts reading characters from
     the std input, and from the child. */

  while(1)  {           /* loop forever */

    /* use select to see who has stuff waiting for me to handle */
    /* set file descriptors for ptc and stdin */
    FD_ZERO(&rfds);
    FD_SET(contNum,&rfds);
    FD_SET(0,&rfds);
    set_function_chars();
#ifdef log
    {
      char modepath[30];
      sprintf(modepath, "\nMODE = %d\n", MODE);
      write(logfd, modepath, strlen(modepath));
    }
#endif
#ifdef logterm
    {
      struct termio ptermio;
      char pbuff[1024];
      tcgetattr(contNum, &ptermio);
      sprintf(pbuff, "child's settings: Lflag = %d, Oflag = %d, Iflag = %d\n",
              ptermio.c_lflag, ptermio.c_oflag, ptermio.c_iflag);
      write(logfd, pbuff, strlen(pbuff));
    }
#endif

    code = select(FD_SETSIZE,(void *) &rfds, NULL, NULL, NULL);
    for(; code < 0 ;) {
      if(errno == EINTR) {
        check_flip();
        code = select(FD_SETSIZE,(void *) &rfds, NULL, NULL, NULL);
      }
      else  {
        perror("clef select failure");
        exit(-1);
      }
    }

    /* reading from the child **/
    if( FD_ISSET(contNum,&rfds)) {
      if( (num_read = read(contNum, out_buff, MAXLINE)) == -1) {
        num_read = 0;
      }
#ifdef log
      write(logfd, "OUT<<<<<", strlen("OUT<<<<<"));
      write(logfd, out_buff, num_read);
#endif
      if(num_read > 0) {
        /* now do the printing to the screen */
        if(MODE!= CLEFRAW) {
          back_up(buff_pntr);
          write(1,out_buff, num_read);
          print_whole_buff();    /* reprint the input buffer */
        }
        else write(1,out_buff, num_read);
      }
    } /* done the child stuff */
    /* I should read from std input */
    else  {
      if(FD_ISSET(0,&rfds)) {
        num_read = read(0, in_buff, MAXLINE);
#ifdef log
        write(logfd, "IN<<<<<", strlen("IN<<<<<"));
        write(logfd, in_buff, num_read);
#endif
        check_flip();
        if(MODE == CLEFRAW )
          write(contNum, in_buff, num_read);
        else
          do_reading();
      }
    }
  }
}