khronosfws/openmax_al/src/engine/xathreadsyncitf.c
changeset 25 6f7ceef7b1d1
parent 12 5a06f39ad45b
child 33 5e8b14bae8c3
equal deleted inserted replaced
21:2ed61feeead6 25:6f7ceef7b1d1
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description: 
    14  * Description: ThreadSync Itf Implementation
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include <stdio.h>
    18 #include <stdio.h>
    19 #include <stdlib.h>
    19 #include <stdlib.h>
    20 #include <assert.h>
    20 #include <assert.h>
    21 
    21 
    23 
    23 
    24 /**
    24 /**
    25  * Base interface XAThreadSyncItf Implementation
    25  * Base interface XAThreadSyncItf Implementation
    26  */
    26  */
    27 XAresult XAThreadSyncItfImpl_EnterCriticalSection(XAThreadSyncItf self)
    27 XAresult XAThreadSyncItfImpl_EnterCriticalSection(XAThreadSyncItf self)
    28 {
    28     {
    29     XAresult ret = XA_RESULT_SUCCESS;
    29     XAresult ret = XA_RESULT_SUCCESS;
    30     XAThreadSyncItfImpl* impl = NULL;
    30     XAThreadSyncItfImpl* impl = NULL;
    31 
    31 
    32     DEBUG_API("->XAThreadSyncItfImpl_EnterCriticalSection");
    32     DEBUG_API("->XAThreadSyncItfImpl_EnterCriticalSection");
    33 
    33 
    34     impl = (XAThreadSyncItfImpl*)(*self);
    34     impl = (XAThreadSyncItfImpl*) (*self);
    35     if( !impl || impl != impl->self )
    35     if (!impl || impl != impl->self)
    36     {
    36         {
    37         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
    37         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
    38         DEBUG_API("<-XAThreadSyncItfImpl_EnterCriticalSection");
    38         DEBUG_API("<-XAThreadSyncItfImpl_EnterCriticalSection");
    39         return XA_RESULT_PARAMETER_INVALID;
    39         return XA_RESULT_PARAMETER_INVALID;
       
    40         }
       
    41 
       
    42     if (impl->engInCritical)
       
    43         {
       
    44         /* The calling context must not already be in
       
    45          critical section state. */
       
    46         DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED");
       
    47         ret = XA_RESULT_PRECONDITIONS_VIOLATED;
       
    48         }
       
    49     else
       
    50         {
       
    51         ret = XAImpl_LockMutex(impl->engCriticalSection);
       
    52         if (ret == XA_RESULT_SUCCESS)
       
    53             {
       
    54             impl->engInCritical = XA_BOOLEAN_TRUE;
       
    55             }
       
    56         }DEBUG_API("<-XAThreadSyncItfImpl_EnterCriticalSection");
       
    57     return ret;
    40     }
    58     }
    41 
    59 
    42     if( impl->engInCritical )
    60 XAresult XAThreadSyncItfImpl_ExitCriticalSection(XAThreadSyncItf self)
    43     {
    61     {
    44         /* The calling context must not already be in
       
    45            critical section state. */
       
    46         DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED");
       
    47         ret = XA_RESULT_PRECONDITIONS_VIOLATED;
       
    48     }
       
    49     else
       
    50     {
       
    51         ret = XAImpl_LockMutex( impl->engCriticalSection );
       
    52         if(ret == XA_RESULT_SUCCESS)
       
    53         {
       
    54             impl->engInCritical = XA_BOOLEAN_TRUE;
       
    55         }
       
    56     }
       
    57     DEBUG_API("<-XAThreadSyncItfImpl_EnterCriticalSection");
       
    58     return ret;
       
    59 }
       
    60 
       
    61 XAresult XAThreadSyncItfImpl_ExitCriticalSection(XAThreadSyncItf self)
       
    62 {
       
    63     XAThreadSyncItfImpl* impl = NULL;
    62     XAThreadSyncItfImpl* impl = NULL;
    64     XAresult ret = XA_RESULT_SUCCESS;
    63     XAresult ret = XA_RESULT_SUCCESS;
    65 
    64 
    66     impl = (XAThreadSyncItfImpl*)(*self);
    65     impl = (XAThreadSyncItfImpl*) (*self);
    67     DEBUG_API("->XAThreadSyncItfImpl_ExitCriticalSection");
    66     DEBUG_API("->XAThreadSyncItfImpl_ExitCriticalSection");
    68 
    67 
    69     if( !impl || impl != impl->self )
    68     if (!impl || impl != impl->self)
    70     {
    69         {
    71         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
    70         DEBUG_ERR("XA_RESULT_PARAMETER_INVALID");
    72         DEBUG_API("<-XAThreadSyncItfImpl_ExitCriticalSection");
    71         DEBUG_API("<-XAThreadSyncItfImpl_ExitCriticalSection");
    73         return XA_RESULT_PARAMETER_INVALID;
    72         return XA_RESULT_PARAMETER_INVALID;
    74     }
    73         }
    75 
    74 
    76     if( impl->engInCritical  )
    75     if (impl->engInCritical)
    77     {
       
    78         ret = XAImpl_UnlockMutex( impl->engCriticalSection );
       
    79         if(ret == XA_RESULT_SUCCESS)
       
    80         {
    76         {
       
    77         ret = XAImpl_UnlockMutex(impl->engCriticalSection);
       
    78         if (ret == XA_RESULT_SUCCESS)
       
    79             {
    81             impl->engInCritical = XA_BOOLEAN_FALSE;
    80             impl->engInCritical = XA_BOOLEAN_FALSE;
       
    81             }
    82         }
    82         }
    83     }
       
    84     else
    83     else
    85     {
    84         {
    86         /* The engine must be in critical section state */
    85         /* The engine must be in critical section state */
    87         DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED");
    86         DEBUG_ERR("XA_RESULT_PRECONDITIONS_VIOLATED");
    88         ret = XA_RESULT_PRECONDITIONS_VIOLATED;
    87         ret = XA_RESULT_PRECONDITIONS_VIOLATED;
       
    88         }DEBUG_API("<-XAThreadSyncItfImpl_ExitCriticalSection");
       
    89     return ret;
    89     }
    90     }
    90     DEBUG_API("<-XAThreadSyncItfImpl_ExitCriticalSection");
       
    91     return ret;
       
    92 }
       
    93 
    91 
    94 /**
    92 /**
    95  * XAThreadSyncItfImpl -specific methods
    93  * XAThreadSyncItfImpl -specific methods
    96  **/
    94  **/
    97 
    95 
    98 XAThreadSyncItfImpl* XAThreadSyncItfImpl_Create()
    96 XAThreadSyncItfImpl* XAThreadSyncItfImpl_Create()
    99 {
    97     {
   100     XAThreadSyncItfImpl *self = NULL;
    98     XAThreadSyncItfImpl *self = NULL;
   101     DEBUG_API("->XAThreadSyncItfImpl_Create");
    99     DEBUG_API("->XAThreadSyncItfImpl_Create");
   102 
   100 
   103     self = (XAThreadSyncItfImpl*)calloc(1,sizeof(XAThreadSyncItfImpl));
   101     self = (XAThreadSyncItfImpl*) calloc(1, sizeof(XAThreadSyncItfImpl));
   104 
   102 
   105     if( self )
   103     if (self)
   106     {
   104         {
   107         /* init itf default implementation */
   105         /* init itf default implementation */
   108         self->itf.EnterCriticalSection = XAThreadSyncItfImpl_EnterCriticalSection;
   106         self->itf.EnterCriticalSection
   109         self->itf.ExitCriticalSection = XAThreadSyncItfImpl_ExitCriticalSection;
   107                 = XAThreadSyncItfImpl_EnterCriticalSection;
       
   108         self->itf.ExitCriticalSection
       
   109                 = XAThreadSyncItfImpl_ExitCriticalSection;
   110 
   110 
   111         if( XAImpl_CreateMutex( &(self->engCriticalSection) )
   111         if (XAImpl_CreateMutex(&(self->engCriticalSection))
   112             != XA_RESULT_SUCCESS )
   112                 != XA_RESULT_SUCCESS)
   113         {
   113             {
   114             DEBUG_ERR("Mutex creation failed, abort");
   114             DEBUG_ERR("Mutex creation failed, abort");
   115             free(self);
   115             free(self);
   116             DEBUG_API("<-XAThreadSyncItfImpl_Create");
   116             DEBUG_API("<-XAThreadSyncItfImpl_Create");
   117             return NULL;
   117             return NULL;
   118         }
   118             }
   119 
   119 
   120         self->self = self;
   120         self->self = self;
   121     }
   121         }
   122     DEBUG_API("<-XAThreadSyncItfImpl_Create");
   122     DEBUG_API("<-XAThreadSyncItfImpl_Create");
   123     return self;
   123     return self;
   124 }
   124     }
   125 
   125 
   126 void XAThreadSyncItfImpl_Free(XAThreadSyncItfImpl* self)
   126 void XAThreadSyncItfImpl_Free(XAThreadSyncItfImpl* self)
   127 {
   127     {
   128     DEBUG_API("->XAThreadSyncItfImpl_Free");
   128     DEBUG_API("->XAThreadSyncItfImpl_Free");
   129     assert(self==self->self);
   129     assert(self==self->self);
   130     XAImpl_DeleteMutex(self->engCriticalSection);
   130     if(self)
   131     free(self);
   131         {
       
   132         XAImpl_DeleteMutex(self->engCriticalSection);
       
   133         free(self);
       
   134         }
   132     DEBUG_API("<-XAThreadSyncItfImpl_Free");
   135     DEBUG_API("<-XAThreadSyncItfImpl_Free");
   133 }
   136     }
   134 
   137