15d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/* 25d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Copyright (C) 2010 NXP Semiconductors 35d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 45d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Licensed under the Apache License, Version 2.0 (the "License"); 55d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * you may not use this file except in compliance with the License. 65d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * You may obtain a copy of the License at 75d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 85d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * http://www.apache.org/licenses/LICENSE-2.0 95d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Unless required by applicable law or agreed to in writing, software 115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * distributed under the License is distributed on an "AS IS" BASIS, 125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * See the License for the specific language governing permissions and 145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * limitations under the License. 155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \file phDalNfc_messageQueueLib.c 195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL independant message queue implementation for android (can be used under linux too) 205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Project: Trusted NFC Linux Lignt 225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Date: 13 aug 2009 245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Author: Jonathan roux 255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * $Revision: 1.0 $ 265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <pthread.h> 305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#ifdef ANDROID 315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <linux/ipc.h> 325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#else 335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <sys/msg.h> 345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#endif 355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <semaphore.h> 375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc.h> 395d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phOsalNfc.h> 405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_DeferredCall.h> 415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly#include <phDal4Nfc_messageQueueLib.h> 425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef struct phDal4Nfc_message_queue_item 445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phLibNfc_Message_t nMsg; 465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly struct phDal4Nfc_message_queue_item * pPrev; 475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly struct phDal4Nfc_message_queue_item * pNext; 485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} phDal4Nfc_message_queue_item_t; 495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pellytypedef struct phDal4Nfc_message_queue 525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_item_t * pItems; 545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_t nCriticalSectionMutex; 555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sem_t nProcessSemaphore; 565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} phDal4Nfc_message_queue_t; 585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL message get function 645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function allocates the message queue. The parameters are ignored, this is 655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * just to keep the same api as Linux queue. 665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval -1 Can not allocate memory or can not init mutex. 685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly* \retval handle The handle on the message queue. 695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 70a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Crossintptr_t phDal4Nfc_msgget ( key_t key, int msgflg ) 715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_t * pQueue; 735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue = (phDal4Nfc_message_queue_t *) phOsalNfc_GetMemory(sizeof(phDal4Nfc_message_queue_t)); 745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pQueue == NULL) 755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset(pQueue, 0, sizeof(phDal4Nfc_message_queue_t)); 775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pthread_mutex_init (&pQueue->nCriticalSectionMutex, NULL) == -1) 785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (sem_init (&pQueue->nProcessSemaphore, 0, 0) == -1) 805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 81a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Cross return ((intptr_t)pQueue); 825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL message control function 885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * This function destroys the message queue. The cmd and buf parameters are ignored, 895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * this is just to keep the same api as Linux queue. 905d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msqid The handle of the message queue. 925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval 0 If success. 945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval -1 Bad passed parameter 955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 96a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Crossint phDal4Nfc_msgctl ( intptr_t msqid, int cmd, void *buf ) 975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_t * pQueue; 995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_item_t * p; 1005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (msqid == 0) 1025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 1035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue = (phDal4Nfc_message_queue_t *)msqid; 1055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_lock(&pQueue->nCriticalSectionMutex); 1065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pQueue->pItems != NULL) 1075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p = pQueue->pItems; 1095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(p->pNext != NULL) { p = p->pNext; } 1105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(p->pPrev != NULL) 1115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p = p->pPrev; 1135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(p->pNext); 1145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p->pNext = NULL; 1155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(p); 1175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue->pItems = NULL; 1195d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_unlock(&pQueue->nCriticalSectionMutex); 1205d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_destroy(&pQueue->nCriticalSectionMutex); 1215d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(pQueue); 1225d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return 0; 1235d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 1245d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1255d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 1265d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 1275d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1285d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL message send function 1295d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * Use this function to send a message to the queue. The message will be added at the end of 1305d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * the queue with respect to FIFO policy. The msgflg parameter is ignored. 1315d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1325d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msqid The handle of the message queue. 1335d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msgp The message to send. 1345d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msgsz The message size. 1355d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1365d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval 0 If success. 1375d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval -1 Bad passed parameter, or can not allocate memory 1385d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 139a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Crossint phDal4Nfc_msgsnd (intptr_t msqid, void * msgp, size_t msgsz, int msgflg) 1405d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 1415d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_t * pQueue; 1425d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_item_t * p; 1435d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_item_t * pNew; 1445d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1455d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((msqid == 0) || (msgp == NULL) || (msgsz == 0)) 1465d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 1475d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1485d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (msgsz != sizeof(phLibNfc_Message_t)) 1495d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 1505d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1515d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue = (phDal4Nfc_message_queue_t *)msqid; 1525d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pNew = (phDal4Nfc_message_queue_item_t *)phOsalNfc_GetMemory(sizeof(phDal4Nfc_message_queue_item_t)); 1535d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pNew == NULL) 1545d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 1555d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memset(pNew, 0, sizeof(phDal4Nfc_message_queue_item_t)); 1565d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(&pNew->nMsg, &((phDal4Nfc_Message_Wrapper_t*)msgp)->msg, sizeof(phLibNfc_Message_t)); 1575d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_lock(&pQueue->nCriticalSectionMutex); 1585d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pQueue->pItems != NULL) 1595d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1605d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p = pQueue->pItems; 1615d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly while(p->pNext != NULL) { p = p->pNext; } 1625d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p->pNext = pNew; 1635d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pNew->pPrev = p; 1645d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1655d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly else 1665d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 1675d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue->pItems = pNew; 1685d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 1695d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_unlock(&pQueue->nCriticalSectionMutex); 1705d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1715d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sem_post(&pQueue->nProcessSemaphore); 1725d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return 0; 1735d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 1745d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1755d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly/** 1765d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \ingroup grp_nfc_dal 1775d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1785d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \brief DAL message receive function 1795d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The call to this function will get the older message from the queue. If the queue is empty the function waits 1805d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * (blocks on a mutex) until a message is posted to the queue with phDal4Nfc_msgsnd. 1815d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * The msgtyp and msgflg parameters are ignored. 1825d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1835d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msqid The handle of the message queue. 1845d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[out] msgp The received message. 1855d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \param[in] msgsz The message size. 1865d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * 1875d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval 0 If success. 1885d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly * \retval -1 Bad passed parameter. 1895d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly */ 190a5282496f1c25f5c8cfefd3b8bc4220ee2192881Colin Crossint phDal4Nfc_msgrcv (intptr_t msqid, void * msgp, size_t msgsz, long msgtyp, int msgflg) 1915d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly{ 1925d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_t * pQueue; 1935d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phDal4Nfc_message_queue_item_t * p; 1945d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1955d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if ((msqid == 0) || (msgp == NULL)) 1965d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 1975d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 1985d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (msgsz != sizeof(phLibNfc_Message_t)) 1995d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return -1; 2005d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2015d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue = (phDal4Nfc_message_queue_t *)msqid; 2025d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly sem_wait(&pQueue->nProcessSemaphore); 2035d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_lock(&pQueue->nCriticalSectionMutex); 2045d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly if (pQueue->pItems != NULL) 2055d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly { 2065d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly memcpy(&((phDal4Nfc_Message_Wrapper_t*)msgp)->msg, &(pQueue->pItems)->nMsg, sizeof(phLibNfc_Message_t)); 2075d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly p = pQueue->pItems->pNext; 2085d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly phOsalNfc_FreeMemory(pQueue->pItems); 2095d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pQueue->pItems = p; 2105d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly } 2115d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly pthread_mutex_unlock(&pQueue->nCriticalSectionMutex); 2125d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly return 0; 2135d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly} 2145d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2155d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2165d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2175d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 2185d9927ba30ba449badb9f6df0fbeb4d6aedc6e2aNick Pelly 219