Skip to content

Commit 0979b7c

Browse files
committed
Better fix for AV at exit() time, CORE-2917 :
a) WaitForSingleObject hungs when process unloads embedded library b) shmem file was changed in incompatime way so build 26000 can't work together with any previous builds c) time_t in shmem replaced by SINT64 to avoid possible issues with builds by MSVC 7.1 (where time_t is 32-bit)
1 parent 47bd7b1 commit 0979b7c

3 files changed

Lines changed: 29 additions & 17 deletions

File tree

src/common/classes/RefCounted.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ namespace Firebird
6666
explicit Reference(RefCounted& refCounted) :
6767
r(refCounted)
6868
{
69-
r.addRef();
69+
r.RefCounted::addRef();
7070
}
7171

7272
~Reference()
7373
{
7474
try {
75-
r.release();
75+
r.RefCounted::release();
7676
}
7777
catch (const Exception&)
7878
{

src/jrd/trace/TraceConfigStorage.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ void checkFileError(const char* filename, const char* operation, ISC_STATUS iscE
7979
#endif
8080
}
8181

82-
ConfigStorage::ConfigStorage()
82+
ConfigStorage::ConfigStorage() :
83+
m_base(NULL),
84+
m_cfg_file(-1),
85+
m_dirty(false),
86+
m_touchSemaphore(FB_NEW(*getDefaultMemoryPool()) AnyRef<Semaphore>),
87+
m_touchSemRef(*m_touchSemaphore)
8388
{
84-
m_base = NULL;
85-
m_cfg_file = -1;
86-
m_dirty = false;
87-
m_thdId = 0;
88-
8989
PathName filename;
9090
#ifdef WIN_NT
9191
DWORD sesID = 0;
@@ -120,20 +120,25 @@ ConfigStorage::ConfigStorage()
120120
status_exception::raise(status);
121121
}
122122

123-
fb_assert(m_base->version == 1);
123+
fb_assert(m_base->version == 1 || m_base->version == 2);
124124

125125
StorageGuard guard(this);
126126
checkFile();
127127
++m_base->cnt_uses;
128128

129-
gds__thread_start(touchThread, (void*) this, THREAD_medium, 0, &m_thdId);
129+
if (m_base->version == 2)
130+
{
131+
if (gds__thread_start(touchThread, (void*) this, THREAD_medium, 0, NULL))
132+
gds__log("Can't start touch thread");
133+
else
134+
m_touchStartSem.enter();
135+
}
130136
}
131137

132138
ConfigStorage::~ConfigStorage()
133139
{
134140
// signal touchThread to finish
135-
m_touchSemaphore.release();
136-
THD_wait_for_completion(m_thdId);
141+
m_touchSemaphore->Semaphore::release();
137142

138143
::close(m_cfg_file);
139144
m_cfg_file = -1;
@@ -181,7 +186,7 @@ void ConfigStorage::initShMem(void* arg, sh_mem* shmemData, bool initialize)
181186
// Initialize the shared data header
182187
if (initialize)
183188
{
184-
header->version = 1;
189+
header->version = 2;
185190
header->change_number = 0;
186191
header->session_number = 1;
187192
header->cnt_uses = 0;
@@ -311,8 +316,13 @@ THREAD_ENTRY_DECLARE ConfigStorage::touchThread(THREAD_ENTRY_PARAM arg)
311316

312317
void ConfigStorage::touchThreadFunc()
313318
{
319+
AnyRef<Semaphore>* semaphore = m_touchSemaphore;
320+
Reference semRef(*semaphore);
321+
322+
m_touchStartSem.release();
323+
314324
int delay = TOUCH_INTERVAL / 2;
315-
while (!m_touchSemaphore.tryEnter(delay))
325+
while (!semaphore->tryEnter(delay))
316326
{
317327
StorageGuard guard(this);
318328

src/jrd/trace/TraceConfigStorage.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "../../common/classes/array.h"
3232
#include "../../common/classes/fb_string.h"
3333
#include "../../common/classes/init.h"
34+
#include "../../common/classes/RefCounted.h"
3435
#include "../../common/classes/semaphore.h"
3536
#include "../../jrd/isc.h"
3637
#include "../../jrd/ThreadStart.h"
@@ -95,11 +96,11 @@ friend class StorageInstance;
9596
volatile ULONG change_number;
9697
volatile ULONG session_number;
9798
ULONG cnt_uses;
98-
time_t touch_time;
9999
char cfg_file_name[MAXPATHLEN];
100100
#ifndef WIN_NT
101101
struct mtx mutex;
102102
#endif
103+
SINT64 touch_time;
103104
};
104105

105106
// items in every session record at sessions file
@@ -125,8 +126,9 @@ friend class StorageInstance;
125126
#endif
126127
int m_cfg_file;
127128
bool m_dirty;
128-
Firebird::Semaphore m_touchSemaphore;
129-
ThreadHandle m_thdId;
129+
Firebird::Semaphore m_touchStartSem;
130+
Firebird::AnyRef<Firebird::Semaphore>* m_touchSemaphore;
131+
Firebird::Reference m_touchSemRef;
130132
};
131133

132134

0 commit comments

Comments
 (0)