Question

In: Computer Science

how to convert Sudo Code to C language of these two functions MsgEnv * request_msg_env( )...

how to convert Sudo Code to C language of these two functions

MsgEnv * request_msg_env( ) {

search for free memory block in the queue of the free blocks(shown in the data structure section );

if (no memory block is available)

{

Block invoking process(Process_switching();

}

else

{

update the data structure;

return a pointer to the memory block;

}

int release_msg_env( MsgEnv * msg_env_ptr ) :

{ if (memory block pointer is not valid)

return ErrorCode;

Add memory block to the pool;

Update datastructure;

Return Sucess code

}

these are the data stucures used in the above functions

// data strucure of message envelops
typedef struct MsgEnv{ struct MsgEnv *Msg_env_ptr;
char body[128];
int time_delay,sender_pid, Target_pid;
int Message_type ; }MsgEnvi;

// queue of message envelops

typedef struct MsgEnvq {
MsgEnvi *head;
MsgEnvi *tail;
MsgEnvi* (*dequeue)();
int (*enqueue)(MsgEnvi *env);
struct MsgEnvq *next;
};

Solutions

Expert Solution

The question have given you the pseudo code. So first step is to understand as ti what it states.

I assume you have the basic knowledge about how a queue works. So according to the given pseudo code we can say,

first function is traversal and searching in the queue

second function is just releasing the memory block that is deleting(dequeue) from a queue

No description about the size of queue is given. So I am taking it as a constant Size_Q in my code.

// data strucure of message envelops
typedef struct MsgEnv{ struct MsgEnv *Msg_env_ptr;
char body[128];
int time_delay,sender_pid, Target_pid;
int Message_type ; }MsgEnvi;

// queue of message envelops

typedef struct MsgEnvq {
MsgEnvi *head;
MsgEnvi *tail;
MsgEnvi* (*dequeue)();
int (*enqueue)(MsgEnvi *env);
struct MsgEnvq *next;
};

#define size_q 5

MsgEnv *search_queue(Msgenv *s){

int count=0;

MsgEnv *temp = s->head;

for(temp=s->head;temp!=NULL;temp=temp->NULL){

count++;

}

if(count == 5){

Block invoking process(Process_switching();

temp = NULL;

}

else{

temp = s->tail->next;

update the data structure;

s->tail = temp;

temp->tail = s->tail;

}

return temp;

}

int release_msg_env(MsgEnv * msg_env_ptr){

if(msg_env_ptr == NULL)

return 0; // refering 0 as error code as int has to be returned. You amy include your ErrorCode function as well which will be returning its own integer value which will finally be returned by this return statement.

else{

msg_env_ptr->next = NULL

}

}


Related Solutions

How to convert Sudo Code to C language? keyboard_process() {//insert a string. //check for shared memory...
How to convert Sudo Code to C language? keyboard_process() {//insert a string. //check for shared memory If(shared memory not full) { //sendthe string to the shared memory //send signal to process; }
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
Implement two functions in C language: stringLength() - Takes a pointer to a string, and a...
Implement two functions in C language: stringLength() - Takes a pointer to a string, and a pointer to an int variable. It computes the length of the string and updates the int variable with the length. stringCopy() - Copies one string onto another using pointers #include<stdio.h> #define MAX_STR_LEN 2048 void stringLength(char *str, int *len) { // This function computes the length of the string // at the address in the pointer *str. Once the length // has been determined, it...
Please write code for C language Problem: Write a couple of functions to process arrays. Note...
Please write code for C language Problem: Write a couple of functions to process arrays. Note that from the description of the function you have to identify what would be the return type and what would be part of the parameter. display(): The function takes an int array and it’s size and prints the data in the array. sumArray(): It takes an int array and size, and returns the sum of the elements of the array. findMax(): It takes an...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
All in C++ programming language 1. a.) convert for loop to while loop example b.) convert...
All in C++ programming language 1. a.) convert for loop to while loop example b.) convert while loop to for loop example 2.) pass one dimension array(and its size) to function example
C++ Please Fill in for the functions for the code below. The functions will be implemented...
C++ Please Fill in for the functions for the code below. The functions will be implemented using vectors ONLY. Additional public helper functions or private members/functions can be used. The List class will be instantiated via a pointer and called similar to the code below: Stack *ptr = new Stack(); ptr->push(value); int pop1 = ptr->pop(); int pop2 = ptr->pop(); bool isEmpty = ptr->empty(); class Stack{     public: // Default Constructor Stack() {// ... } // Push integer n onto top of...
C++ Please Fill in for the functions for the code below. The functions will implement an...
C++ Please Fill in for the functions for the code below. The functions will implement an integer list using dynamic array ONLY (an array that can grow and shrink as needed, uses a pointer an size of array). Additional public helper functions or private members/functions can be used. The List class will be instantiated via a pointer and called similar to the code below: class List { public: // Default Constructor List() {// ... } // Push integer n onto...
C++ Please Fill in for the functions for the code below. The functions will implement an...
C++ Please Fill in for the functions for the code below. The functions will implement an integer stack using deques ONLY. It is possible to use only one deque but using two deques also works. Additional public helper functions or private members/functions can be used. The Stack class will be instantiated via a pointer and called as shown below: Stack *ptr = new Stack(); ptr->push(value); int pop1 = ptr->pop(); int pop2 = ptr->pop(); bool isEmpty = ptr->empty(); class Stack{     public:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT