Queue.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:28k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*******************************************************************************
  36.  * Filename:
  37.  * ---------
  38.  *  Queue.c
  39.  *
  40.  * Project:
  41.  * --------
  42.  *  MAUI
  43.  *
  44.  * Description:
  45.  * ------------
  46.  *  
  47.  *
  48.  * Author:
  49.  * -------
  50.  *  
  51.  *
  52.  *==============================================================================
  53.  *             HISTORY
  54.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  55.  *------------------------------------------------------------------------------
  56.  * removed!
  57.  *
  58.  * removed!
  59.  * removed!
  60.  * removed!
  61.  *
  62.  * removed!
  63.  * removed!
  64.  * removed!
  65.  *
  66.  * removed!
  67.  * removed!
  68.  * removed!
  69.  *
  70.  * removed!
  71.  * removed!
  72.  * removed!
  73.  *
  74.  * removed!
  75.  * removed!
  76.  * removed!
  77.  *
  78.  * removed!
  79.  * removed!
  80.  * removed!
  81.  *
  82.  * removed!
  83.  * removed!
  84.  * removed!
  85.  *
  86.  * removed!
  87.  * removed!
  88.  * removed!
  89.  *
  90.  * removed!
  91.  * removed!
  92.  * removed!
  93.  *
  94.  * removed!
  95.  * removed!
  96.  * removed!
  97.  *
  98.  * removed!
  99.  * removed!
  100.  * removed!
  101.  *
  102.  * removed!
  103.  * removed!
  104.  * removed!
  105.  *
  106.  * removed!
  107.  * removed!
  108.  * removed!
  109.  *
  110.  * removed!
  111.  * removed!
  112.  * removed!
  113.  *
  114.  * removed!
  115.  * removed!
  116.  * removed!
  117.  *
  118.  * removed!
  119.  * removed!
  120.  * removed!
  121.  *
  122.  * removed!
  123.  * removed!
  124.  * removed!
  125.  *
  126.  * removed!
  127.  * removed!
  128.  * removed!
  129.  *
  130.  *------------------------------------------------------------------------------
  131.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
  132.  *==============================================================================
  133.  *******************************************************************************/
  134. /**
  135.  * Copyright Notice
  136.  * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
  137.  * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
  138.  *  (It is illegal to remove this copyright notice from this software or any
  139.  *  portion of it)
  140.  */
  141. /**************************************************************
  142.    FILENAME : Queue.c
  143.    PURPOSE     : Task queue implementation functions 
  144.    REMARKS     : nil
  145.    AUTHOR      : Neeraj Sharma
  146.    DATE     : Dec' 28, 2002
  147. **************************************************************/
  148. // #define __NEWSIMULATOR
  149. #include "MMI_features.h"
  150. #include "stdc.h"
  151. // #include "L4Dr1.h"
  152. #include "OslMemory.h"
  153. #include "pixteldatatypes.h"
  154. #include "QueueGprot.h"
  155. #include "DebugInitDef.h"
  156. //#undef __NEWSIMULATOR 
  157. //#include "l4dr.h"
  158. //#include "MMI_trc.h"
  159. #ifndef __MTK_TARGET__
  160. #define __align(x)
  161. #endif 
  162. void *lastMemory;
  163. TSIZE *lastSize;
  164. MYQUEUE *qPtr;
  165. /*****************************************************************************
  166.  * FUNCTION
  167.  *  OslIntCreateMsgQ
  168.  * DESCRIPTION
  169.  *  Creates Message Queue
  170.  * PARAMETERS
  171.  *  queue_name          [IN]        
  172.  *  max_msg_size        [IN]        
  173.  *  max_msgs            [IN]        
  174.  * RETURNS
  175.  *  void
  176.  *****************************************************************************/
  177. oslMsgqid OslIntCreateMsgQ(PS8 queue_name, U32 max_msg_size, U32 max_msgs)
  178. {
  179. #ifdef MMI_ON_WIN32
  180.     /*----------------------------------------------------------------*/
  181.     /* Local Variables                                                */
  182.     /*----------------------------------------------------------------*/
  183.     win32_msgqid *msgqid;
  184.     /*----------------------------------------------------------------*/
  185.     /* Code Body                                                      */
  186.     /*----------------------------------------------------------------*/
  187.     msgqid = (win32_msgqid*) OslMalloc(sizeof(win32_msgqid));
  188.     strcpy(msgqid->q_name, queue_name);
  189.     msgqid->q_max_message_size = max_msg_size;
  190.     msgqid->q_max_messages = max_msgs;
  191.     msgqid->q_messages = 0;
  192.     msgqid->q_queue_size = msgqid->q_max_message_size * msgqid->q_max_messages;
  193.     msgqid->q_semaphore_read = CreateSemaphore(NULL, 0, 1000, NULL);
  194.     msgqid->q_semaphore_write = CreateSemaphore(NULL, 0, 1000, NULL);
  195.     msgqid->q_start = (PU32) OslMalloc(msgqid->q_queue_size);
  196.     msgqid->q_message_size = (PU32) OslMalloc(msgqid->q_max_messages * 4);
  197.     msgqid->q_read = 0;
  198.     msgqid->q_write = 0;
  199.     msgqid->q_tasks_waiting_read = 0;
  200.     msgqid->q_tasks_waiting_write = 0;
  201.     InitializeCriticalSection(&msgqid->q_cs);
  202.     return msgqid;
  203. #else /* MMI_ON_WIN32 */ 
  204.     return NULL;
  205. #endif /* MMI_ON_WIN32 */ 
  206. }
  207. /*****************************************************************************
  208.  * FUNCTION
  209.  *  OslIntDeleteMsgQ
  210.  * DESCRIPTION
  211.  *  Deletes Message Queue
  212.  * PARAMETERS
  213.  *  msgqid      [IN]        
  214.  * RETURNS
  215.  *  void
  216.  *****************************************************************************/
  217. void OslIntDeleteMsgQ(oslMsgqid msgqid)
  218. {
  219. #ifdef MMI_ON_WIN32
  220.     /*----------------------------------------------------------------*/
  221.     /* Local Variables                                                */
  222.     /*----------------------------------------------------------------*/
  223.     /*----------------------------------------------------------------*/
  224.     /* Code Body                                                      */
  225.     /*----------------------------------------------------------------*/
  226.     DeleteCriticalSection(&msgqid->q_cs);
  227.     CloseHandle(msgqid->q_semaphore_read);
  228.     CloseHandle(msgqid->q_semaphore_write);
  229.     OslMfree(msgqid->q_start);
  230.     OslMfree(msgqid->q_message_size);
  231.     OslMfree(msgqid);
  232. #endif /* MMI_ON_WIN32 */ 
  233. }
  234. /*****************************************************************************
  235.  * FUNCTION
  236.  *  OslIntWriteMsgQ
  237.  * DESCRIPTION
  238.  *  Writes to Message Queue
  239.  * PARAMETERS
  240.  *  msgqid          [IN]        
  241.  *  msgPtr          [?]         
  242.  *  msgSize         [IN]        
  243.  *  wait_mode       [IN]        
  244.  * RETURNS
  245.  *  void
  246.  *****************************************************************************/
  247. OSLSTATUS OslIntWriteMsgQ(oslMsgqid msgqid, void *msgPtr, U32 msgSize, OSLWAITMODE wait_mode)
  248. {
  249. #ifdef MMI_ON_WIN32
  250.     /*----------------------------------------------------------------*/
  251.     /* Local Variables                                                */
  252.     /*----------------------------------------------------------------*/
  253.     U32 index;
  254.     PU32 ptr;
  255.     /*----------------------------------------------------------------*/
  256.     /* Code Body                                                      */
  257.     /*----------------------------------------------------------------*/
  258.     EnterCriticalSection(&msgqid->q_cs);
  259.     if (msgSize > msgqid->q_max_message_size)
  260.     {
  261.         LeaveCriticalSection(&msgqid->q_cs);
  262.         return OSL_MESSAGE_TOO_BIG;
  263.     }
  264.     /* Check whether the queue is full) */
  265.     if (msgqid->q_messages == msgqid->q_max_messages)
  266.     {
  267.         if (wait_mode == OSL_INFINITE_WAIT)
  268.         {
  269.             ++msgqid->q_tasks_waiting_write;
  270.             LeaveCriticalSection(&msgqid->q_cs);
  271.             WaitForSingleObject(msgqid->q_semaphore_write, INFINITE);
  272.             EnterCriticalSection(&msgqid->q_cs);
  273.         }
  274.         else
  275.         {
  276.             LeaveCriticalSection(&msgqid->q_cs);
  277.             return OSL_Q_FULL;
  278.         }
  279.     }
  280.     msgqid->q_message_size[msgqid->q_write] = msgSize;
  281.     index = msgqid->q_write * (msgqid->q_max_message_size / 4);
  282.     ptr = msgqid->q_start + index;
  283.     memcpy(ptr, msgPtr, msgSize);
  284.     if (++msgqid->q_write == msgqid->q_max_messages)
  285.     {
  286.         msgqid->q_write = 0;
  287.     }
  288.     ++msgqid->q_messages;
  289.     if (msgqid->q_tasks_waiting_read != 0)
  290.     {
  291.         ReleaseSemaphore(msgqid->q_semaphore_read, 1, NULL);
  292.         msgqid->q_tasks_waiting_read -= 1;
  293.     }
  294.     LeaveCriticalSection(&msgqid->q_cs);
  295. #endif /* MMI_ON_WIN32 */ 
  296.     return OSL_SUCCESS;
  297. }
  298. /*****************************************************************************
  299.  * FUNCTION
  300.  *  OslIntReadMsgQ
  301.  * DESCRIPTION
  302.  *  Reades from Message Queue
  303.  * PARAMETERS
  304.  *  msgqid          [IN]        
  305.  *  msgPtr          [?]         
  306.  *  msgSize         [?]         
  307.  *  wait_mode       [IN]        
  308.  * RETURNS
  309.  *  void
  310.  *****************************************************************************/
  311. OSLSTATUS OslIntReadMsgQ(oslMsgqid msgqid, void *msgPtr, U32 *msgSize, OSLWAITMODE wait_mode)
  312. {
  313. #ifdef MMI_ON_WIN32
  314.     /*----------------------------------------------------------------*/
  315.     /* Local Variables                                                */
  316.     /*----------------------------------------------------------------*/
  317.     /*----------------------------------------------------------------*/
  318.     /* Code Body                                                      */
  319.     /*----------------------------------------------------------------*/
  320.     EnterCriticalSection(&msgqid->q_cs);
  321.     if ((msgqid->q_read == msgqid->q_write) && (msgqid->q_messages == 0))
  322.     {
  323.         if (wait_mode == OSL_INFINITE_WAIT)
  324.         {
  325.             ++msgqid->q_tasks_waiting_read;
  326.             LeaveCriticalSection(&msgqid->q_cs);
  327.             WaitForSingleObject(msgqid->q_semaphore_read, INFINITE);
  328.             EnterCriticalSection(&msgqid->q_cs);
  329.         }
  330.         else
  331.         {
  332.             LeaveCriticalSection(&msgqid->q_cs);
  333.             return OSL_Q_EMPTY;
  334.         }
  335.     }
  336.     *msgSize = msgqid->q_message_size[msgqid->q_read];
  337.     memcpy(msgPtr, msgqid->q_start + (msgqid->q_read * (msgqid->q_max_message_size / 4)), *msgSize);
  338.     if (++msgqid->q_read == msgqid->q_max_messages)
  339.     {
  340.         msgqid->q_read = 0;
  341.     }
  342.     --msgqid->q_messages;
  343.     if (msgqid->q_tasks_waiting_write != 0)
  344.     {
  345.         ReleaseSemaphore(msgqid->q_semaphore_write, 1, NULL);
  346.         --msgqid->q_tasks_waiting_write;
  347.     }
  348.     LeaveCriticalSection(&msgqid->q_cs);
  349. #endif /* MMI_ON_WIN32 */ 
  350.     return OSL_SUCCESS;
  351. }
  352. /*****************************************************************************
  353.  * FUNCTION
  354.  *  OslIntReceiveMsgExtQ
  355.  * DESCRIPTION
  356.  *  Reades from Task External Queue
  357.  * PARAMETERS
  358.  *  msgqid      [IN]        
  359.  *  Message     [?]         
  360.  * RETURNS
  361.  *  void
  362.  *****************************************************************************/
  363. U32 OslIntReceiveMsgExtQ(oslMsgqid msgqid, MYQUEUE *Message)
  364. {
  365.     /*----------------------------------------------------------------*/
  366.     /* Local Variables                                                */
  367.     /*----------------------------------------------------------------*/
  368.     U32 msgSize = 0;
  369.     /*----------------------------------------------------------------*/
  370.     /* Code Body                                                      */
  371.     /*----------------------------------------------------------------*/
  372.     OslIntReadMsgQ(msgqid, Message, &msgSize, OSL_INFINITE_WAIT);
  373.     return msgSize;
  374. }
  375. extern void CheckAndPrintMsgId(U16 Id);
  376. /*****************************************************************************
  377.  * FUNCTION
  378.  *  OslIntMsgSendExtQueue
  379.  * DESCRIPTION
  380.  *  Writes to Task External Queue
  381.  * PARAMETERS
  382.  *  Message     [?]     
  383.  * RETURNS
  384.  *  void
  385.  *****************************************************************************/
  386. void OslIntMsgSendExtQueue(MYQUEUE *Message)
  387. {
  388. #ifndef MMI_ON_WIN32
  389.     /*----------------------------------------------------------------*/
  390.     /* Local Variables                                                */
  391.     /*----------------------------------------------------------------*/
  392.     MYQUEUE *oslMessage;
  393.     U8 ref_count;
  394.     
  395.     /*----------------------------------------------------------------*/
  396.     /* Code Body                                                      */
  397.     /*----------------------------------------------------------------*/
  398.     
  399.     /* check ref_count of local para */
  400.     if (Message->local_para_ptr != NULL)
  401.     {
  402.         ref_count = Message->local_para_ptr->ref_count;              
  403.         EXT_ASSERT(ref_count != 0, (int)Message->src_mod_id, 
  404.                     (int)Message->dest_mod_id, (int)Message->msg_id);
  405.     }    
  406.     
  407.     oslMessage = allocate_ilm(Message->oslSrcId);
  408.     memcpy(oslMessage, Message, sizeof(MYQUEUE));
  409.     if (oslMessage->oslSrcId == MOD_MMI &&
  410.         oslMessage->oslDestId == MOD_L4C)
  411.     {
  412.         oslMessage->sap_id = MMI_L4C_SAP;
  413.     }
  414.     else if (oslMessage->oslSrcId == MOD_MMI &&
  415.              oslMessage->oslDestId == MOD_MMI)
  416.     {
  417.         oslMessage->sap_id = MMI_MMI_SAP;
  418.     }
  419. #ifdef __MMI_FILE_MANAGER__    
  420.     else if (oslMessage->oslSrcId == MOD_MMI &&
  421.              oslMessage->oslDestId == MOD_FMT)
  422.     {
  423.         oslMessage->sap_id = MMI_FMT_SAP;
  424.     }
  425. #endif
  426.     else if (oslMessage->oslSrcId == MOD_MMI &&
  427.              oslMessage->oslDestId == MOD_ABM)
  428.     {
  429.         oslMessage->sap_id = MMI_ABM_SAP;
  430.     }
  431.     else if (oslMessage->oslSrcId == MOD_MMI &&
  432.              oslMessage->oslDestId == MOD_J2ME)
  433.     {
  434.         oslMessage->sap_id = MMI_J2ME_SAP;
  435.     }
  436.     else if (oslMessage->oslSrcId == MOD_MMI &&
  437.              oslMessage->oslDestId == MOD_JASYN)
  438.     {
  439.         oslMessage->sap_id = MMI_JASYN_SAP;
  440.     }
  441.     else if (oslMessage->oslSrcId == MOD_MMI &&
  442.              oslMessage->oslDestId == MOD_SYNCML)
  443.     {
  444.         oslMessage->sap_id = MMI_SYNCML_SAP;
  445.     }
  446.     else if (oslMessage->oslSrcId == MOD_MMI &&
  447.              oslMessage->oslDestId == MOD_POC)
  448.     {
  449.         oslMessage->sap_id = MMI_POC_SAP;
  450.     }
  451.     else if (oslMessage->oslSrcId == MOD_MMI &&
  452.              oslMessage->oslDestId == MOD_WAP)
  453.     {
  454.         oslMessage->sap_id = MMI_WAP_SAP;
  455.     }
  456.     else if (oslMessage->oslSrcId == MOD_WAP &&
  457.              oslMessage->oslDestId == MOD_MMI)
  458.     {
  459.         oslMessage->sap_id = WAP_MMI_SAP;
  460.     }
  461.     else
  462.     {
  463.         oslMessage->sap_id = INVALID_SAP;
  464.     }
  465.     msg_send_ext_queue(oslMessage);
  466.     CheckAndPrintMsgId((U16) (Message->msg_id));
  467. #else /* MMI_ON_WIN32 */ 
  468.     if (Message->oslDestId == MOD_MMI)
  469.     {
  470.         Message->oslDestId = MOD_PRT;
  471.     }
  472.     if (Message->oslSrcId == MOD_MMI)
  473.     {
  474.         Message->oslSrcId = MOD_PRT;
  475.     }
  476.     if (Message->oslDestId == MOD_WAP)
  477.     {
  478.         Message->oslDestId = MOD_PRT;
  479.     }
  480.     
  481.     /* make sure destination module exists */
  482.     MMI_ASSERT( Message->oslDestId < TOTAL_TASKS );
  483.     
  484.     OslIntWriteMsgQ(task_info_g1[Message->oslDestId].task_ext_qid, Message, sizeof(MYQUEUE), OSL_INFINITE_WAIT);
  485. #endif /* MMI_ON_WIN32 */ 
  486. }
  487. /*****************************************************************************
  488.  * FUNCTION
  489.  *  OslIntConstructDataPtr
  490.  * DESCRIPTION
  491.  *  Constructs Data Ptr
  492.  *  
  493.  *  Not used now
  494.  * PARAMETERS
  495.  *  size        [IN]        
  496.  * RETURNS
  497.  *  void
  498.  *****************************************************************************/
  499. void *OslIntConstructDataPtr(U32 size)
  500. {
  501. #ifndef MMI_ON_WIN32
  502.     /*----------------------------------------------------------------*/
  503.     /* Local Variables                                                */
  504.     /*----------------------------------------------------------------*/
  505.     /*----------------------------------------------------------------*/
  506.     /* Code Body                                                      */
  507.     /*----------------------------------------------------------------*/
  508.     return (construct_local_para((kal_uint16) size, TD_CTRL));
  509. #else /* MMI_ON_WIN32 */ 
  510.     void *ptr;
  511.     TSIZE *temp, tempdata;
  512.     temp = OslMalloc(size + sizeof(tempdata));
  513.     assert(temp != NULL);
  514.     tempdata.s = size;
  515.     memcpy(temp, &tempdata, sizeof(tempdata));
  516.     ptr = (void*)((char*)temp + sizeof(tempdata));
  517.     return ptr;
  518. #endif /* MMI_ON_WIN32 */ 
  519. }
  520. /*****************************************************************************
  521.  * FUNCTION
  522.  *  OslIntFreeDataPtr
  523.  * DESCRIPTION
  524.  *  Frees Data Ptr
  525.  *  
  526.  *  Not used now
  527.  * PARAMETERS
  528.  *  ptr     [?]     
  529.  * RETURNS
  530.  *  void
  531.  *****************************************************************************/
  532. void OslIntFreeDataPtr(void *ptr)
  533. {
  534. #ifndef MMI_ON_WIN32
  535.     /*----------------------------------------------------------------*/
  536.     /* Local Variables                                                */
  537.     /*----------------------------------------------------------------*/
  538.     /*----------------------------------------------------------------*/
  539.     /* Code Body                                                      */
  540.     /*----------------------------------------------------------------*/
  541.     free_local_para(ptr);
  542. #else /* MMI_ON_WIN32 */ 
  543.     TSIZE *temp;
  544.     temp = (void*)((char*)ptr - sizeof(TSIZE));
  545.     OslMfree(temp);
  546. #endif /* MMI_ON_WIN32 */ 
  547. }
  548. /*****************************************************************************
  549.  * FUNCTION
  550.  *  OslIntSizeofDataPtr
  551.  * DESCRIPTION
  552.  *  Returns Size of Data Ptr
  553.  *  
  554.  *  Not used now
  555.  * PARAMETERS
  556.  *  ptr     [?]     
  557.  * RETURNS
  558.  *  void
  559.  *****************************************************************************/
  560. U32 OslIntSizeofDataPtr(void *ptr)
  561. {
  562. #ifndef MMI_ON_WIN32
  563.     /*----------------------------------------------------------------*/
  564.     /* Local Variables                                                */
  565.     /*----------------------------------------------------------------*/
  566.     struct tsize
  567.     {
  568.         U8 ref_count;
  569.         U16 size;
  570.         /*----------------------------------------------------------------*/
  571.         /* Code Body                                                      */
  572.         /*----------------------------------------------------------------*/
  573.     };
  574.     return 0;
  575. #else /* MMI_ON_WIN32 */ 
  576.     typedef struct tsize
  577.     {
  578.         U32 size;
  579.     } TSIZE;
  580.     TSIZE *temp;
  581.     if (ptr == NULL)
  582.     {
  583.         return 0;
  584.     }
  585.     temp = (void*)((char*)ptr - sizeof(TSIZE));
  586.     return (U32) temp->size;
  587. #endif /* MMI_ON_WIN32 */ 
  588. }
  589. /*****************************************************************************
  590.  * FUNCTION
  591.  *  OslIntFreeInterTaskMsg
  592.  * DESCRIPTION
  593.  *  Frees InterTask Mesg
  594.  *  
  595.  *  Not used now
  596.  * PARAMETERS
  597.  *  Message     [?]     
  598.  * RETURNS
  599.  *  void
  600.  *****************************************************************************/
  601. void OslIntFreeInterTaskMsg(void *Message)
  602. {
  603. #ifndef MMI_ON_WIN32
  604.     /*----------------------------------------------------------------*/
  605.     /* Local Variables                                                */
  606.     /*----------------------------------------------------------------*/
  607.     /*----------------------------------------------------------------*/
  608.     /* Code Body                                                      */
  609.     /*----------------------------------------------------------------*/
  610.     free_ilm(Message);
  611. #else /* MMI_ON_WIN32 */ 
  612.     MYQUEUE *ptr;
  613.     ptr = Message;
  614.     if (ptr->oslSrcId == MOD_L4C)
  615.     {
  616.         ptr->oslSrcId = MOD_MMI;
  617.         ptr->oslDestId = MOD_L4C;
  618.         ptr->oslMsgId = 0;
  619.         OslMsgSendExtQueue(ptr);
  620.     }
  621.     else
  622.     {
  623.         if (ptr->oslDataPtr != NULL)
  624.         {
  625.             OslIntFreeDataPtr(ptr->oslDataPtr);
  626.         }
  627.     }
  628. #endif /* MMI_ON_WIN32 */ 
  629. }
  630. #ifdef MMI_ON_WIN32
  631. /*****************************************************************************
  632.  * FUNCTION
  633.  *  OslNumOfQMsgs
  634.  * DESCRIPTION
  635.  *  Get the message number in MMI queue
  636.  * PARAMETERS
  637.  *  void
  638.  * RETURNS
  639.  *  message number
  640.  *****************************************************************************/
  641. U8 OslNumOfQMsgs(void)
  642. {
  643.     /*----------------------------------------------------------------*/
  644.     /* Local Variables                                                */
  645.     /*----------------------------------------------------------------*/
  646.     U8 num;
  647.     oslMsgqid msgqid = task_info_g1[MOD_PRT].task_ext_qid;
  648.     /*----------------------------------------------------------------*/
  649.     /* Code Body                                                      */
  650.     /*----------------------------------------------------------------*/
  651.     EnterCriticalSection(&msgqid->q_cs);
  652.     num = (U8) (msgqid->q_messages);
  653.     LeaveCriticalSection(&msgqid->q_cs);
  654.     return num;
  655. }
  656. #endif /* MMI_ON_WIN32 */ 
  657. #define CIRCQ_NODE_SIZE sizeof(MYQUEUE)
  658. /* 
  659.  * Because MMI task will receive extQ message into circular queue,
  660.  * we increase the circular queue size from 30 to 50
  661.  */
  662. #define CIRCQ_NO_OF_NODES 65
  663. __align(4)
  664.      U8 circq_array[CIRCQ_NODE_SIZE * CIRCQ_NO_OF_NODES];
  665.      U8 circq_read = 0, circq_write = 0, circq_messages = 0, max_circq_messages = 0;
  666. /*****************************************************************************
  667.  * FUNCTION
  668.  *  OslReadCircularQ
  669.  * DESCRIPTION
  670.  *  Reads from Circ Queue
  671.  *  
  672.  *  Not used now
  673.  * PARAMETERS
  674.  *  msgPtr      [?]     
  675.  * RETURNS
  676.  *  void
  677.  *****************************************************************************/
  678.      U8 OslReadCircularQ(void *msgPtr)
  679. {
  680.     /*----------------------------------------------------------------*/
  681.     /* Local Variables                                                */
  682.     /*----------------------------------------------------------------*/
  683.     /*----------------------------------------------------------------*/
  684.     /* Code Body                                                      */
  685.     /*----------------------------------------------------------------*/
  686.     PRINT_INFORMATION_2((MMI_TRACE_G1_FRM, "OslReadCircularQ: <#[%d], read:[%d], write:[%d]>", circq_messages,
  687.                          circq_read, circq_write));
  688.     if (circq_messages == 0)
  689.     {
  690.         return 0;
  691.     }
  692.     memcpy(msgPtr, circq_array + (circq_read * CIRCQ_NODE_SIZE), CIRCQ_NODE_SIZE);
  693.     if (++circq_read == CIRCQ_NO_OF_NODES)
  694.     {
  695.         circq_read = 0;
  696.     }
  697.     --circq_messages;
  698.     return 1;
  699. }
  700. /*****************************************************************************
  701.  * FUNCTION
  702.  *  OslLookUpLastCircularQMsg
  703.  * DESCRIPTION
  704.  *  Look up the last message in Circ Queue
  705.  *  
  706.  *  Not used now
  707.  * PARAMETERS
  708.  *  msgPtr      [?]     
  709.  * RETURNS
  710.  *  void
  711.  *****************************************************************************/
  712. U8 OslLookUpLastCircularQMsg(void *msgPtr)
  713. {
  714.     /*----------------------------------------------------------------*/
  715.     /* Local Variables                                                */
  716.     /*----------------------------------------------------------------*/
  717.     U16 last_read_index;
  718.     /*----------------------------------------------------------------*/
  719.     /* Code Body                                                      */
  720.     /*----------------------------------------------------------------*/
  721.     if (circq_messages > 0)
  722.     {
  723.         if (circq_write == 0)
  724.         {
  725.             last_read_index = CIRCQ_NO_OF_NODES;
  726.         }
  727.         else
  728.         {
  729.             last_read_index = circq_write - 1;
  730.         }
  731.         memcpy(msgPtr, circq_array + (last_read_index * CIRCQ_NODE_SIZE), CIRCQ_NODE_SIZE);
  732.         return 1;
  733.     }
  734.     else
  735.     {
  736.         memset(msgPtr, 0, CIRCQ_NODE_SIZE);
  737.         return 0;
  738.     }
  739. }
  740. /*****************************************************************************
  741.  * FUNCTION
  742.  *  OslWriteCircularQ
  743.  * DESCRIPTION
  744.  *  Writes to Circ Queue
  745.  *  
  746.  *  Not used now
  747.  * PARAMETERS
  748.  *  msgPtr      [?]     
  749.  * RETURNS
  750.  *  void
  751.  *****************************************************************************/
  752. U8 OslWriteCircularQ(void *msgPtr)
  753. {
  754.     /*----------------------------------------------------------------*/
  755.     /* Local Variables                                                */
  756.     /*----------------------------------------------------------------*/
  757.     /*----------------------------------------------------------------*/
  758.     /* Code Body                                                      */
  759.     /*----------------------------------------------------------------*/
  760.     PRINT_INFORMATION_2((MMI_TRACE_G1_FRM, "OslWriteCircularQ: <#[%d], read:[%d], write:[%d]>", circq_messages,
  761.                          circq_read, circq_write));
  762.     if (circq_messages == CIRCQ_NO_OF_NODES)
  763.     {
  764.         MMI_ASSERT(0);
  765.         return 0;
  766.     }
  767.     memcpy(circq_array + (circq_write * CIRCQ_NODE_SIZE), msgPtr, CIRCQ_NODE_SIZE);
  768.     if (++circq_write == CIRCQ_NO_OF_NODES)
  769.     {
  770.         circq_write = 0;
  771.     }
  772.     ++circq_messages;
  773.     if (max_circq_messages < circq_messages)
  774.     {
  775.         max_circq_messages = circq_messages;
  776.     }
  777.     return 1;
  778. }
  779. /*****************************************************************************
  780.  * FUNCTION
  781.  *  OslNumOfCircularQMsgs
  782.  * DESCRIPTION
  783.  *  Get the message number
  784.  *  
  785.  *  Not used now
  786.  * PARAMETERS
  787.  *  void
  788.  * RETURNS
  789.  *  void
  790.  *****************************************************************************/
  791. U8 OslNumOfCircularQMsgs(void)
  792. {
  793.     /*----------------------------------------------------------------*/
  794.     /* Local Variables                                                */
  795.     /*----------------------------------------------------------------*/
  796.     /*----------------------------------------------------------------*/
  797.     /* Code Body                                                      */
  798.     /*----------------------------------------------------------------*/
  799.     return circq_messages;
  800. }
  801. /*****************************************************************************
  802.  * FUNCTION
  803.  *  OslIsCircularQFull
  804.  * DESCRIPTION
  805.  *  Check if Circ Queue is full
  806.  *  
  807.  *  Not used now
  808.  * PARAMETERS
  809.  *  void
  810.  * RETURNS
  811.  *  void
  812.  *****************************************************************************/
  813. U8 OslIsCircularQFull(void)
  814. {
  815.     /*----------------------------------------------------------------*/
  816.     /* Local Variables                                                */
  817.     /*----------------------------------------------------------------*/
  818.     /*----------------------------------------------------------------*/
  819.     /* Code Body                                                      */
  820.     /*----------------------------------------------------------------*/
  821.     return (circq_messages == CIRCQ_NO_OF_NODES);
  822. }