Esempio n. 1
0
/*
    Handle data acknowledge sent by the ti-99/4 handset ISR (through tms9901
    line P0).  This function is called by a delayed timer 30us after the state
    of P0 is changed, because, in one occasion, the ISR asserts the line before
    it reads the data, so we need to delay the acknowledge process.
*/
void ti99_handset_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	if (id==DELAY_TIMER)
	{
		m_clock_high = !m_clock_high;
		m_buf >>= 4;
		m_buflen--;

		// Clear the INT12 line
		m_joyport->set_interrupt(CLEAR_LINE);

		if (m_buflen == 1)
		{
			// Unless I am missing something, the third and last nibble of the
			// message is not acknowledged by the DSR in any way, and the first nibble
			// of next message is not requested for either, so we need to decide on
			// our own when we can post a new event.  Currently, we wait for 1000us
			// after the DSR acknowledges the second nybble.
			m_delay_timer->adjust(attotime::from_usec(1000));
		}

		if (m_buflen == 0)
			/* See if we need to post a new event */
			do_task();
	}
Esempio n. 2
0
 virtual void* run_once() override {
     m_cur_task = m_pool->pop();
     if (m_cur_task != nullptr)
         do_task();
     else
         usleep(10);
     return nullptr;
 }
Esempio n. 3
0
/* parent goes first program */
int main()
{
	pid_t pid;
	
	TELL_WAIT();
	
	pid = fork();
	if(pid < 0) {
		printf("fork error\n");
	}
	else if(pid == 0) {
		WAIT_PARENT();
		do_task("child task\n");
	}
	else {
		do_task("parent task\n");
		TELL_CHILD(pid);
	}
	
	return 0;
}
Esempio n. 4
0
void *work_thr_clinet_file(void *arg)
{
    int ret;
    SYNC_TASK *task;

    while (1)
    {
        task = fetch_file_task();
        if (NULL == task)
            break;
        do_task(task);
        free_task(task);
    }
    pthread_exit(0);
}
Esempio n. 5
0
File: msh.c Progetto: mrlennix/OS
/*
 *
 *THIS METHOD IS THE MAIN:
 *
 * IT TAKES USER INPUT AND PARSES EACH STRING
 *THEN IT SENDS OF THAT INFO TO ANOTHER FUNCTION FOR PROCESSING
 * THE USERS COMMAND
 */
