static void taskTwo(void) { char message[] = "Received Message from taskTwo."; char msgBuf[MAX_MESSAGE_LENGTH]; int i; for (i = 0; i < MAX_MESSAGES; i++) { if (msgQReceive(msgQueueId, msgBuf, MAX_MESSAGE_LENGTH, WAIT_FOREVER) == ERROR) { printf("msgQReceive in taskTwo failed.\n"); } else { printf("taskTwo %s\n",msgBuf); } if (msgQSend(msgQueueIdNew, message, MAX_MESSAGE_LENGTH, WAIT_FOREVER, MSG_PRI_NORMAL) == ERROR) { printf("msgQsend in taskTwo failed.\n"); } else { printf("taskTwo sent a message.\n"); } } msgQDelete(msgQueueId); }
//------------------------------------------------------------------------------ tOplkError timeru_delInstance(void) { ULONG msg; tTimeruData* pTimer; /* send message to timer task to signal shutdown */ msg = 0; msgQSend(timeruInstance_l.msgQueue, (char*)&msg, sizeof(ULONG), NO_WAIT, MSG_PRI_NORMAL); /* wait for timer task to end */ while (taskIdVerify(timeruInstance_l.taskId) == OK) taskDelay(sysClkRateGet()); /* free up timer list */ resetTimerList(); while ((pTimer = getNextTimer()) != NULL) { hrtimer_delete (pTimer->timer); removeTimer(pTimer); OPLK_FREE(pTimer); } /* cleanup resources */ semDelete(timeruInstance_l.mutex); msgQDelete(timeruInstance_l.msgQueue); timeruInstance_l.pFirstTimer = NULL; timeruInstance_l.pLastTimer = NULL; return kErrorOk; }
/** * @brief Détruire les ressources systèmes. * @return OK en cas de succès, ERROR sinon. */ int pe_cleanup_resources() { int errtest = 0; // Destruction des ressources. if(semDelete(mut_table_capt)) { printf("Erreur : Problème de destruction du sémaphore pour table_capt.\n"); errtest = 1; } if(semDelete(mut_table_buffer)) { printf("Erreur : Problème de destruction du sémaphore pour table_buffer.\n"); errtest = 1; } if(msgQDelete(msgQ_dispatcher)) { printf("Erreur : mauvais numéro de file de message.\n"); errtest = 1; } if(taskDelete(id_pe_task_dispatcher)) { printf("Erreur : mauvais numéro de tache pour la tache dispatcher.\n"); errtest = 1; } if (errtest) { return ERROR; } return OK; }
/***************************************************************************** ** user system shutdown and resource cleanup *****************************************************************************/ void user_syskill( void ) { STATUS err; while ( getchar() != (int)'q' ) sleep( 1 ); puts( "\r\nDeleting Task 1" ); err = taskDelete( task1_id ); puts( "\r\nDeleting Task 2" ); err = taskDelete( task2_id ); puts( "\r\nDeleting Task 3" ); err = taskDelete( task3_id ); printf( "\r\nDeleting Semaphore SEM3" ); errno = 0; err = semDelete( sema43_id ); if ( err == ERROR ) printf( "... returned error %x\r\n", errno ); printf( "\r\nDeleting Semaphore SEM2" ); errno = 0; err = semDelete( sema42_id ); if ( err == ERROR ) printf( "... returned error %x\r\n", errno ); printf( "\r\nDeleting Queue QUEUE3" ); errno = 0; err = msgQDelete( queue3_id ); if ( err == ERROR ) printf( "... returned error %x\r\n", errno ); else printf( "\r\n" ); printf( "\r\nDeleting Queue QUEUE2" ); errno = 0; err = msgQDelete( queue2_id ); if ( err == ERROR ) printf( "... returned error %x\r\n", errno ); else printf( "\r\n" ); printf( "\r\n" ); }
MSG_Q_ID msgQCreate(int nb_msgs, int length, int flags) { static unsigned long msgq_ids; wind_msgq_t *queue; xnflags_t bflags = 0; int i, msg_size; char *msgs_mem; spl_t s; check_NOT_ISR_CALLABLE(return 0); error_check(nb_msgs <= 0, S_msgQLib_INVALID_QUEUE_TYPE, return 0); error_check(flags & ~WIND_MSG_Q_OPTION_MASK, S_msgQLib_INVALID_QUEUE_TYPE, return 0); error_check(length < 0, S_msgQLib_INVALID_MSG_LENGTH, return 0); msgs_mem = xnmalloc(sizeof(wind_msgq_t) + nb_msgs * (sizeof(wind_msg_t) + length)); error_check(msgs_mem == NULL, S_memLib_NOT_ENOUGH_MEMORY, return 0); queue = (wind_msgq_t *)msgs_mem; msgs_mem += sizeof(wind_msgq_t); queue->magic = WIND_MSGQ_MAGIC; queue->msg_length = length; queue->free_list = NULL; initq(&queue->msgq); inith(&queue->rlink); queue->rqueue = &wind_get_rholder()->msgQq; /* init of the synch object : */ if (flags & MSG_Q_PRIORITY) bflags |= XNSYNCH_PRIO; xnsynch_init(&queue->synchbase, bflags, NULL); msg_size = sizeof(wind_msg_t) + length; for (i = 0; i < nb_msgs; ++i, msgs_mem += msg_size) free_msg(queue, (wind_msg_t *)msgs_mem); xnlock_get_irqsave(&nklock, s); appendq(queue->rqueue, &queue->rlink); xnlock_put_irqrestore(&nklock, s); sprintf(queue->name, "mq%lu", msgq_ids++); if (xnregistry_enter(queue->name, queue, &queue->handle, &msgq_pnode)) { wind_errnoset(S_objLib_OBJ_ID_ERROR); msgQDelete((MSG_Q_ID)queue); return 0; } return (MSG_Q_ID)queue; }
/* * Admin functions API: install of driver and then of devices. * uninstall of devices and then of driver * direct driver uninstall is also supported */ int drvInstall() { if (semMAdmin==0) {//The semaphore hasn't been created yet : the driver has not been installed yet, //let's do it semMAdmin = semMCreate(SEM_Q_FIFO); if(semMAdmin==0) { errnoSet(SEM_ERR); return -1; } } else { errnoSet(ALREADY_INSTALLED); return -1; } isrmq = msgQCreate(10,4,0); //Create a msg queue with 10 msg max, //4 byte per msg max, and msgs filled up in fifo order if (isrmq == NULL) { errnoSet(MSGQ_ERR); return -1; } tMsgDispatchID = taskSpawn("tMsgDispatch",0,0,1000,msgDispatch,(int)semMAdmin,0,0,0,0,0,0,0,0,0); //This task will dispatch a msg received by the isr and sleep the rest of the time. //It needs to be fast to prevent isr msg queue to fill up, hence the high priority //It's also nice for tests if his priority is superior than the shell's one, which //is set to 1 if (tMsgDispatchID==-1) { msgQDelete(isrmq); errnoSet(TASK_ERR); return -1; } numPilote=iosDrvInstall(0,0,devOpen,devClose,devRead,0,0); //Register device in ios if (numPilote == -1) { msgQDelete(isrmq); taskDelete(tMsgDispatchID); errnoSet(INSTALL_ERR); return -1; } return 0; }
cleanAupdt() { int tid; if (pMsgesToAupdt != NULL) { msgQDelete(pMsgesToAupdt); pMsgesToAupdt = NULL; } tid = taskNameToId("tAupdt"); if (tid != ERROR) taskDelete(tid); }
UGL_STATUS uglOSMsgQDelete ( UGL_OS_MSG_Q_ID qId ) { UGL_STATUS status; if (msgQDelete(qId) != OK) { status = UGL_STATUS_ERROR; } else { status = UGL_STATUS_OK; } return status; }
static int __wind_msgq_delete(struct task_struct *curr, struct pt_regs *regs) { xnhandle_t handle = __xn_reg_arg1(regs); wind_msgq_t *msgq; msgq = (wind_msgq_t *)xnregistry_fetch(handle); if (!msgq) return S_objLib_OBJ_ID_ERROR; if (msgQDelete((MSG_Q_ID)msgq) == ERROR) return wind_errnoget(); return 0; }
int arretConditionnement() { wdDelete(wdReparation); taskDelete(tidTraitementPalette); taskDelete(tidTraitementCarton); msgQDelete(fileConvoyage); semDelete(semClapet); semDelete(semCompteurPalette); semDelete(semEtatEmb); semDelete(semCapteurPalette); semDelete(semEtatImp); semDelete(semCapteurCarton); return OK; }
/* * ===================================================================== * Function:MsgQDelete() * Description: delete a message queue * Input: mqname -- name of new message queue, just for Linux * In Linux, the queue is identified by name. * msgQId -- msgQ id * Output: N/A * Return: OK on success or ERROR otherwise. *====================================================================== */ int MsgQDelete(const char* mqname, MSG_QUEUE_ID msgQId) { #ifdef LINUX_OS if (mqname == AII_NULL || msgQId == AII_NULL) { return (-1); } free(msgQId); msgQId = AII_NULL; return Mq_unlink(mqname); #elif VXWORKS_OS if (msgQId == AII_NULL) { return (-1); } return msgQDelete(msgQId); #endif }
static void peerTask(long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7, long a8, long a9) { int ret, msg; traceobj_enter(&trobj); traceobj_mark(&trobj, 8); ret = msgQReceive(qid, (char *)&msg, sizeof(int), WAIT_FOREVER); traceobj_assert(&trobj, ret == sizeof(int) && msg == 0); traceobj_mark(&trobj, 9); ret = msgQDelete(qid); traceobj_assert(&trobj, ret == OK); traceobj_mark(&trobj, 10); traceobj_exit(&trobj); }
/*|><|************************************************************************ * * Method Name: TerminateProcessing * * * Inputs: None * * Outputs: None * * Returns: bool * * Logic Notes: * * Caveats: * ************************************************************************|<>|*/ void CMsgQueue::TerminateProcessing(unsigned long dwMode) { #ifdef WIN32 /* [ */ // Check Whether Messaging has been terminated. If the Message event is still // valid, then it hasn't. In this case, we will terminate messaging ourselves. if(m_hMessageEvent) TerminateMessaging(dwMode); // Now let's wait for the Thread to notify us that its has terminated WaitForSingleObject (m_hTerminateEvent, INFINITE); // Close the Terminate Event Handle CloseHandle(m_hTerminateEvent); // Clear Terminate Event Handle m_hTerminateEvent = NULL; #elif defined(_VXWORKS) /* ] [ */ // Check whether the Message Queue was successfully created. if(m_ulMsgQID) { // Remove all message which may be left on the message list FlushMessages(); // Delete the Message Queue msgQDelete(m_ulMsgQID); m_ulMsgQID = NULL; } #elif defined(__pingtel_on_posix__) /* ] [ */ if(m_pMsgQ) delete m_pMsgQ; m_pMsgQ = NULL; #endif /* ] */ return; }
int drvRemove() { myDev * i = first; myDev * drv; if (semMAdmin == 0) { errnoSet(NOT_INSTALLED); return -1; } if (semTake(semMAdmin,WAIT_FOREVER)==-1) { errnoSet(SEM_ERR); return -1; } if (iosDrvRemove(numPilote,1) == -1) //And force closure of open files { errnoSet(REMOVE_ERROR); semGive(semMAdmin); return -1; } taskDelete(tMsgDispatchID); msgQDelete(isrmq); //Delete all devices : while (i!=NULL) { drv = i; i = drv->next; iosDevDelete((DEV_HDR*)drv); semTake(drv->semMData,WAIT_FOREVER); //Let pending ops finish semDelete(drv->semMData); free(drv); } numPilote = -1; first = NULL; semDelete(semMAdmin); semMAdmin=0; return 0; }
int main(int argc, char* argv[]) { HANDLE hReceiver = NULL; unsigned int tReceiver = 0; char c = 0; MSG_Q_ID msgQTest = NULL; int maxMsgs = 3; /* Fix the eclipse CDT output issue */ setbuf(stdout, NULL); setbuf(stderr, NULL); msgQTest = msgQOpen("test"); if(msgQTest == NULL) { msgQTest = msgQCreateEx(maxMsgs, 100, MSG_Q_FIFO, "test"); printf("%s: message queue created.\n", __func__); } else { printf("%s: message queue opened.\n", __func__); } hReceiver = (HANDLE)CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)msgQReceiver, msgQTest, 0, (DWORD*)&tReceiver); while((c = getchar()) != 'q') { msgQShow(msgQTest); } CloseHandle(hReceiver); msgQShow(msgQTest); msgQDelete(msgQTest); return 0; }