/* Close a message queue descriptor. 
See IEEE 1003.1  */
int mq_close(mqd_t mqdes)
/* Close a message queue descriptor. 
See IEEE 1003.1  */
int mq_close(mqd_t mqdes)
{
	mqueue_desc *mqd = (mqueue_desc *)mqdes;
	if (mqd == NULL) {
		errno = EBADF;
		return -1;
	}
	atomic_dec(&mqd->mqueue->ref_count);
	if (mqd->mqueue->name == NULL) {
		remove_mq(mqd->mqueue);
	}
	k_free(mqd->mem_desc);
	return 0;
}