Example #1
0
void sleep(int secs)
{
	PROCESS * proc;
	proc = GetProcessByPID(CurrentPID);
	proc->sleep = 18 * secs;
	block_process(CurrentPID);
}
Example #2
0
void waitpid_in_kernel(int pid)
{
	PROCESS* proc;
	proc = GetProcessByPID(CurrentPID);
	proc->waitingPid = pid;
	block_process(CurrentPID);
}
Example #3
0
std::vector<std::string> parallel_parse(str_vec_iter begin, str_vec_iter end, const GTFOptions & options) {

    const size_t MIN_SIZE = 10000;

    size_t length = std::distance(begin, end);

    if (length < MIN_SIZE) {
        return block_process() (begin, end, std::ref(options));
    }

    size_t num_threads = std::max((unsigned int)2, std::thread::hardware_concurrency());
    size_t block_size = length / num_threads;

    str_vec_iter current_begin, current_end;
    current_begin = begin;

    std::vector< std::future<std::vector<std::string>>> handle_vector;

    for (size_t i=0 ; i < (num_threads - 1) ; i++) {
        current_end=current_begin;
        std::advance(current_end, block_size);
        handle_vector.push_back(
            std::async(
                std::launch::async, block_process(), current_begin, current_end, std::ref(options)
            )
        );
        current_begin = current_end;
    }

    handle_vector.push_back(
        std::async(
            std::launch::async, block_process(), current_begin, end, std::ref(options)
        )
    );

    std::vector<std::string> final_results;

    std::for_each(handle_vector.begin(), handle_vector.end(), [&final_results](auto &element){
        auto result = element.get();
        std::move(result.begin(), result.end(), std::back_inserter(final_results));
    });

    return std::move(final_results);
}
void core_test2() {
	rtx_dbug_outs("Running core test 2\r\n");
	block_process(CORE_TEST2_PID, mem);
	rtx_dbug_outs("Core test 2 unblocked\r\n");
}
Example #5
0
//int argc;
//char *argv[];
main(int argc,char * argv[])
{
    int command;
    int prio;
    float ratio;
    int status;

    if (argc < (MAXPRIO+1))
    {
        fprintf(stdout, "incorrect usage\n");
        return;
    }

    initialize();
    for (prio=MAXPRIO; prio >= 1; prio--)
    {
        init_prio_queue(prio, atoi(argv[prio]));
    }
    for (status = fscanf(stdin, "%d", &command);((status!=EOF) && status);status = fscanf(stdin, "%d", &command))
    {
        switch (command)
        {
        case FINISH:
            finish_process();
            break;
        case BLOCK:
            block_process();
            break;
        case QUANTUM_EXPIRE:
            quantum_expire();
            break;
        case UNBLOCK:
            fscanf(stdin, "%f", &ratio);
            unblock_process(ratio);
            break;
        case UPGRADE_PRIO:
            fscanf(stdin, "%d", &prio);
            fscanf(stdin, "%f", &ratio);
            if (prio > MAXPRIO || prio <= 0)
            {
                fprintf(stdout, "** invalid priority\n");
                return;
            }
            else
            {
                upgrade_process_prio(prio, ratio);
            }
            break;
        case NEW_JOB:
            fscanf(stdin, "%d", &prio);
            if (prio > MAXPRIO || prio <= 0)
            {
                fprintf(stdout, "** invalid priority\n");
                return;
            }
            else
            {
                add_process(prio);
            }
            break;
        case FLUSH:
            finish_all_processes();
            break;
        }
    }
}
Example #6
0
int comms_send(cpu_state* state)
{
  unsigned int port = state->ebx;
  void *req_buf = (void*)state->ecx;
  unsigned int req_size = state->edx;
  void *rep_buf = (void*)state->esi;
  unsigned int rep_size = state->edi;
  
  //return no such port when if the port doesn't exist
  if (bt(comms_bitmap,port))
  {
    state->eax = -ERR_IPC_NO_SUCH_PORT;
    return 0;
  }
  //return invalid port if port exceeds max ports
  if (port >= COMMS_MAX_PORTS)
  {
    state->eax = -ERR_IPC_INVALID_PORT;
    return 0;
  }
  //return invalid msg size if req_size or rep_size is less than 1 or exceeds max msg size
  if ((req_size < 1) | (req_size > COMMS_MAX_MSG) | (rep_size < 1) | (rep_size >= COMMS_MAX_MSG))
  {
    state->eax = -ERR_IPC_INVALID_MSG_SIZE;
    return 0;
  }
  //return invalid buffer when a buffer equals NULL
  if ((req_buf == NULL) | (rep_buf == NULL))
  {
    state->eax = -ERR_IPC_INVALID_BUFFER;
    return 0;
  }

  //allocate memory for the message
  msg *temp = (struct msg*)mem_alloc(sizeof(struct msg));
  
  //is this the first message?
  if (msg_port[port]->queue == NULL)
  {
    //set as first node
    msg_port[port]->queue = temp;    
  }else
  {
    //let the last message point to it
    msg_port[port]->last->next = temp;    
  }
  //the msg is also the last msg
  msg_port[port]->last = temp;
  
  //save it's page directory
  temp->pd = (void*)cr3();
  
  //save the adress of the request and it's size
  temp->req_buf = req_buf;
  temp->req_size = req_size;
  //save the adress we need to reply to and it's size
  temp->rep_buf = rep_buf;
  temp->rep_size = rep_size;
  //there isn't a next
  temp->next = NULL;
  //get the server page directory
  page_directory* pd = (page_directory*)(msg_port[port]->pcb->pd);
  
  //get the page table entry where the server is located
  unsigned int pt_entry = pd->table[msg_port[port]->index];
  
  //get the client page directory   
  pd = (page_directory*)(temp->pd);
  //get a open slot in the page directory 
  temp->offset = 0;
  while ((temp->offset < PTES) && (pd->table[temp->offset] != 0))
  {
    temp->offset++;
  }
    
  //add the server page table into the client's page directory
  pd->table[temp->offset] = pt_entry;
  
  //save the multiplier to work with the server adresses in the client pd
  temp->mult = (temp->offset - msg_port[port]->index) * 0x400000;
  
  //unblock the server if it's blocked and send the message dadelik
  if (unblock_server(port))
  {
    //flush tlb
    mem_switch_to_kernel_directory();
    i386_set_page_directory(temp->pd);
    void *buf = (void*)msg_port[port]->pcb->state->ecx;
    //copy the message request into buf
    copy_4(temp->req_buf,(unsigned int)buf+temp->mult,req_size/4);
  }
  
  //block the client
  state->eax = OK;
  block_process(port,state);
  
  //return reschedule
  return 1;    
}
Example #7
0
void logUser(void)
{
	int i, fd, usrNotFound, j;
	user * usr;
	current = superblock->root;
	currentUsr.group = ADMIN;
	fd = do_open("usersfile", 777, 777);
	usr = malloc(sizeof(user) * 100);
	do_read(fd, (char *)usr, sizeof(user) * 100);

	while(!usrLoged)
	{
		usrNotFound = 1;
		printf("username: "******"%s", buffcopy);
		for(i = 0; i < 100 && usr[i].usrID != 0 && usrNotFound; i++)
		{
			if(strcmp(usr[i].name, buffcopy))
			{
				usrNotFound = 0;
			}
		}
		usrName = 0;
		printf("\n");
		clearTerminalBuffer(currentTTY);
		for(j = 0; j < BUFFER_SIZE; j++)
			buffcopy[j] = 0;
		if(!usrNotFound)
		{
			printf("password: "******"%s", buffcopy);
			if(strcmp(usr[i - 1].password, buffcopy))
			{
				usrLoged = 1;
				currentUsr.usrID = usr[i - 1].usrID;
				currentUsr.group = usr[i - 1].group;
			}
			else
				printf("\nIncorrect password. Please try again");
			password = 0;
			printf("\n");
		} else
			printf("User not found. Please try again\n");
		clearTerminalBuffer(currentTTY);
		for(j = 0; j < BUFFER_SIZE; j++)
			buffcopy[j] = 0;
	}
	terminals[0].PID = CreateProcessAt("Shell0", (int(*)(int, char**))shell, 0, 0, (char**)0, PAGE_SIZE, 2, 1);
	//printf("terminals[0].PID \n");
	terminals[1].PID = CreateProcessAt("Shell1", (int(*)(int, char**))shell, 1, 0, (char**)0, PAGE_SIZE, 2, 1);
	//printf("terminals[1].PID \n");
	terminals[2].PID = CreateProcessAt("Shell2", (int(*)(int, char**))shell, 2, 0, (char**)0, PAGE_SIZE, 2, 1);
	//printf("terminals[2].PID \n");
	terminals[3].PID = CreateProcessAt("Shell3", (int(*)(int, char**))shell, 3, 0, (char**)0, PAGE_SIZE, 2, 1);
	//printf("terminals[3].PID \n");
	//do_close(fd);

	//free(usr);
	_Sti();
	return;
}