示例#1
0
int msg_create_Q (const char *name, int maxmsg, int size)
{
	int  qid = get_qid ();

	if (qid < 0)  {
		return -1;
	}

	Queue[qid].mpool_id = mem_pool_create (name, maxmsg * sizeof (struct msg) , 
                                               sizeof(struct msg), 0);

	if (Queue[qid].mpool_id < 0) {
		printf ("Mem Pool Creation failed ..\n");
		return -1;
	}

	memcpy (Queue[qid].name, name, MAX_Q_NAME);
	Queue[qid].max_msg = maxmsg;
	Queue[qid].size = size;
	Queue[qid].flags = MQ_ACTIVE;

	EventInit (&Queue[qid].q_evt);

	return qid;
}
示例#2
0
int msg_create_Q (char *name, int maxmsg, int size)
{
#ifdef SFS_WANTED
	mqd_t qid = -1;
        struct mq_attr attr;
#define  MAX_MQ_NAME 12
	char mq_name[MAX_MQ_NAME];
	
	memset (mq_name, 0, MAX_MQ_NAME);
        memset (&attr, 0, sizeof(attr));

	sprintf (mq_name, "/%s",name);

	mq_unlink (mq_name);

        attr.mq_flags = 0;
        attr.mq_maxmsg = maxmsg;
        attr.mq_msgsize = size;

        qid =  tm_mq_open (mq_name, O_RDWR | O_CREAT,
                           S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH , &attr);

        if (qid == (mqd_t)-1) {
                perror ("mq_open: ");
		return -1;
        }
	return qid;
#else
	int  qid = get_qid ();

	if (qid < 0)  {
		return -1;
	}

	Queue[qid].mpool_id = mem_pool_create (name, maxmsg * sizeof (struct msg) , 
                                               sizeof(struct msg), 0);

	if (Queue[qid].mpool_id < 0) {
		printf ("Mem Pool Creation failed ..\n");
		return -1;
	}

	memcpy (Queue[qid].name, name, MAX_Q_NAME);
	Queue[qid].max_msg = maxmsg;
	Queue[qid].size = size;
	Queue[qid].flags = MQ_ACTIVE;

	pthread_cond_init (&Queue[qid].q_cnd, NULL);
	pthread_mutex_init (&Queue[qid].q_mtx, NULL);

	return qid;

#endif
}