int main( void ) 
{

//define var
//Stores the length of the user input for removing '\n'
int len;
//Stores the parsed command provided by the user
char ** parsecommand =(char **)malloc(numOftokens*sizeof(char*));
//Stores the users input
char * command  = (char*)malloc(numOfchar*sizeof(char)),SHELL[]="msh>";

//this calls nothing if control+c is called
signal(SIGINT,nothing);
//this calls nothing if control+z is called so the program isn't stopped
signal(SIGTSTP,nothing);

//This is the main loop for the program to run the shell
while ( strcmp(command,"exit") )
{
	//print shell format
	printf("%s",SHELL);
	
	//read users input
	fgets(command,numOfchar,stdin);
	
	//removes '\n' and replaces with '\0'
	if(command[len=(strlen(command)-1)]=='\n')command[len]='\0';
	//if equal to quit it will terminate
	if(!strcmp(command,"quit"))break;
	 //if equal to exit or quit don't do task
	if( strcmp(command,"exit")  )
	{
		//parse string command from use
		parsecommand=parse_tokens(command);
		if(!strcmp("",command))continue;
		//do users task
		do_task(parsecommand);
	}
}

  return 0 ;
}//end of main
Esempio n. 6
0
int do_tasks(void)
{
	int i;
	int status;

	for (i = 0; i < nr_task; i++) {
		if (fork() == 0) {
			return do_task();
		}
	}

	for (i = 0; i < nr_task; i++) {
		if (wait3(&status, 0, 0) < 0) {
			if (errno != EINTR) {
				printf("wait3 error on %dth child\n", i);
				perror("wait3");
				return 1;
			}
		}
	}

	return 0;
}
Esempio n. 7
0
int main(int argc, char *argv[])
{
	int c;

	ourname = argv[0];
	pagesize = getpagesize();

	while ((c = getopt_long(argc, argv,
				"aAf:FPp:gqowRMm:n:t:ds:T:Sr:u:j:h", opts, NULL)) != -1) {
		switch (c) {
		case 'a':
			opt_malloc++;
			break;
		case 'u':
			unit = memparse(optarg, NULL);
			break;
		case 'j':
			step = memparse(optarg, NULL);
			break;
		case 'A':
			msync_mode = MS_ASYNC;
			break;
		case 'f':
			filename = optarg;
			map_shared = MAP_SHARED;
			break;
		case 'p':
			pid_filename = optarg;
			break;
		case 'g':
			do_getchar = 1;
			break;
		case 'm': /* kept for compatibility */
			bytes = strtol(optarg, NULL, 10);
			bytes <<= 20;
			break;
		case 'n':
			nr_task = strtol(optarg, NULL, 10);
			break;
		case 't':
			nr_thread = strtol(optarg, NULL, 10);
			break;
		case 'P':
			prealloc++;
			break;
		case 'F':
			map_populate = MAP_POPULATE;
			break;
		case 'M':
			do_mlock = 1;
			break;
		case 'q':
			quiet = 1;
			break;
		case 's':
			sleep_secs = strtol(optarg, NULL, 10);
			break;
		case 'T':
			runtime_secs = strtol(optarg, NULL, 10);
			break;
		case 'd':
			opt_detach = 1;
			break;
		case 'r':
			reps = strtol(optarg, NULL, 10);
			break;
		case 'R':
			opt_randomise++;
			break;
		case 'S':
			msync_mode = MS_SYNC;
			break;
		case 'o':
			opt_readonly++;
			break;
		case 'w':
			opt_openrw++;
			break;
		case 'h':
			usage(0);
			break;
		default:
			usage(1);
		}
	}

	if (step < sizeof(long))
		step = sizeof(long);

	if (optind != argc - 1)
		usage(0);

	if (pid_filename && nr_task) {
		fprintf(stderr, "%s: pid file is only for single process\n",
			ourname);
		exit(1);
	}

	if (runtime_secs)
		gettimeofday(&start_time, NULL);

	bytes = memparse(argv[optind], NULL);

	if (!opt_malloc)
		fd = open(filename, ((opt_readonly && !opt_openrw) ?
			  O_RDONLY : O_RDWR) | O_CREAT, 0666);
	if (fd < 0) {
		fprintf(stderr, "%s: failed to open `%s': %s\n",
			ourname, filename, strerror(errno));
		exit(1);
	}

	if (prealloc)
		prealloc = allocate(bytes);

	if (nr_task)
		return do_tasks();

	return do_task();
}
Esempio n. 8
0
int main(int argc, char **argv)
{
    int fd;

    if (argc < 2) {
        printf("usage: temporary-file-name\n");
        exit(EXIT_SUCCESS);
    }

    /*
     * lseek() 対象の一時ファイルを作成
     */
    const char *filename = argv[1];

    fd = open(filename, O_CREAT|O_RDWR, 0600);

    if (fd == -1) {
        perror("open");
        exit(EXIT_FAILURE);
    }

    if (ftruncate(fd, LSEEK_FILE_SIZE) < 0) {
        perror("ftruncate");
        exit(EXIT_FAILURE);
    }
    fsync(fd);

    unlink(filename);

    /*
     * アフィニティを確認 
     */
    int max_processors, ret;
    cpu_set_t cpu_set;

    max_processors = (int) sysconf(_SC_NPROCESSORS_CONF);

    if (sched_getaffinity(0, sizeof(cpu_set), &cpu_set) != 0) {
        perror("sched_getaffinity");
        exit(EXIT_FAILURE);
    }

    /*
     * 共有メモリを作成
     */
    void *addr;
    addr = mmap(NULL, sizeof(shared_area_t), PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, -1, 0);
    if (addr == MAP_FAILED) {
        perror("mmap");
        exit(EXIT_FAILURE);
    }

    shared_area_p = (shared_area_t *) addr;

    memset(shared_area_p, sizeof(*shared_area_p), 0);

    /*
     * アフィニティが存在する CPU 毎に子プロセスを作成
     */
    int i;
    for (i = 0 ; i < max_processors ; i++) {
        if (CPU_ISSET(i, &cpu_set)) {
            pid_t pid;

            pid = fork();

            if (pid > 0) {
                /* parent */
                shared_area_p->children[i].pid = pid;
            } else if (pid == 0) {
                /* child */
                cpu_set_t child_cpu_set;

                CPU_ZERO_S(sizeof(child_cpu_set), &child_cpu_set);
                CPU_SET_S(i, sizeof(child_cpu_set), &child_cpu_set);

                if (sched_setaffinity(0, sizeof(child_cpu_set), &child_cpu_set)) {
                    perror("sched_setaffinity");
                    exit(EXIT_FAILURE);
                }

                shared_area_p->children[i].count = do_task(fd, &shared_area_p->start, &shared_area_p->stop);

                exit(EXIT_SUCCESS);
            } else {
                /* error */
                perror("fork");
                exit(EXIT_FAILURE);
            }
        }
    }

    /*
     * 計測
     */
    shared_area_p->start = 1;

    ret = usleep(TEST_DURATION * 1000000);

    if (ret != 0) {
        perror("usleep");
        exit(EXIT_FAILURE);        
    }

    shared_area_p->stop = 1;

    /*
     * 子プロセスの回収と集計
     */
    unsigned long total_count = 0;

    for (i = 0 ; i < max_processors ; i++) {
        pid_t pid = shared_area_p->children[i].pid;
        
        if (pid != 0) {
            pid_t ret;
            int status;

            do {
                ret = waitpid(pid, &status, 0);
            } while (ret == 0);

            if (ret == (pid_t) -1) {
                perror("watipid");
                exit(EXIT_FAILURE);
            }

            assert(pid == ret);

            total_count += shared_area_p->children[i].count;
        }
    }

    printf("TPS: %.3f\n", (double) total_count / TEST_DURATION);

    return 0;
}
Esempio n. 9
0
int KSG_Reactor_Work_Thr::svc()
{
	int ret;
#if 0
	KSG_Service_Handler *handle = NULL;
	while(KsgGetGateway()->is_running())
	{
		handle = schd_->peek_handle();
		if(!handle)
		{
			// wait for signal
			ret = schd_->wait();
			if(ret)
			{
				// 被唤醒
				continue;
			}
			else
			{
				// 超时, sleep 一下
				KSG_SLEEP(1000);
			}
		}
		else
		{
			ret = do_task(handle);
			if(0 == ret)
			{
				// 处理成功, 手工关闭
				handle->handle_close();
			}
			else if(-1 == ret)
			{
				// 处理失败
			}
			else if(1 == ret)
			{
				// 成功,并且需要应答给对方
				// 有未处理的请求数据包
			}
			KSGThreadUtil::Sleep(10); // 10ms sleep
		}
	}
#else
	KSG_Reactor_Scheduler::SERVER_HANDLER *handle = NULL;
	while(KsgGetGateway()->is_running())
	{
		handle = schd_->peek_handle();
		if(!handle)
		{
			// wait for signal
			ret = schd_->wait();
			if(ret)
			{
				// 被唤醒
				continue;
			}
			else
			{
				// 超时, sleep 一下
				KSG_SLEEP(1000);
			}
		}
		else
		{
			ret = do_task2(handle);
			//ret = 0;
			if(0 == ret)
			{
				// 处理成功, 手工关闭
				
			}
			else if(-1 == ret)
			{
				// 处理失败
			}
			else if(1 == ret)
			{
				// 成功,并且需要应答给对方
				// 有未处理的请求数据包
			}
			KSGThreadUtil::Sleep(10); // 10ms sleep
		}
	}
#endif
	return 0;
}