Ejemplo n.º 1
0
void *k_receive_message_nonblocking(int* pid){
	Node* res;
	void* msg;

	if (!is_pid_valid(*pid)|| isEmpty(get_message_queue(*pid))){
        return NULL;
	}

	res = dequeue_message_queue(*pid);
	msg = res->data;
	k_release_node(res);
	return msg;
}
Ejemplo n.º 2
0
Node* k_receive_message_node(int* sender_id) {
	Node* res;

	__disable_irq();

	while (isEmpty(get_message_queue(gp_current_process->m_pid))){
		__enable_irq();
		block_current_process_on_receive();
		__disable_irq();
	}

	res = dequeue_message_queue(gp_current_process->m_pid);

	__enable_irq();

	if (res != NULL) {
		*sender_id = res->sender_id;
	}

	return res;
}
Ejemplo n.º 3
0
void *k_receive_message(int* p_pid){
	Node* res;
	void* msg;

	__disable_irq();

	while (isEmpty(get_message_queue(gp_current_process->m_pid))){
		__enable_irq();
		block_current_process_on_receive();
		__disable_irq();
	}

	res = dequeue_message_queue(gp_current_process->m_pid);

	__enable_irq();

    if (res == NULL) {
        return NULL;
    }
    *p_pid = res->sender_id;
	msg = res->data;
	k_release_node(res);
	return msg;
}
Ejemplo n.º 4
0
/**
 * obtains the resources needed by the session for it to function.
 *
 * @function   initialize
 *
 * @date       2015-02-12
 *
 * @revision   none
 *
 * @designer   EricTsang
 *
 * @programmer EricTsang
 *
 * @note       none
 *
 * @signature  static void initialize(int clntPid, int priority, char* filePath)
 *
 * @param      clntPid process id of the session's client process
 */
static void initialize(int clntPid, int priority, char* filePath)
{
    Message pidMsg;         /* used to send client the PID of this process */
    char fatalstring[MAX_STR_LEN];  /* buffer used to print fatal messages */

    pidMsg.dataType  = MSG_DATA_PID;

    /* initialize global client PID */
    clientPid = clntPid;

    /* set signal handler */
    signal(SIGUSR1, sigusr1_handler);

    /* get the message queue. */
    get_message_queue(&msgQId);

    /* verify priority input */
    if(priority < MIN_PROC_PRIO || priority > MAX_PROC_PRIO)
    {
        sprintf(fatalstring, "invalid priority; %d <= priority <= %d\n",
            MIN_PROC_PRIO, MAX_PROC_PRIO);
        fatal(fatalstring);
    }

    /* open the file */
    fd = open(filePath, 0);
    if(fd == -1)
    {
        sprintf(fatalstring, "failed to open file: %d\n", errno);
        fatal(fatalstring);
    }

    /* send the client the session's PID */
    pidMsg.data.pidMsg.pid = getpid();
    msg_send(msgQId, &pidMsg, clientPid);
}