Skip to content

Commit

Permalink
lib and pm all compiles now. 'make world' works
Browse files Browse the repository at this point in the history
  • Loading branch information
gopalshankar committed Oct 23, 2011
1 parent 9a4a7ec commit a9ed371
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 67 deletions.
2 changes: 1 addition & 1 deletion include/minix/libmsgque.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* and structures associated with it
*/

PUBLIC struct MsgQue {
struct MsgQue {
int token; /* This identifies the Message Queue uniquely
* Multiple applications can use same key to
* operate of single queue in multicast mode */
Expand Down
106 changes: 58 additions & 48 deletions servers_pm/msgque.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@
#include "mproc.h"
#include "param.h"

PRIVATE MQueue mQueue_[MQ_MAX_MSGQUES];
struct MQueue mQueues_[MQ_MAX_MSGQUES];



PRIVATE int cleanOnTimer( ) { /* Need to call this periodically using timer callback */
return 0;
}

PRIVATE int insertUser( MQueue *mq, int proc_nr) {
PRIVATE int insertUser( struct MQueue *mq, int proc_nr) {
return 0;
}


PRIVATE int removeUser( MQueue *mq, int proc_nr ) {
PRIVATE int removeUser( struct MQueue *mq, int proc_nr ) {
return 0;
}

/* This is not supposed to fail */
PRIVATE int setUserProperty( MQueue *mq, int type, int state ) {
PRIVATE int setUserProperty( struct MQueue *mq, int type, int state ) {

MQUser *user = mq->userHead;
struct MQUser *user = mq->userHead;
while( user ) {
if( user->proc_nr == who_p ) {
user->type = type;
Expand All @@ -57,7 +57,7 @@ PRIVATE int setUserProperty( MQueue *mq, int type, int state ) {
return MQ_SUCCESS;
}

PRIVATE int insertMessage( MQueue *mq, char *message ) {
PRIVATE int insertMessage( struct MQueue *mq, char *message ) {
if( mq->queueLen == MQ_MAX_MESSAGES )
return (MQ_ERR_MAX_MESSAGES);

Expand All @@ -67,39 +67,48 @@ PRIVATE int insertMessage( MQueue *mq, char *message ) {
return MQ_SUCCESS;
}

PRIVATE int readReciever( MQueue *mq ) {
PRIVATE int readMessage( struct MQueue *mq, char *message ) {
return MQ_SUCCESS;
}

/* Called by readReciever */
PRIVATE int readReciever( struct MQueue *mq ) {
/* if you are the last reciever in the queue
* then delete the element from MsgNode */
return MQ_SUCCESS;
}

/* Called by readReciever */
PRIVATE int removeMessage( MQueue *mq ) {
PRIVATE int removeMessage( struct MQueue *mq ) {

mq->queueLen--;
return MQ_SUCCESS;
}

PRIVATE int removeAllMessages( struct MQueue *mq ) {
return MQ_SUCCESS;
}

PUBLIC int do_minit(message *m)
{
int token = 0;
int i = 0;
int firstFreeQueue = -1;
MsgQue *user_mq;
struct MsgQue *user_mq;

printf("\nCS551 I am inside minit!\n");

/* Read token and MsgQue */
token = m_in.m1_i1;
sys_datacopy(who_p, (virbytes) m_in.m1_p1, SELF, (virbytes) user_mq, sizeof(MsgQue) );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p1, SELF, (phys_bytes) user_mq, sizeof(struct MsgQue) );

/* Check if already exists MQueue with such token
* If Yes, return MQueue address in MsgQueue->queue
* This happens ussually when reciever comes in
*/
for( i=0; i< MQ_MAX_MSGQUES ; i++) {
if( mQueues_[i].token == i ) {
user_mq->queue = &mQueue_[i];
sys_datacopy(SELF, (virbytes) user_mq, who_p, (virbytes) m_in.m1_p1, sizeof(MsgQue) );
user_mq->queue = &mQueues_[i];
sys_datacopy(SELF, (phys_bytes) user_mq, who_p, (phys_bytes) m_in.m1_p1, sizeof(struct MsgQue) );
return( MQ_SUCCESS );
}
if( mQueues_[i].token = -1 && firstFreeQueue == -1 )
Expand All @@ -111,27 +120,27 @@ PUBLIC int do_minit(message *m)
return ( MQ_ERR_MAX_MSGQUE );

/* This is new request so, give him a new MQueue */
mQueue_[ firstFreeQueue ].token = token;
insertUser( &mQueue_[i], who_p );
mQueues_[ firstFreeQueue ].token = token;
insertUser( &mQueues_[i], who_p );

user_mq->queue = &mQueue_[i];
sys_datacopy(SELF, (virbytes) user_mq, who_p, (virbytes) m_in.m1_p1, sizeof(MsgQue) );
user_mq->queue = &mQueues_[i];
sys_datacopy(SELF, (phys_bytes) user_mq, who_p, (phys_bytes) m_in.m1_p1, sizeof(struct MsgQue) );

return MQ_SUCCESS;
}

PUBLIC int do_msend(message *m)
{
int len;
MsgQue *user_mq;
struct MsgQue *user_mq;
char *message;
MQueue *mq;
struct MQueue *mq;
printf("\nCS551 I am inside msend!\n");

/* Read token and MsgQue */
len = m_in.m1_i1;
sys_datacopy(who_p, (virbytes) m_in.m1_p1, SELF, (virbytes) user_mq, sizeof(MsgQue) );
sys_datacopy(who_p, (virbytes) m_in.m1_p2, SELF, (virbytes) message, len );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p1, SELF, (phys_bytes) user_mq, sizeof(struct MsgQue) );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p2, SELF, (phys_bytes) message, len );

/* Validate that such token/queue exists */
mq = user_mq->queue;
Expand All @@ -146,7 +155,7 @@ PUBLIC int do_msend(message *m)
pause();

/* Add message to mq->MsgNode */
removeSender( mq, who_p );
removeUser( mq, who_p );
setUserProperty( mq, MQ_SENDER, MQ_USER_ACTIVE );
return MQ_SUCCESS;
}
Expand All @@ -156,9 +165,9 @@ PUBLIC int do_msend(message *m)

/* Wake-up Recievers if they are sleeping */
if( mq->userHead ) {
MQUser *user = mq->userHead;
while( user && user->type==MQ_RECIEVER && user->state=MQ_USER_BLOCKED ) {
unpause( user->proc_nr ); /* Wake-up */
struct MQUser *user = mq->userHead;
while( user && user->type==MQ_RECIEVER && user->state==MQ_USER_BLOCKED ) {
/*unpause( user->proc_nr ); /* Wake-up */
user = user->next;
}
}
Expand All @@ -169,22 +178,22 @@ PUBLIC int do_msend(message *m)
PUBLIC int do_mrecv(message *m)
{
int len;
MsgQue *user_mq;
struct MsgQue *user_mq;
char *message;
MQueue *mq;
struct MQueue *mq;
printf("\nCS551 I am inside mrecv!\n");

/* Read token and MsgQue */
len = m_in.m1_i1;
sys_datacopy(who_p, (virbytes) m_in.m1_p1, SELF, (virbytes) user_mq, sizeof(MsgQue) );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p1, SELF, (phys_bytes) user_mq, sizeof(struct MsgQue) );

/* Validate that such token/queue exists */
mq = user_mq->queue;
if( INVALID_MQ( mq, user_mq->token ))
return ( ERR_INVALID_MQ );

/* Block if MQueue is EMPTY */
if( mq->MsgNode == NULL ) {
if( mq->msgHead == NULL ) {
setUserProperty( mq, MQ_RECIEVER, MQ_USER_BLOCKED );

/* Block Reciever */
Expand All @@ -197,10 +206,10 @@ PUBLIC int do_mrecv(message *m)
readMessage( mq, message );

/* Wake-up Sender if they are sleeping */
if( mq->shead ) {
MQUser *user = mq->userHead;
while( user && user->type==MQ_SENDER && user->state=MQ_USER_BLOCKED ) {
unpause( user->proc_nr ); /* Wake-up */
if( mq->userHead ) {
struct MQUser *user = mq->userHead;
while( user && user->type==MQ_SENDER && user->state==MQ_USER_BLOCKED ) {
/*unpause( user->proc_nr ); /* Wake-up */
user = user->next;
}
}
Expand All @@ -210,25 +219,26 @@ PUBLIC int do_mrecv(message *m)

PUBLIC int do_mclose(message *m)
{
MsgQue *user_mq;
MQueue *mq;
int token;
struct MsgQue *user_mq;
struct MQueue *mq;
printf("\nCS551 I am inside mclose!\n");

/* Read MsgQue */
token = m_in.m1_i1;
sys_datacopy(who_p, (virbytes) m_in.m1_p1, SELF, (virbytes) user_mq, sizeof(MsgQue) );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p1, SELF, (phys_bytes) user_mq, sizeof(struct MsgQue) );

/* Validate that such token/queue exists */
mq = user_mq->queue;

if( INVALID_MQ( mq, user_mq->token ) || mq.userHead == NULL )
if( INVALID_MQ( mq, user_mq->token ) || mq->userHead == NULL )
return ( ERR_INVALID_MQ );

/* Remove element from userHead */
removeUser( mq, who_p );
if( mq.userHead == NULL ) { /* free the Message Queue */
mq.token = MQ_FREE;
mq.queueLen = 0;
if( mq->userHead == NULL ) { /* free the Message Queue */
mq->token = MQ_FREE;
mq->queueLen = 0;
removeAllMessages( mq );
}

Expand All @@ -237,20 +247,20 @@ PUBLIC int do_mclose(message *m)

PUBLIC int do_mclean(message *m)
{
MsgQue *user_mq;
int rc;
MQueue *mq;
MQUser *user;
struct MsgQue *user_mq;
int token,rc;
struct MQueue *mq;
struct MQUser *user;

printf("\nCS551 I am inside mclean!\n");

/* Read MsgQue */
token = m_in.m1_i1;
sys_datacopy(who_p, (virbytes) m_in.m1_p1, SELF, (virbytes) user_mq, sizeof(MsgQue) );
sys_datacopy(who_p, (phys_bytes) m_in.m1_p1, SELF, (phys_bytes) user_mq, sizeof(struct MsgQue) );

/* Validate that such token/queue exists */
mq = user_mq->queue;
if( INVALID_MQ( mq, user_mq->token ) || mq.userHead == NULL )
if( INVALID_MQ( mq, user_mq->token ) || mq->userHead == NULL )
return ( ERR_INVALID_MQ );

/* Ping every one and see if they are all alive */
Expand All @@ -267,8 +277,8 @@ PUBLIC int do_mclean(message *m)
return( ERR_MQ_INUSE );

/* Free the MQueue */
mq.token = MQ_FREE;
mq.queueLen = 0;
mq->token = MQ_FREE;
mq->queueLen = 0;
removeAllMessages( mq );

return MQ_SUCCESS;
Expand Down
16 changes: 8 additions & 8 deletions servers_pm/msgque.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
/* This structure hold all MQ users who are registered
*
*/
typedef struct MQUser_t{ /* Dynamically allocated */
struct MQUser { /* Dynamically allocated */
int messageNo; /* This is the last message recieve used */
int proc_nr; /* Receiver's process number */
int state; /* Blocked or Active */
int type; /* Sender or reciever = has meaning only with 'state' */
struct MQUser_t *next; /* If many are waiting to read message */
} MQUser;
struct MQUser *next; /* If many are waiting to read message */
};

/*
* Linked list maintaining all the message posted by msend
Expand All @@ -34,13 +34,13 @@ struct MsgNode {
struct MsgNode *next;
};

typedef struct {
struct MQueue{
int token; /* Unique identifier for this message queue,
* user gives this */
int queueLen;
struct MsgNode *msgHead;
MQUser *userHead;
} MQueue;
#define INVALID_MQ( mq, tok ) (mq < mQueue[0] || mq > mQueue[MQ_MAX_MSGQUES] || mq->token != tok )
struct MQUser *userHead;
} ;
#define INVALID_MQ( mq, tok ) (mq < &mQueues_[0] || mq > &mQueues_[MQ_MAX_MSGQUES] || mq->token != tok )



10 changes: 5 additions & 5 deletions servers_pm/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ struct memory;
#include <timers.h>

/* project 2: multicast */
_PROTOTYPE( int do_minit, (void));
_PROTOTYPE( int do_msend, (void));
_PROTOTYPE( int do_mrecv, (void));
_PROTOTYPE( int do_mclose, (void));
_PROTOTYPE( int do_mclean, (void));
_PROTOTYPE( int do_minit, (message *m));
_PROTOTYPE( int do_msend, (message *m));
_PROTOTYPE( int do_mrecv, (message *m));
_PROTOTYPE( int do_mclose, (message *m));
_PROTOTYPE( int do_mclean, (message *m));

/* alarm.c */
_PROTOTYPE( int do_alarm, (void) );
Expand Down
10 changes: 5 additions & 5 deletions servers_pm/table.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ _PROTOTYPE (int (*call_vec[]), (void) ) = {
do_getdma, /* 110 = getdma */
do_srv_kill, /* 111 = srv_kill */
no_sys, /* 112 = gcov_flush */
do_minit, /* 113 */
do_mrecv, /* 114 */
do_msend, /* 115 */
do_mclose, /* 116 */
do_mclean, /* 117 */
do_minit, /* 113 = minit */
do_mrecv, /* 114 = mrecv */
do_msend, /* 115 = msend */
do_mclose, /* 116 = mclose */
do_mclean /* 117 = mclean */
};
/* This should not fail with "array size is negative": */
extern int dummy[sizeof(call_vec) == NCALLS * sizeof(call_vec[0]) ? 1 : -1];
Loading

0 comments on commit a9ed371

Please sign in to comment.