Skip to content

Commit

Permalink
multiple queue fix and other minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akailash committed Oct 26, 2011
1 parent 924790e commit cbe6681
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 45 deletions.
2 changes: 0 additions & 2 deletions include/minix/libmsgque.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ struct MsgQue {
#define MQ_SUCCESS 0
#define MQ_FAILED -1
#define MQ_ERR_MAX_MSGQUE -2
#define MQ_ERR_MAX_MESSAGES -3
#define MQ_ERR_MAX_RECIEVERS -4
#define ERR_INVALID_MQ -5
#define ERR_MQ_INUSE -6
#define ERR_INVALID_ARG -8
Expand Down
75 changes: 41 additions & 34 deletions servers_pm/msgque.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,38 +101,6 @@ PRIVATE int insertUser( struct MQueue *mq, int proc_nr) {
return MQ_SUCCESS;
}

/* Any user calling mclose() will do below */
PRIVATE void removeUser( struct MQueue *mq, int proc_nr ) {
struct MQUser *tmp;
struct MQUser *prev = NULL;

if(mq==NULL)
return;

tmp = mq->userHead;
printf("\nCS551 DBG: removeUser");

while( tmp ) {
if( tmp->proc_nr == proc_nr )
{
if( prev == NULL )
mq->userHead = tmp->next;
else
prev->next = tmp->next;
free( tmp );

if( mq->userHead == NULL ) {
truncateQueue( mq );
mq->token = MQ_FREE;
mq->queueLen = 0;
}
return;
}
prev = tmp;
tmp = tmp->next;
}
}

/* First args NULL, causes search in all Q */
PRIVATE struct MQUser* getUserPtr( struct MQueue *mq, int proc_nr ) {
struct MQUser *tmp;
Expand Down Expand Up @@ -292,6 +260,42 @@ PRIVATE int truncateQueue( struct MQueue *mq ) {
return MQ_SUCCESS;
}

/* Any user calling mclose() will do below */
PRIVATE void removeUser( struct MQueue *mq, int proc_nr ) {
struct MQUser *tmp;
struct MQUser *prev = NULL;

if(mq==NULL)
return;

tmp = mq->userHead;
printf("\nCS551 DBG: removeUser");

while( tmp ) {
if( tmp->proc_nr == proc_nr )
{
if( prev == NULL )
mq->userHead = tmp->next;
else
prev->next = tmp->next;
free( tmp );

if( mq->userHead == NULL ) {
truncateQueue( mq );
mq->token = MQ_FREE;
mq->queueLen = 0;
mq->msgCounter = 0;
mq->msgHead = NULL;
mq->msgTail = NULL;
mq->userHead = NULL;
}
return;
}
prev = tmp;
tmp = tmp->next;
}
}


/* Called by mrecv() when message already present in Queue
* Called by msend() when unblocking reciever
Expand Down Expand Up @@ -397,7 +401,7 @@ PUBLIC int do_minit(void)
return( MQ_SUCCESS );

}
if( mQueues_[i].token = MQ_FREE && firstFreeQueue == MQ_FREE )
if( mQueues_[i].token == MQ_FREE && firstFreeQueue == MQ_FREE )
firstFreeQueue = i;
}

Expand Down Expand Up @@ -634,7 +638,10 @@ PUBLIC int do_mclean(void)
truncateQueue( mq );
mq->token = MQ_FREE;
mq->queueLen = 0;

mq->msgCounter = 0;
mq->msgHead = NULL;
mq->msgTail = NULL;
mq->userHead = NULL;
return MQ_SUCCESS;
}

4 changes: 2 additions & 2 deletions servers_pm/msgque_const.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
*/

#define MQ_MAX_MSGQUES 128
#define MQ_MAX_MESSAGES 512
#define MQ_MAX_MSGQUES 5
#define MQ_MAX_MESSAGES 50
#define MQ_MAX_BYTES_IN_MSG 256 /* Single msg que can hold 512 * 256 bytes */
#define MQ_CLEANUP_TIMER 1500 /* number of ticks after which cleanup is to be run */

Expand Down
17 changes: 10 additions & 7 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,16 @@ int main(int argc, char *argv[], char *envp[])
}

minit(key, &msgque);

printf("Process[%d] registered to queue[%d,0x%x]\n", getpid(), msgque.token, msgque.queue);
if (sleep_time>0)
sleep(sleep_time);

while(repeat>0)
{
if((proc_num<1)||(proc_num>2))
{
printf("\nEnter choice[1-recv, 2-send]");
scanf("%d",choice);
scanf("%d",&choice);
}
else
{
Expand All @@ -64,17 +67,17 @@ int main(int argc, char *argv[], char *envp[])
if(choice==1){
rc = mrecv(&msgque, msg, 50);
if ( rc != MQ_SUCCESS)
printf("%d:Error while receiving\n",rc);
printf("Process[%d] %d:Error while receiving\n",getpid(), rc);
else
printf("Recved:%d %s\n",rc, msg);
printf("Process[%d] Recved:%d %s\n", getpid(), rc, msg);
} else if(choice==2)
{
sprintf(msg,"Process[%d] MsgNo %d", getpid(), msg_num++);
rc = msend(&msgque, msg, 50);
if (rc != MQ_SUCCESS)
printf("Sender: %d Error while sending\n",rc);
printf("Process[%d] Sender: %d Error while sending\n", getpid(), rc);
else
printf("Sender got:%d\n",rc);
printf("Process[%d] Sender got:%d\n",getpid(), rc);
}
repeat--;
mclean(&msgque);
Expand All @@ -84,4 +87,4 @@ int main(int argc, char *argv[], char *envp[])
mclose(&msgque);

return 0;
}
}

0 comments on commit cbe6681

Please sign in to comment.