24
24
*/
25
25
/* ************************************ Driver wide stuff ************************************************/
26
26
27
- CRITICAL_SECTION globalLock;
27
+ std::mutex globalLock;
28
28
static MADB_List *deletedStmt= NULL ;
29
- static unsigned int envCount= 0 ;
29
+ // sles12 does not have atomic_uint32 defined
30
+ static std::atomic<uint32_t > envCount (0U );
30
31
31
32
#ifndef _WIN32
32
33
__attribute__ ((constructor))
@@ -43,53 +44,48 @@ extern "C" {
43
44
/* {{{ DriverGlobalInit */
44
45
void DriverGlobalInit ()
45
46
{
46
- InitializeCriticalSection (&globalLock);
47
47
}
48
48
/* }}} */
49
49
50
50
/* {{{ DriverGlobalClean()*/
51
51
void DriverGlobalClean (void )
52
52
{
53
- EnterCriticalSection (&globalLock);
53
+ // There is no need to lock here at least the while it used the way it used now -
54
+ // only called when library is unloaded
54
55
if (deletedStmt)
55
56
{
56
57
MADB_ListFree (deletedStmt, FALSE );
57
58
}
58
- LeaveCriticalSection (&globalLock);
59
- DeleteCriticalSection (&globalLock);
60
59
}
61
60
/* }}} */
62
61
}
63
62
/* {{{ IncrementEnvCount */
64
63
// Normally there should be 1 Env, but nothing forbids app have more than 1.
65
64
void IncrementEnvCount ()
66
65
{
67
- EnterCriticalSection (&globalLock);
68
66
++envCount;
69
- LeaveCriticalSection (&globalLock);
70
67
}
71
68
/* }}}*/
72
69
73
70
/* {{{ DecrementEnvCount */
74
71
// If the last Env has been freed - we should probably clean the list
75
72
void DecrementEnvCount ()
76
73
{
77
- EnterCriticalSection (&globalLock);
78
74
--envCount;
79
75
if (!envCount)
80
76
{
77
+ std::lock_guard<std::mutex> localScopeLock (globalLock);
81
78
MADB_ListFree (deletedStmt, FALSE );
82
79
deletedStmt= NULL ;
83
80
}
84
- LeaveCriticalSection (&globalLock);
85
81
}
86
82
/* }}}*/
87
83
88
84
/* {{{ CheckDeletedStmt */
89
85
// If the last Env has been freed - we should probably clean the list
90
86
MADB_List* CheckDeletedStmt (void * stmtObjAddr)
91
87
{
92
- MADB_List* item= deletedStmt;
88
+ MADB_List * item= deletedStmt;
93
89
while (item != NULL )
94
90
{
95
91
if (item->data == stmtObjAddr)
@@ -104,18 +100,17 @@ MADB_List* CheckDeletedStmt(void* stmtObjAddr)
104
100
105
101
/* {{{ RemoveStmtFromDeleted */
106
102
// If the last Env has been freed - we should probably clean the list
107
- BOOL RemoveStmtFromDeleted (void * stmtObjAddr)
103
+ bool RemoveStmtFromDeleted (void * stmtObjAddr)
108
104
{
109
- BOOL result= FALSE ;
110
- EnterCriticalSection (& globalLock);
105
+ bool result= false ;
106
+ std::lock_guard<std::mutex> localScopeLock ( globalLock);
111
107
MADB_List* found= CheckDeletedStmt (stmtObjAddr);
112
108
if (found)
113
109
{
114
110
deletedStmt= MADB_ListDelete (deletedStmt, found);
115
111
free (found);
116
- result= TRUE ;
112
+ result= true ;
117
113
}
118
- LeaveCriticalSection (&globalLock);
119
114
return result;
120
115
}
121
116
/* }}}*/
0 commit comments