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

lock.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2002, TransGaming Technologies Inc.
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 #include <precomp.h>
00020 
00021 
00022 typedef struct
00023 {
00024   BOOL             bInit;
00025   CRITICAL_SECTION crit;
00026 } LOCKTABLEENTRY;
00027 
00028 static LOCKTABLEENTRY lock_table[ _TOTAL_LOCKS ];
00029 
00030 static __inline void msvcrt_mlock_set_entry_initialized( int locknum, BOOL initialized )
00031 {
00032   lock_table[ locknum ].bInit = initialized;
00033 }
00034 
00035 static __inline void msvcrt_initialize_mlock( int locknum )
00036 {
00037   InitializeCriticalSection( &(lock_table[ locknum ].crit) );
00038   msvcrt_mlock_set_entry_initialized( locknum, TRUE );
00039 }
00040 
00041 static __inline void msvcrt_uninitialize_mlock( int locknum )
00042 {
00043   DeleteCriticalSection( &(lock_table[ locknum ].crit) );
00044   msvcrt_mlock_set_entry_initialized( locknum, FALSE );
00045 }
00046 
00047 /**********************************************************************
00048  *     msvcrt_init_mt_locks (internal)
00049  *
00050  * Initialize the table lock. All other locks will be initialized
00051  * upon first use.
00052  *
00053  */
00054 void msvcrt_init_mt_locks(void)
00055 {
00056   int i;
00057 
00058   TRACE( "initializing mtlocks\n" );
00059 
00060   /* Initialize the table */
00061   for( i=0; i < _TOTAL_LOCKS; i++ )
00062   {
00063     msvcrt_mlock_set_entry_initialized( i, FALSE );
00064   }
00065 
00066   /* Initialize our lock table lock */
00067   msvcrt_initialize_mlock( _LOCKTAB_LOCK );
00068 }
00069 
00070 /**********************************************************************
00071  *     msvcrt_free_mt_locks (internal)
00072  *
00073  * Uninitialize all mt locks. Assume that neither _lock or _unlock will
00074  * be called once we're calling this routine (ie _LOCKTAB_LOCK can be deleted)
00075  *
00076  */
00077 void msvcrt_free_mt_locks(void)
00078 {
00079   int i;
00080 
00081   TRACE(": uninitializing all mtlocks\n" );
00082 
00083   /* Uninitialize the table */
00084   for( i=0; i < _TOTAL_LOCKS; i++ )
00085   {
00086     if( lock_table[ i ].bInit == TRUE )
00087     {
00088       msvcrt_uninitialize_mlock( i );
00089     }
00090   }
00091 }
00092 
00093 
00094 /**********************************************************************
00095  *              _lock (MSVCRT.@)
00096  */
00097 void _lock( int locknum )
00098 {
00099   TRACE( "(%d)\n", locknum );
00100 
00101   /* If the lock doesn't exist yet, create it */
00102   if( lock_table[ locknum ].bInit == FALSE )
00103   {
00104     /* Lock while we're changing the lock table */
00105     _lock( _LOCKTAB_LOCK );
00106 
00107     /* Check again if we've got a bit of a race on lock creation */
00108     if( lock_table[ locknum ].bInit == FALSE )
00109     {
00110       TRACE( ": creating lock #%d\n", locknum );
00111       msvcrt_initialize_mlock( locknum );
00112     }
00113 
00114     /* Unlock ourselves */
00115     _unlock( _LOCKTAB_LOCK );
00116   }
00117 
00118   EnterCriticalSection( &(lock_table[ locknum ].crit) );
00119 }
00120 
00121 /**********************************************************************
00122  *              _unlock (MSVCRT.@)
00123  *
00124  * NOTE: There is no error detection to make sure the lock exists and is acquired.
00125  */
00126 void _unlock( int locknum )
00127 {
00128   TRACE( "(%d)\n", locknum );
00129 
00130   LeaveCriticalSection( &(lock_table[ locknum ].crit) );
00131 }
00132 
00133 

Generated on Sun May 27 2012 04:24:26 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.