Skip to content

Commit

Permalink
front-ported fox for CORE-1098
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPeshkoff committed Jan 18, 2007
1 parent 1881afc commit a13e291
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/jrd/cch.cpp
Expand Up @@ -1257,6 +1257,14 @@ void CCH_fini(thread_db* tdbb)

#ifdef CACHE_WRITER

/* Wait for cache writer startup to complete. */
while ((bcb = dbb->dbb_bcb) && (bcb->bcb_flags & BCB_writer_start))
{
THREAD_EXIT();
THREAD_YIELD();
THREAD_ENTER();
}

/* Shutdown the dedicated cache writer for this database. */

if ((bcb = dbb->dbb_bcb) && (bcb->bcb_flags & BCB_cache_writer)) {
Expand Down Expand Up @@ -1755,13 +1763,18 @@ void CCH_init(thread_db* tdbb, ULONG number)
#ifdef CACHE_WRITER
if (!(dbb->dbb_flags & DBB_read_only)) {
event_t* event = dbb->dbb_writer_event_init;

// writer startup in progress
bcb->bcb_flags |= BCB_writer_start;

/* Initialize initialization event */
ISC_event_init(event, 0, 0);
count = ISC_event_clear(event);

if (gds__thread_start(cache_writer, dbb,
THREAD_high, 0, 0))
{
bcb->bcb_flags &= ~BCB_writer_start;
ERR_bugcheck_msg("cannot start thread");
}
THREAD_EXIT();
Expand Down Expand Up @@ -4054,22 +4067,24 @@ static THREAD_ENTRY_DECLARE cache_writer(THREAD_ENTRY_PARAM arg)
LCK_init fails we won't be able to accomplish anything anyway, so
return, unlike the other try blocks further down the page. */
event_t* writer_event = 0;
BufferControl* bcb = 0;
BufferControl* bcb = dbb->dbb_bcb;

try {
writer_event = dbb->dbb_writer_event;
ISC_event_init(writer_event, 0, 0);
LCK_init(tdbb, LCK_OWNER_attachment);
bcb = dbb->dbb_bcb;
bcb->bcb_flags |= BCB_cache_writer;
bcb->bcb_flags &= ~BCB_writer_start;

/* Notify our creator that we have started */
ISC_event_post(dbb->dbb_writer_event_init);
}
catch (const Firebird::Exception& ex) {
Firebird::stuff_exception(status_vector, ex);
gds__log_status(dbb->dbb_filename.c_str(), status_vector);

ISC_event_fini(writer_event);
bcb->bcb_flags &= ~(BCB_cache_writer | BCB_writer_start);
THREAD_EXIT();
return (THREAD_ENTRY_RETURN)(-1);
}
Expand All @@ -4085,6 +4100,7 @@ static THREAD_ENTRY_DECLARE cache_writer(THREAD_ENTRY_PARAM arg)
THREAD_EXIT();
ISC_event_wait(1, &writer_event, &count, 10 * 1000000, NULL, 0);
THREAD_ENTER();
bcb = dbb->dbb_bcb;
continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/jrd/cch.h
Expand Up @@ -90,6 +90,7 @@ class BufferControl : public pool_alloc_rpt<bcb_repeat, type_bcb>
const int BCB_keep_pages = 1; /* set during btc_flush(), pages not removed from dirty binary tree */
const int BCB_cache_writer = 2; /* cache writer thread has been started */
//const int BCB_checkpoint_db = 4; // WAL has requested a database checkpoint
const int BCB_writer_start = 4; // cache writer thread is starting now
const int BCB_writer_active = 8; /* no need to post writer event count */
#ifdef SUPERSERVER_V2
const int BCB_cache_reader = 16; /* cache reader thread has been started */
Expand Down

0 comments on commit a13e291

Please sign in to comment.