Skip to content

Commit 40f782a

Browse files
committed
Backported fix for CORE-5452: Segfault when engine's dynamic library is unloaded right after closing worker threads (GC and/or cache writer)
1 parent c112d5d commit 40f782a

35 files changed

Lines changed: 182 additions & 99 deletions

src/alice/alice_meta.epp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include "firebird.h"
3131
#include <stdio.h>
3232
#include "../jrd/ibase.h"
33-
//#include "../jrd/license.h"
3433
#include "../alice/alice.h"
3534
#include "../alice/alice_meta.h"
3635
#include "../yvalve/gds_proto.h"

src/burp/burp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,8 +769,6 @@ struct burp_meta_obj
769769
// I need to review if we tolerate different lengths for different OS's here.
770770
const unsigned int MAX_FILE_NAME_SIZE = 256;
771771

772-
//#include "../jrd/svc.h"
773-
774772
#include "../burp/std_desc.h"
775773

776774
#ifdef WIN_NT

src/common/ThreadStart.h

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define JRD_THREADSTART_H
3232

3333
#include "../common/ThreadData.h"
34+
#include "../common/classes/semaphore.h"
3435

3536
#ifdef WIN_NT
3637
#include <windows.h>
@@ -89,4 +90,89 @@ inline ThreadId getThreadId()
8990
return Thread::getId();
9091
}
9192

93+
94+
#ifndef USE_POSIX_THREADS
95+
#define USE_FINI_SEM
96+
#endif
97+
98+
template <typename TA>
99+
class ThreadFinishSync
100+
{
101+
public:
102+
typedef void ThreadRoutine(TA);
103+
104+
ThreadFinishSync(Firebird::MemoryPool& pool, ThreadRoutine* routine, int priority_arg)
105+
:
106+
#ifdef USE_FINI_SEM
107+
fini(pool),
108+
#else
109+
threadHandle(0),
110+
#endif
111+
threadRoutine(routine),
112+
threadPriority(priority_arg)
113+
{ }
114+
115+
void run(TA arg)
116+
{
117+
threadArg = arg;
118+
119+
Thread::start(internalRun, this, threadPriority
120+
#ifndef USE_FINI_SEM
121+
, &threadHandle
122+
#endif
123+
);
124+
}
125+
126+
void waitForCompletion()
127+
{
128+
#ifdef USE_FINI_SEM
129+
fini.enter();
130+
#else
131+
Thread::waitForCompletion(threadHandle);
132+
threadHandle = 0;
133+
#endif
134+
}
135+
136+
private:
137+
#ifdef USE_FINI_SEM
138+
Firebird::Semaphore fini;
139+
#else
140+
Thread::Handle threadHandle;
141+
#endif
142+
143+
TA threadArg;
144+
ThreadRoutine* threadRoutine;
145+
int threadPriority;
146+
bool starting;
147+
148+
static THREAD_ENTRY_DECLARE internalRun(THREAD_ENTRY_PARAM arg)
149+
{
150+
((ThreadFinishSync*)arg)->internalRun();
151+
return 0;
152+
}
153+
154+
void internalRun()
155+
{
156+
try
157+
{
158+
threadRoutine(threadArg);
159+
}
160+
catch (const Firebird::Exception& ex)
161+
{
162+
threadArg->exceptionHandler(ex, threadRoutine);
163+
}
164+
165+
#ifdef USE_FINI_SEM
166+
try
167+
{
168+
fini.release();
169+
}
170+
catch (const Firebird::Exception& ex)
171+
{
172+
threadArg->exceptionHandler(ex, threadRoutine);
173+
}
174+
#endif
175+
}
176+
};
177+
92178
#endif // JRD_THREADSTART_H

src/common/classes/Synchronize.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
#define CLASSES_SYNCHRONIZE_H
3434

3535
#include "../common/classes/SyncObject.h"
36-
37-
#ifndef WIN_NT
38-
#include "fb_pthread.h"
39-
#endif
36+
#include "../common/ThreadStart.h"
4037

4138

4239
namespace Firebird {

src/common/classes/misc/class_perf.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929
#include "tree.h"
3030
#include "alloc.h"
31-
//#include "../memory/memory_pool.h"
3231
#include <stdio.h>
3332
#include <time.h>
3433
#include <set>

src/common/xdr.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@
2626

2727
#include "firebird.h"
2828
#include <string.h>
29-
//#include "../remote/remote.h"
3029
#include "../common/xdr.h"
31-
//#include "../remote/proto_proto.h"
3230
#include "../common/xdr_proto.h"
3331
#include "../yvalve/gds_proto.h"
3432
#include "../common/gdsassert.h"

src/gpre/boot/gpre_meta_boot.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <string.h>
3333
#include "../jrd/ibase.h"
3434
#include "../gpre/gpre.h"
35-
//#include "../jrd/license.h"
3635
#include "../jrd/intl.h"
3736
#include "../gpre/gpre_proto.h"
3837
#include "../gpre/hsh_proto.h"

src/gpre/std/gpre_meta.epp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <string.h>
3333
#include "../jrd/ibase.h"
3434
#include "../gpre/gpre.h"
35-
//#include "../jrd/license.h"
3635
#include "../jrd/intl.h"
3736
#include "../gpre/gpre_proto.h"
3837
#include "../gpre/hsh_proto.h"

src/include/fb_exception.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
#include "fb_types.h"
4545
#include "firebird/Interface.h"
46-
#include "../common/ThreadStart.h"
4746

4847
namespace Firebird
4948
{

src/include/firebird.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@
6868

6969
#ifdef __cplusplus
7070
#include "../common/common.h"
71-
//#include "fb_exception.h"
7271
#endif
7372

7473
#ifndef NULL

0 commit comments

Comments
 (0)