/* Delayed Send Test */ void test_proc_p2_1(void) { int result_pid = 0; msg_buf_t* msg_envelope = NULL; char* msg = "Hello"; msg_envelope = (msg_buf_t*)request_memory_block(); strncpy(msg_envelope->msg_data, msg, 5); delayed_send(PID_P1, msg_envelope, CLOCK_INTERVAL); msg_envelope = (msg_buf_t*)receive_message(NULL); if (strcmp(msg_envelope->msg_data, msg) == 5) { printf("G005_test: test 1 OK\r\n"); } else { printf("G005_test: test 1 FAIL\r\n"); test_results[result_pid] = 0; } release_memory_block(msg_envelope); test_ran[result_pid] = 1; set_process_priority(g_test_procs[result_pid].pid, 3); while (1) { release_processor(); } }
caf::behavior main_phase() { send(this, tick_atom::value); return { [=](const std::vector<uint16_t>& data, uint32_t id) { concat_data(data, id); }, [=](tick_atom) { delayed_send(this, tick_rate_, tick_atom::value); if (cache_.empty()) { std::cout << "[WARNING] Cache empty..." << std::endl; return; } send(sink_, image_width_, cache_.front()); cache_.pop(); send_job(); }, [=](resize_atom, uint32_t w, uint32_t h) { resize(w,h); }, [=](limit_atom, normal_atom, uint32_t workers) { become(make_behavior()); send(this, calc_weights_atom::value, size_t{workers}); }, caf::others() >> [=] { std::cout << to_string(current_message()) << std::endl; } }; }
//TC 1: Delayed message sending & no preemption void proc1(void) { MSG_BUF* envelope = NULL; char* msg = "SE 350"; uart1_put_string("\n\r"); uart1_put_string("G003_test: START\n\r"); uart1_put_string("G003_test: total "); uart1_put_char(total + 48); uart1_put_string(" tests\n\r"); prev_pid = 1; envelope = (MSG_BUF*)request_memory_block(); strcpy(envelope->mtext, msg); delayed_send(1, envelope, 5000); envelope = (MSG_BUF*)receive_message(NULL); if (strcmp(envelope->mtext, msg) == 0) { prev_success = 1; } else { prev_success = 0; } release_memory_block(envelope); if (prev_success) { uart1_put_string("G003_test: test "); uart1_put_char(1 + 48); uart1_put_string(" OK\n\r"); pass = pass + 1; } else { uart1_put_string("G003_test: test "); uart1_put_char(1 + 48); uart1_put_string(" FAIL\n\r"); } //TC 2: Blocked on receive & preemption envelope = (MSG_BUF*)receive_message(NULL); prev_success = 1; // Checks if you ever get here. release_memory_block(envelope); if (prev_success) { uart1_put_string("G003_test: test "); uart1_put_char(2 + 48); uart1_put_string(" OK\n\r"); pass = pass + 1; } else { uart1_put_string("G003_test: test "); uart1_put_char(2 + 48); uart1_put_string(" FAIL\n\r"); } while (1) { release_processor(); } }
void local_actor::delayed_send_tuple(message_priority prio, const channel& dest, const duration& rel_time, message msg) { message_id mid; if (prio == message_priority::high) { mid = mid.with_high_priority(); } auto sched_cd = detail::singletons::get_scheduling_coordinator(); sched_cd->delayed_send(rel_time, address(), dest, mid, std::move(msg)); }
void wall_clock_display(int time) { MSG_BUF *msg; msg = (MSG_BUF *) request_memory_block(); msg->mtype = UPDATE_TIME; delayed_send(PID_CLOCK, msg, ONE_SECOND); msg = (MSG_BUF *) request_memory_block(); msg->mtype = CRT_DISPLAY; timeToChar(time, msg->mtext); send_message(PID_CRT, msg); }
void test1() { void* message_1; void* message_2; void* message_3; void* message_4; void* message_5; void* message_6; printf_0(GID"_test: START\r\n"GID"_test: total 6 tests\r\n"); message_1 = g_test_fixture.request_memory_block(); delayed_send(2, message_1, 2); message_2 = g_test_fixture.request_memory_block(); delayed_send(2, message_2, 100); message_3 = g_test_fixture.request_memory_block(); delayed_send(2, message_3, 1000); message_4 = g_test_fixture.request_memory_block(); delayed_send(2, message_4, 2000); message_5 = g_test_fixture.request_memory_block(); delayed_send(2, message_5, 500); message_6 = g_test_fixture.request_memory_block(); delayed_send(2, message_6, 1); while (1) { g_test_fixture.release_processor(); } }
/** * @brief: a process that prints 2x5 lowercase letters */ void proc1(void) { int i = 0; int j; int counter = 0; int ret_val = 100; char *c; void *mem; MSG_BUF *msg; MSG_BUF *msg2; while ( 1 ) { if (i == 5) { msg = (MSG_BUF *)request_memory_block(); strcpy(msg->mtext, "%Z"); msg->mtype = DEFAULT; msg2 = (MSG_BUF *)request_memory_block(); strcpy(msg2->mtext, "%C 9 2"); msg2->mtype = DEFAULT; send_message(PID_A, msg); delayed_send(PID_SET_PRIO, msg2, ONE_SECOND*25); } if ( i != 0 && i%5 == 0 ) { uart0_put_string("\n\r"); counter++; if ( counter == 4 ) { //ret_val = set_process_priority(PID_P2, HIGH); break; } else { ret_val = release_processor(); } #ifdef DEBUG_0 printf("proc1: ret_val = %d \n", ret_val); #endif /* DEBUG_0 */ } uart0_put_char('a' + i%10); i++; } c = "proc1 end of testing\n\r"; uart0_put_string(c); while ( 1 ) { release_processor(); } }
void C (void) { Q_Queue local_mailbox; int sender_pid; q_init(&local_mailbox); while (1) { msg* p; if (local_mailbox.first == NULL) { p = (msg*)(receive_message(&sender_pid)); } else { p = (msg*)q_pop(&local_mailbox); } if (p->mtype == 3) { int msg_value = atoi(p->mtext); if (msg_value%20 == 0) { msg* MessageToSend = (msg*)request_memory_block(); msg* q = (msg*)request_memory_block(); MessageToSend->mtype = 2; MessageToSend->mtext = "Process C"; send_message(13, MessageToSend); q->mtype = 4; q->mtext = ""; delayed_send(7,q,10000); while (1) { msg* r; r = (msg*)(receive_message(&sender_pid)); //block and let other processes execute if (r->mtype == 4) { release_memory_block(r); break; } else { q_push(&local_mailbox, r); } } } } release_memory_block(p); release_processor(); } }
//Test 4 (normal message is recieved before a delayed message) void proc4(void) { int pid = 4; msgbuf *delayed_msg; msgbuf *normal_msg; msgbuf *received_msg; //create delayed message delayed_msg = request_memory_block(); delayed_msg->mtype = DEFAULT; delayed_msg->mtext[0] = MSG_TEXT_1; //create normal message normal_msg = request_memory_block(); normal_msg->mtype = DEFAULT; normal_msg->mtext[0] = MSG_TEXT_2;//different text from the delayed message //send delayed message delayed_send(pid, delayed_msg, DELAY); //send normal message send_message(pid, normal_msg); //recieve message received_msg = receive_message(&pid); //if normal message, mark test passed if (received_msg->mtext[0] == MSG_TEXT_2){//should get the non delayed message before the delayed message even though it was sent later. test_status[3] = TEST_SUCCESS;//TEST 4: normal message is recieved before delayed message } else { test_status[3] = TEST_FAILURE; } //release message memory release_memory_block(received_msg); //recieve massage received_msg = receive_message(&pid);//reusing variable now that the test is finished. //release message memory release_memory_block(received_msg); //Done testing set_process_priority(pid, LOWEST); while (1) { release_processor(); } }
message_id local_actor::timed_sync_send_tuple_impl(message_priority mp, const actor& dest, const duration& rtime, message&& what) { if (!dest) { throw std::invalid_argument( "cannot send synchronous message " "to invalid_actor"); } auto nri = new_request_id(); if (mp == message_priority::high) { nri = nri.with_high_priority(); } dest->enqueue(address(), nri, std::move(what), host()); auto rri = nri.response_id(); auto sched_cd = detail::singletons::get_scheduling_coordinator(); sched_cd->delayed_send(rtime, address(), this, rri, make_message(sync_timeout_msg{})); return rri; }
//Test 2 (delayed send does not block), and //Test 3 (delayed recieve occurs after correct amount of time) void proc3(void) { int pid = 3; msgbuf *msg; int start_time; int end_time; //create message msg = request_memory_block(); msg->mtype = DEFAULT; msg->mtext[0] = MSG_TEXT_1; //check time start_time = get_time(); //send with delay delayed_send(pid, msg, DELAY); test_status[1] = TEST_SUCCESS;//TEST 2: Send does not block //(if it did, we wouldn't reach this line because this process is sending the message to itself) receive_message(&pid);//don't need to store, because we have the original. Just checking the timing. //check time end_time = get_time(); //mark test 3 passed if it is late enough, otherwise make it failed if (end_time >= start_time + DELAY){ test_status[2] = TEST_SUCCESS;//TEST 3: delayed message recieved after the appropriate delay } else { test_status[2] = TEST_FAILURE;//message recieved too soon } //release message memory release_memory_block(msg); //Done testing set_process_priority(pid, LOWEST); while (1) { release_processor(); } }
inline void delayed_reply(const std::chrono::duration<Rep, Period>& rel_time, Args&&... what) { delayed_send(self->last_sender(), rel_time, std::forward<Args>(what)...); }
void wall_clock_proc(void) { /*sends message to kcd to register the command types*/ ENVELOPE *msg = (ENVELOPE *)request_memory_block(); msg->message_type = MSG_COMMAND_REGISTRATION; msg->sender_pid = WALL_CLOCK_PID; msg->destination_pid = KCD_PID; set_message(msg, "%WR" + '\0', 4*sizeof(char)); send_message(KCD_PID, msg); msg = (ENVELOPE *)request_memory_block(); msg->sender_pid = WALL_CLOCK_PID; msg->destination_pid = KCD_PID; msg->message_type = MSG_COMMAND_REGISTRATION; set_message(msg, "%WS" + '\0', 4*sizeof(char)); send_message(KCD_PID, msg); msg = (ENVELOPE *)request_memory_block(); msg->sender_pid = WALL_CLOCK_PID; msg->destination_pid = KCD_PID; msg->message_type = MSG_COMMAND_REGISTRATION; set_message(msg, "%WT" + '\0', 4*sizeof(char)); send_message(KCD_PID, msg); while(1){ ENVELOPE * rec_msg= (ENVELOPE*) receive_message(NULL); char * char_message = (char *) rec_msg->message; if(rec_msg->message_type == MSG_WALL_CLOCK && rec_msg->sender_pid == WALL_CLOCK_PID && show_wclock ==1) { int curr_time = 0; int s1, s2, m1, m2, h1, h2; ENVELOPE * delay_msg = (ENVELOPE*) request_memory_block(); ENVELOPE * w_clock = (ENVELOPE*) request_memory_block(); w_clock->sender_pid = WALL_CLOCK_PID; w_clock->destination_pid = CRT_PID; w_clock->message_type = MSG_CRT_DISPLAY; curr_time = g_timer_count - elapsed + base; w_secs= (curr_time /1000)%60; s2=w_secs%10; s1=w_secs/10; w_mins = (curr_time/(60000))%60; m2=w_mins%10; m1=w_mins/10; w_hours= (curr_time/(3600000))%24; h2=w_hours%10; h1=w_hours/10; w_clock->message = w_clock + HEADER_OFFSET; sprintf(w_clock->message, "%d%d:%d%d:%d%d\n\r", h1,h2,m1,m2,s1,s2); send_message(CRT_PID, w_clock); delay_msg->message_type=MSG_WALL_CLOCK; delay_msg->sender_pid=WALL_CLOCK_PID; delay_msg->destination_pid=WALL_CLOCK_PID; delay_msg->message=NULL; delayed_send(WALL_CLOCK_PID, delay_msg, 1000); } else { if (char_message[2]== 'R') { ENVELOPE *msg =(ENVELOPE *) request_memory_block(); msg->message_type=MSG_WALL_CLOCK; msg->sender_pid=WALL_CLOCK_PID; msg->destination_pid=WALL_CLOCK_PID; msg->message=NULL; w_secs=0; w_mins=0; w_hours=0; base = 0; elapsed = g_timer_count; if (show_wclock == 0){ show_wclock = 1; send_message(WALL_CLOCK_PID, msg); } } if (char_message[2]== 'S') { if ((char_message[4] >= '0')&&(char_message[4] <= '9')&&(char_message[5] >= '0')&&(char_message[5] <= '9')&&(char_message[6] == ':') &&(char_message[7] >= '0')&&(char_message[7] <= '9')&&(char_message[8] >= '0')&&(char_message[8] <= '9')&&(char_message[9] == ':') &&(char_message[10] >= '0')&&(char_message[10] <= '9')&&(char_message[11] >= '0')&&(char_message[11] <= '9') &&((char_message[12] == ' ')||(char_message[12] == '\0'))) { int h1,h2,m1,m2,s1,s2; ENVELOPE *msg =(ENVELOPE *) request_memory_block(); msg->message_type=MSG_WALL_CLOCK; msg->sender_pid=WALL_CLOCK_PID; msg->destination_pid=WALL_CLOCK_PID; msg->message=NULL; h1=char_message[4] - '0'; h2=char_message[5] - '0'; w_hours=h1*10 + h2; m1=char_message[7] - '0'; m2=char_message[8] - '0'; w_mins=m1*10 + m2; s1=char_message[10] - '0'; s2=char_message[11] - '0'; w_secs= s1*10 + s2; elapsed = g_timer_count; base = ((w_hours * 3600) + (w_mins * 60) + w_secs) * 1000; if (show_wclock == 0){ show_wclock = 1; send_message(WALL_CLOCK_PID, msg); } } } else if (char_message[2]== 'T') { show_wclock=0; } } release_memory_block(rec_msg); }//end while }
void stress_c() { #ifdef _STRESS_DEBUG rtx_dbug_outs("Initializing: Stress Test C\r\n"); #endif msgq_head = NULL; msgq_tail = NULL; struct num_message * msg_rx; struct num_message * msg_wake; struct MessageEnvelope * proc_c; struct num_message * hibernate; while(1) { #ifdef _STRESS_DEBUG rtx_dbug_outs("Enter: Stress Test C\r\n"); #endif if(msgq_head == NULL) { // receive message msg_rx = (num_message *)receive_message(NULL); #ifdef _STRESS_DEBUG rtx_dbug_outs("Stress Test C received a message\r\n"); #endif } else { // dequeue first message from local message queue msg_rx = msgq_head->env; msgq_head = msgq_head->next; if(msgq_head == NULL) { msgq_tail = NULL; } #ifdef _STRESS_DEBUG rtx_dbug_outs("Stress Test C dequeued a message\r\n"); #endif } UINT32 type = msg_rx->type; UINT32 msg_data = msg_rx->msg; release_memory_block((void *)msg_rx); if(type == TYPE_COUNT_REPORT) { #ifdef _STRESS_DEBUG rtx_dbug_outs_int("Stress Test C got message ", msg_rx->msg); #endif if(msg_data%20 == 0) { proc_c = (MessageEnvelope *)request_memory_block(); str_copy((BYTE *) "Process C\r\n", (BYTE *)proc_c->msg); send_message(CRT_PID, proc_c); #ifdef _STRESS_DEBUG rtx_dbug_outs("Stress Test C sent a message to CRT\r\n"); #endif // hibernate for 10 seconds hibernate = (num_message *)request_memory_block(); hibernate->type = TYPE_WAKEUP10; delayed_send(STRESS_C_PID, hibernate, 10000); while(1) { msg_wake = (num_message *)receive_message(NULL); if(msg_wake->type == TYPE_WAKEUP10) { break; } else { // enqueue the message into local queue enqueue_local_msg(msg_wake); } } } } release_memory_block((void *)hibernate); release_processor(); } }
void clock_process() { int sender, parsed_length, d1, d2; char* parsed_msg, *pointer; MSG_BUF *crtMessage; MSG_BUF *each_msg, *msg_buf = (MSG_BUF*)request_memory_block(); msg_buf->mtype = MSG_CLOCK_NOTIFICATION; reg_msg.mtype = MSG_KCD_REG; strcpy(reg_msg.mtext,"%W"); send_message(PID_KCD, ®_msg); delayed_send(PID_CLOCK ,msg_buf,1000); while(1) { each_msg = receive_message(&sender); switch (each_msg->mtype) { case MSG_CLOCK_NOTIFICATION: { second++; if(second % 60 == 0 && second > 0) { minute += second / 60; second = second % 60; if(minute % 60 == 0 && minute > 0) { hour += minute / 60; minute = minute % 60; } } if(display == 1) { crtMessage = (MSG_BUF*)request_memory_block(); crtMessage->mtype= MSG_CRT_DISPLAY; pointer = (char*)crtMessage->mtext; if(hour < 10) { k_sprintf(pointer, "0%d:", hour); } else { k_sprintf(pointer, "%d:", hour); } pointer = _next_null_pos(pointer); if(minute < 10) { k_sprintf(pointer, "0%d:", minute); } else { k_sprintf(pointer, "%d:", minute); } pointer = _next_null_pos(pointer); if(second < 10) { k_sprintf(pointer, "0%d\n", second); } else { k_sprintf(pointer, "%d\n", second); } send_message(PID_CRT, crtMessage); release_memory_block(crtMessage); } delayed_send(PID_CLOCK ,msg_buf,1000); break; } case MSG_DEFAULT: { parsed_msg = (char*)each_msg->mtext; parsed_length = str_len(parsed_msg); if(parsed_length < 3) break; if(parsed_msg[2] == 'S') { hour = 0; minute = 0; second = 0; display = 1; } else if(parsed_msg[2] == 'R' && parsed_length == 12 && parsed_msg[3] == ' ' && parsed_msg[6] == ':' && parsed_msg[9] == ':') { d1 = charToInt(parsed_msg[4]); if(d1 < 0) break; d2 = charToInt(parsed_msg[5]); if(d2 < 0) break; hour = d1*10 + d2; d1 = charToInt(parsed_msg[7]); if(d1 < 0) break; d2 = charToInt(parsed_msg[8]); if(d2 < 0) break; minute = d1*10 + d2; d1 = charToInt(parsed_msg[10]); if(d1 < 0) break; d2 = charToInt(parsed_msg[11]); if(d2 < 0) break; second = d1*10 + d2; display = 1; } else if(parsed_msg[2] == 'T') { display = 0; } break; } default: break; } } }
void wall_clock() { { // Register the command. Mail* envelop = (Mail*)request_memory_block(); RegisteredCommand* rc = (RegisteredCommand*)(((char*)envelop)+64); RegisteredCommand_construct(rc,'W', WALL_CLOCK_PID, WALL_CLOCK_CHANGE_MSG_TYPE); envelop->m_messageType = COMMAND_REGISTRATION_MSG_TYPE; send_message(KEYBOARD_DECODER_PROCESS_PID, envelop); //rtx_dbug_outs((CHAR *)"<=========register command complete"); } Mail* secMail = (Mail*)request_memory_block(); Mail* crtMessage = (Mail*)request_memory_block(); secMail->m_messageType = WALL_CLOCK_NEXT_SECOND_MSG_TYPE; delayed_send(WALL_CLOCK_PID, secMail, 1000); //rtx_dbug_outs((CHAR *)"<=========delay send complete"); // Start the wall clock. int currentTime = -1; while (TRUE) { int senderId; secMail = (Mail*)receive_message(&senderId); //rtx_dbug_outs((CHAR *)"received message! \r\n"); char* msg = ((char*)secMail)+64; if (secMail->m_messageType == WALL_CLOCK_CHANGE_MSG_TYPE) { // Parse the message. char type = msg[2]; if (type == 'T') { currentTime = -1; } else if (type == 'S') { // Set wall clock // %WS HH:MM:SS currentTime = parse_to_sec(msg); //rtx_dbug_outs((CHAR *)"clock set"); //rtx_dbug_out_number(currentTime); } release_memory_block(secMail); continue; } else if (secMail->m_messageType == WALL_CLOCK_NEXT_SECOND_MSG_TYPE) { //rtx_dbug_outs((CHAR *)"clock add second\r\n"); if (currentTime != -1){ currentTime += 1; //rtx_dbug_outs((CHAR *)"clock add second\r\n"); if (currentTime == 24*60*60){ currentTime = 0; } } } else { //rtx_dbug_outs((CHAR *)"BAD BAD\r\n"); } char* data = ((char*)crtMessage)+64; if (currentTime != -1){ parse_to_display(¤tTime, data); data[10] = '\0'; } else { data[0] = '\0'; } delayed_send(WALL_CLOCK_PID, secMail, 1000); crtMessage->m_messageType = CRT_OUTPUT_MSG_TYPE; send_message(CRT_DISPLAY_PID, crtMessage); crtMessage = (Mail*)request_memory_block(); } }