ReactOS 0.4.15-dev-8116-gf69e256
lock.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2002, TransGaming Technologies Inc.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include <precomp.h>
20
21
22typedef struct
23{
27
29
30static __inline void msvcrt_mlock_set_entry_initialized( int locknum, BOOL initialized )
31{
32 lock_table[ locknum ].bInit = initialized;
33}
34
35static __inline void msvcrt_initialize_mlock( int locknum )
36{
37 InitializeCriticalSection( &(lock_table[ locknum ].crit) );
39}
40
41static __inline void msvcrt_uninitialize_mlock( int locknum )
42{
43 DeleteCriticalSection( &(lock_table[ locknum ].crit) );
45}
46
47/**********************************************************************
48 * msvcrt_init_mt_locks (internal)
49 *
50 * Initialize the table lock. All other locks will be initialized
51 * upon first use.
52 *
53 */
55{
56 int i;
57
58 TRACE( "initializing mtlocks\n" );
59
60 /* Initialize the table */
61 for( i=0; i < _TOTAL_LOCKS; i++ )
62 {
64 }
65
66 /* Initialize our lock table lock */
68}
69
70/**********************************************************************
71 * msvcrt_free_mt_locks (internal)
72 *
73 * Uninitialize all mt locks. Assume that neither _lock or _unlock will
74 * be called once we're calling this routine (ie _LOCKTAB_LOCK can be deleted)
75 *
76 */
78{
79 int i;
80
81 TRACE(": uninitializing all mtlocks\n" );
82
83 /* Uninitialize the table */
84 for( i=0; i < _TOTAL_LOCKS; i++ )
85 {
86 if( lock_table[ i ].bInit )
87 {
89 }
90 }
91}
92
93
94/**********************************************************************
95 * _lock (MSVCRT.@)
96 */
97void _lock( int locknum )
98{
99 TRACE( "(%d)\n", locknum );
100
101 /* If the lock doesn't exist yet, create it */
102 if( lock_table[ locknum ].bInit == FALSE )
103 {
104 /* Lock while we're changing the lock table */
106
107 /* Check again if we've got a bit of a race on lock creation */
108 if( lock_table[ locknum ].bInit == FALSE )
109 {
110 TRACE( ": creating lock #%d\n", locknum );
111 msvcrt_initialize_mlock( locknum );
112 }
113
114 /* Unlock ourselves */
116 }
117
118 EnterCriticalSection( &(lock_table[ locknum ].crit) );
119}
120
121/**********************************************************************
122 * _unlock (MSVCRT.@)
123 *
124 * NOTE: There is no error detection to make sure the lock exists and is acquired.
125 */
126void _unlock( int locknum )
127{
128 TRACE( "(%d)\n", locknum );
129
130 LeaveCriticalSection( &(lock_table[ locknum ].crit) );
131}
132
133
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define _LOCKTAB_LOCK
Definition: mtdll.h:54
#define _TOTAL_LOCKS
Definition: mtdll.h:70
static __inline void msvcrt_uninitialize_mlock(int locknum)
Definition: lock.c:41
static __inline void msvcrt_mlock_set_entry_initialized(int locknum, BOOL initialized)
Definition: lock.c:30
static __inline void msvcrt_initialize_mlock(int locknum)
Definition: lock.c:35
static LOCKTABLEENTRY lock_table[_TOTAL_LOCKS]
Definition: lock.c:28
void msvcrt_init_mt_locks(void)
Definition: lock.c:54
void _unlock(int locknum)
Definition: lock.c:126
void msvcrt_free_mt_locks(void)
Definition: lock.c:77
void _lock(int locknum)
Definition: lock.c:97
#define TRACE(s)
Definition: solgame.cpp:4
CRITICAL_SECTION crit
Definition: lock.c:25
BOOL bInit
Definition: lock.c:24
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
static BOOL initialized
Definition: syslog.c:39
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)