Skip to content
Snippets Groups Projects
Commit a27db952 authored by Tom Feng's avatar Tom Feng
Browse files

Merge branch 'kernel2' into 'k2merge'

# Conflicts:
#   lib/buffer.c
#   lib/rps.c
parents 85b43580 2598b051
No related branches found
No related tags found
1 merge request!2due date morning, rps doesn't work
......@@ -77,4 +77,4 @@ int BufferShrinkFIFO(Buffer* Buf, int Num)
Buf->Head = (Buf->Head + ActualShrink) % Buf->Size;
return 0;
}else return BUFF_NOTREADY;
}
}
\ No newline at end of file
......@@ -164,25 +164,23 @@ int Player(int ID){
SendMsg.Choice = Paper;
break;
}
else if (Input == 's' || Input == 'S') {
SendMsg.Choice = Scissors;
break;
}else if(Input == 'q' || Input == 'Q'){
SendMsg.Msg = Quit;
}
else {
Input = 'U';
bwprintf(COM2, "Please enter r/R for Rock, p/P for Paper, s/S for Scissors.\n\r");
}
}
SendMsg.Msg = Play;
Result = Send(ServerTID, &SendMsg, sizeof(SendMsg), &ReplyMsg, sizeof(ReplyMsg));
if (Result != sizeof(ReplyMsg)) {
if(SendMsg.Msg == Quit){
bwprintf(COM2, "Request for QUIT from %s did not go through gracefully.", Name);
}else{
bwprintf(COM2, "%s: Game obstructed!",Name);
char Input = 'U'; // for Undefined
RPSMsgType RPSResult;
int MyTID, ServerID, Result;
RPSMessage SendMsg, ReplyMsg;
MyTID = MyTid();
bwprintf(COM2, "%s with TaskID(%d) is about to Play\n\r", Name, MyTID);
ServerTID = WhoIs("RPSServer");
if (ServerTID < 0) return FAILURE;
SendMsg.Msg = SignUp;
Result = Send(ServerTID, &SendMsg, sizeof(SendMsg), &ReplyMsg, sizeof(ReplyMsg));
if (Result != sizeof(ReplyMsg)) {
bwprintf(COM2, "Sign Up Request to Server did not go through.");
return Result;
}
return FAILURE;
}else{
......@@ -190,19 +188,17 @@ int Player(int ID){
bwprintf(COM2, "%s exitting...",Name);
Result = ReplyMsg.Msg;
}
}
}
return SUCCESS;
return SUCCESS;
}
int RPSClient1(){
Player(1);
Exit();
Player(1);
Exit();
}
int RPSClient2(){
Player(2);
Exit();
}
Player(2);
Exit();
}
\ No newline at end of file
#include <k2PerfTest.h>
#include <timer.h>
#include <syscall.h>
#include "nameserver.h"
void HelloWorld() {
bwprintf(COM2, "Hello World\n\r");
void Sender() {
int ReceiverTID, Result, i, startTime, endTime;
int sum = 0;;
int SendMsg, ReplyMsg;
Clock* c;
ClockInit(c);
ReceiverTID = WhoIs("Rcvr");
for (i = 0; i < 100; ++i) {
ClockUpdate(c);
startTime = c->ClockCount;
Send(ReceiverTID, (void*)SendMsg, sizeof(SendMsg), (void*)ReplyMsg, sizeof(ReplyMsg));
ClockUpdate(c);
endTime = c->ClockCount;
sum += endTime - startTime;
}
sum /= 100;
bwprintf(COM2, "Time: \n\r", sum);
Exit();
}
void Receiver() {
int SenderTID, Result, i, StartTime, EndTime;
int sum = 0;
int ReceiveMsg, ReplyMsg; // 4 bytes
Clock* c;
ClockInit(c);
Result = RegisterAS("Rcvr");
Receive(&SenderTID, (void*)ReceiveMsg, sizeof(ReceiveMsg));
Reply(SenderTID, ReplyMsg, sizeof(ReplyMsg));
x
for (i = 0; i < 100; i++) {
ClockUpdate(c);
startTime = c->ClockCount;
Receive(&senderTid, ReceiveMsg, sizeof(ReceiveMsg));
ClockUpdate(c);
endTime = c->ClockCount;
Reply(SenderTID, ReplyMsg, sizeof(ReplyMsg));
sum += (EndTime-StartTime);
}
sum /= 100;
bwpritnf(COM2, "Time: %d\n\r",sum );
Exit();
}
void PerfTest() {
int Task1ID, Task2ID;
int i;
char SendMsg[6] = "CS452";
int SendMsgLen = 6, ReplyMsgLen = 6;
char Reply[6];
int SenderTID, ReceiverTID, NSTID, SendFirst = 1;
AP Args1, Args5, Args;
char* SendMsg, ReplyMsg;
AP* Args4;
Args4->arg0 = (PrioLvl) Prio4;
Args4->arg1 = (void* ) (&HelloWorld);
Args5.arg0 = (void *) Prior5;
Args5.arg1 = (void *) (&Receiver);
Task1ID = Create(&Args4);
Args1.arg0 = (void *) Prior1;
Args1.arg1 = (void *) (&Receiver);
Task2ID = Create(&Args4);
Args.arg1 = (void*) (&Receiver);
for (i = 0; i < 10; i++) {
Send(Task1ID, SendMsg, SendMsgLen, ReplyMsgLen,
}
NSTID = Create(&Args1);
if (SendFirst) Args.arg0 = (void*) Prior3;
else Args.arg0 = (void*) Prio7;
ReceiverTID = Create(&Args);
Args5.arg1 = (void*)(&Sender);
SenderTID = Create(&Args5);
Send(ReceiverTID, (void*)SendMsg, sizeof(SendMsg), (void*)Reply, sizeof(ReplyMsg));
Exit();
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment