ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utmutex.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Module Name: utmutex - local mutex support
00004  *
00005  ******************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 
00117 #define __UTMUTEX_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 
00122 #define _COMPONENT          ACPI_UTILITIES
00123         ACPI_MODULE_NAME    ("utmutex")
00124 
00125 /* Local prototypes */
00126 
00127 static ACPI_STATUS
00128 AcpiUtCreateMutex (
00129     ACPI_MUTEX_HANDLE       MutexId);
00130 
00131 static void
00132 AcpiUtDeleteMutex (
00133     ACPI_MUTEX_HANDLE       MutexId);
00134 
00135 
00136 /*******************************************************************************
00137  *
00138  * FUNCTION:    AcpiUtMutexInitialize
00139  *
00140  * PARAMETERS:  None.
00141  *
00142  * RETURN:      Status
00143  *
00144  * DESCRIPTION: Create the system mutex objects. This includes mutexes,
00145  *              spin locks, and reader/writer locks.
00146  *
00147  ******************************************************************************/
00148 
00149 ACPI_STATUS
00150 AcpiUtMutexInitialize (
00151     void)
00152 {
00153     UINT32                  i;
00154     ACPI_STATUS             Status;
00155 
00156 
00157     ACPI_FUNCTION_TRACE (UtMutexInitialize);
00158 
00159 
00160     /* Create each of the predefined mutex objects */
00161 
00162     for (i = 0; i < ACPI_NUM_MUTEX; i++)
00163     {
00164         Status = AcpiUtCreateMutex (i);
00165         if (ACPI_FAILURE (Status))
00166         {
00167             return_ACPI_STATUS (Status);
00168         }
00169     }
00170 
00171     /* Create the spinlocks for use at interrupt level */
00172 
00173     Status = AcpiOsCreateLock (&AcpiGbl_GpeLock);
00174     if (ACPI_FAILURE (Status))
00175     {
00176         return_ACPI_STATUS (Status);
00177     }
00178 
00179     Status = AcpiOsCreateLock (&AcpiGbl_HardwareLock);
00180     if (ACPI_FAILURE (Status))
00181     {
00182         return_ACPI_STATUS (Status);
00183     }
00184 
00185     /* Mutex for _OSI support */
00186     Status = AcpiOsCreateMutex (&AcpiGbl_OsiMutex);
00187     if (ACPI_FAILURE (Status))
00188     {
00189         return_ACPI_STATUS (Status);
00190     }
00191 
00192     /* Create the reader/writer lock for namespace access */
00193 
00194     Status = AcpiUtCreateRwLock (&AcpiGbl_NamespaceRwLock);
00195     return_ACPI_STATUS (Status);
00196 }
00197 
00198 
00199 /*******************************************************************************
00200  *
00201  * FUNCTION:    AcpiUtMutexTerminate
00202  *
00203  * PARAMETERS:  None.
00204  *
00205  * RETURN:      None.
00206  *
00207  * DESCRIPTION: Delete all of the system mutex objects. This includes mutexes,
00208  *              spin locks, and reader/writer locks.
00209  *
00210  ******************************************************************************/
00211 
00212 void
00213 AcpiUtMutexTerminate (
00214     void)
00215 {
00216     UINT32                  i;
00217 
00218 
00219     ACPI_FUNCTION_TRACE (UtMutexTerminate);
00220 
00221 
00222     /* Delete each predefined mutex object */
00223 
00224     for (i = 0; i < ACPI_NUM_MUTEX; i++)
00225     {
00226         AcpiUtDeleteMutex (i);
00227     }
00228 
00229     AcpiOsDeleteMutex (AcpiGbl_OsiMutex);
00230 
00231     /* Delete the spinlocks */
00232 
00233     AcpiOsDeleteLock (AcpiGbl_GpeLock);
00234     AcpiOsDeleteLock (AcpiGbl_HardwareLock);
00235 
00236     /* Delete the reader/writer lock */
00237 
00238     AcpiUtDeleteRwLock (&AcpiGbl_NamespaceRwLock);
00239     return_VOID;
00240 }
00241 
00242 
00243 /*******************************************************************************
00244  *
00245  * FUNCTION:    AcpiUtCreateMutex
00246  *
00247  * PARAMETERS:  MutexID         - ID of the mutex to be created
00248  *
00249  * RETURN:      Status
00250  *
00251  * DESCRIPTION: Create a mutex object.
00252  *
00253  ******************************************************************************/
00254 
00255 static ACPI_STATUS
00256 AcpiUtCreateMutex (
00257     ACPI_MUTEX_HANDLE       MutexId)
00258 {
00259     ACPI_STATUS             Status = AE_OK;
00260 
00261 
00262     ACPI_FUNCTION_TRACE_U32 (UtCreateMutex, MutexId);
00263 
00264 
00265     if (!AcpiGbl_MutexInfo[MutexId].Mutex)
00266     {
00267         Status = AcpiOsCreateMutex (&AcpiGbl_MutexInfo[MutexId].Mutex);
00268         AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
00269         AcpiGbl_MutexInfo[MutexId].UseCount = 0;
00270     }
00271 
00272     return_ACPI_STATUS (Status);
00273 }
00274 
00275 
00276 /*******************************************************************************
00277  *
00278  * FUNCTION:    AcpiUtDeleteMutex
00279  *
00280  * PARAMETERS:  MutexID         - ID of the mutex to be deleted
00281  *
00282  * RETURN:      Status
00283  *
00284  * DESCRIPTION: Delete a mutex object.
00285  *
00286  ******************************************************************************/
00287 
00288 static void
00289 AcpiUtDeleteMutex (
00290     ACPI_MUTEX_HANDLE       MutexId)
00291 {
00292 
00293     ACPI_FUNCTION_TRACE_U32 (UtDeleteMutex, MutexId);
00294 
00295 
00296     AcpiOsDeleteMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
00297 
00298     AcpiGbl_MutexInfo[MutexId].Mutex = NULL;
00299     AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
00300 }
00301 
00302 
00303 /*******************************************************************************
00304  *
00305  * FUNCTION:    AcpiUtAcquireMutex
00306  *
00307  * PARAMETERS:  MutexID         - ID of the mutex to be acquired
00308  *
00309  * RETURN:      Status
00310  *
00311  * DESCRIPTION: Acquire a mutex object.
00312  *
00313  ******************************************************************************/
00314 
00315 ACPI_STATUS
00316 AcpiUtAcquireMutex (
00317     ACPI_MUTEX_HANDLE       MutexId)
00318 {
00319     ACPI_STATUS             Status;
00320     ACPI_THREAD_ID          ThisThreadId;
00321 
00322 
00323     ACPI_FUNCTION_NAME (UtAcquireMutex);
00324 
00325 
00326     if (MutexId > ACPI_MAX_MUTEX)
00327     {
00328         return (AE_BAD_PARAMETER);
00329     }
00330 
00331     ThisThreadId = AcpiOsGetThreadId ();
00332 
00333 #ifdef ACPI_MUTEX_DEBUG
00334     {
00335         UINT32                  i;
00336         /*
00337          * Mutex debug code, for internal debugging only.
00338          *
00339          * Deadlock prevention.  Check if this thread owns any mutexes of value
00340          * greater than or equal to this one.  If so, the thread has violated
00341          * the mutex ordering rule.  This indicates a coding error somewhere in
00342          * the ACPI subsystem code.
00343          */
00344         for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
00345         {
00346             if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
00347             {
00348                 if (i == MutexId)
00349                 {
00350                     ACPI_ERROR ((AE_INFO,
00351                         "Mutex [%s] already acquired by this thread [%u]",
00352                         AcpiUtGetMutexName (MutexId),
00353                         (UINT32) ThisThreadId));
00354 
00355                     return (AE_ALREADY_ACQUIRED);
00356                 }
00357 
00358                 ACPI_ERROR ((AE_INFO,
00359                     "Invalid acquire order: Thread %u owns [%s], wants [%s]",
00360                     (UINT32) ThisThreadId, AcpiUtGetMutexName (i),
00361                     AcpiUtGetMutexName (MutexId)));
00362 
00363                 return (AE_ACQUIRE_DEADLOCK);
00364             }
00365         }
00366     }
00367 #endif
00368 
00369     ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX,
00370         "Thread %u attempting to acquire Mutex [%s]\n",
00371         (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
00372 
00373     Status = AcpiOsAcquireMutex (AcpiGbl_MutexInfo[MutexId].Mutex,
00374                 ACPI_WAIT_FOREVER);
00375     if (ACPI_SUCCESS (Status))
00376     {
00377         ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u acquired Mutex [%s]\n",
00378             (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
00379 
00380         AcpiGbl_MutexInfo[MutexId].UseCount++;
00381         AcpiGbl_MutexInfo[MutexId].ThreadId = ThisThreadId;
00382     }
00383     else
00384     {
00385         ACPI_EXCEPTION ((AE_INFO, Status,
00386             "Thread %u could not acquire Mutex [0x%X]",
00387             (UINT32) ThisThreadId, MutexId));
00388     }
00389 
00390     return (Status);
00391 }
00392 
00393 
00394 /*******************************************************************************
00395  *
00396  * FUNCTION:    AcpiUtReleaseMutex
00397  *
00398  * PARAMETERS:  MutexID         - ID of the mutex to be released
00399  *
00400  * RETURN:      Status
00401  *
00402  * DESCRIPTION: Release a mutex object.
00403  *
00404  ******************************************************************************/
00405 
00406 ACPI_STATUS
00407 AcpiUtReleaseMutex (
00408     ACPI_MUTEX_HANDLE       MutexId)
00409 {
00410     ACPI_THREAD_ID          ThisThreadId;
00411 
00412 
00413     ACPI_FUNCTION_NAME (UtReleaseMutex);
00414 
00415 
00416     ThisThreadId = AcpiOsGetThreadId ();
00417     ACPI_DEBUG_PRINT ((ACPI_DB_MUTEX, "Thread %u releasing Mutex [%s]\n",
00418         (UINT32) ThisThreadId, AcpiUtGetMutexName (MutexId)));
00419 
00420     if (MutexId > ACPI_MAX_MUTEX)
00421     {
00422         return (AE_BAD_PARAMETER);
00423     }
00424 
00425     /*
00426      * Mutex must be acquired in order to release it!
00427      */
00428     if (AcpiGbl_MutexInfo[MutexId].ThreadId == ACPI_MUTEX_NOT_ACQUIRED)
00429     {
00430         ACPI_ERROR ((AE_INFO,
00431             "Mutex [0x%X] is not acquired, cannot release", MutexId));
00432 
00433         return (AE_NOT_ACQUIRED);
00434     }
00435 
00436 #ifdef ACPI_MUTEX_DEBUG
00437     {
00438         UINT32                  i;
00439         /*
00440          * Mutex debug code, for internal debugging only.
00441          *
00442          * Deadlock prevention.  Check if this thread owns any mutexes of value
00443          * greater than this one.  If so, the thread has violated the mutex
00444          * ordering rule.  This indicates a coding error somewhere in
00445          * the ACPI subsystem code.
00446          */
00447         for (i = MutexId; i < ACPI_NUM_MUTEX; i++)
00448         {
00449             if (AcpiGbl_MutexInfo[i].ThreadId == ThisThreadId)
00450             {
00451                 if (i == MutexId)
00452                 {
00453                     continue;
00454                 }
00455 
00456                 ACPI_ERROR ((AE_INFO,
00457                     "Invalid release order: owns [%s], releasing [%s]",
00458                     AcpiUtGetMutexName (i), AcpiUtGetMutexName (MutexId)));
00459 
00460                 return (AE_RELEASE_DEADLOCK);
00461             }
00462         }
00463     }
00464 #endif
00465 
00466     /* Mark unlocked FIRST */
00467 
00468     AcpiGbl_MutexInfo[MutexId].ThreadId = ACPI_MUTEX_NOT_ACQUIRED;
00469 
00470     AcpiOsReleaseMutex (AcpiGbl_MutexInfo[MutexId].Mutex);
00471     return (AE_OK);
00472 }
00473 
00474 

Generated on Sun May 27 2012 04:27:23 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.