mirror of
https://github.com/FirebirdSQL/firebird.git
synced 2025-01-23 14:03:07 +01:00
Avoid pissible thread-safety problems. Thanks for tip to Adriano
This commit is contained in:
parent
833142dd62
commit
e369c6cec6
@ -525,12 +525,15 @@ USHORT PIO_init_data(Database* dbb, jrd_file* main_file, ISC_STATUS* status_vect
|
|||||||
// we need a class here only to return memory on shutdown and avoid
|
// we need a class here only to return memory on shutdown and avoid
|
||||||
// false memory leak reports
|
// false memory leak reports
|
||||||
static Firebird::Array<char> zero_array(*getDefaultMemoryPool());
|
static Firebird::Array<char> zero_array(*getDefaultMemoryPool());
|
||||||
|
static Firebird::Mutex mtx_zero_buff;
|
||||||
static char* zero_buff = NULL;
|
static char* zero_buff = NULL;
|
||||||
const int zero_buf_size = 1024 * 128;
|
const int zero_buf_size = 1024 * 128;
|
||||||
if (!zero_buff)
|
if (!zero_buff)
|
||||||
{
|
{
|
||||||
|
mtx_zero_buff.enter();
|
||||||
zero_buff = zero_array.getBuffer(zero_buf_size);
|
zero_buff = zero_array.getBuffer(zero_buf_size);
|
||||||
memset(zero_buff, 0, zero_buf_size);
|
memset(zero_buff, 0, zero_buf_size);
|
||||||
|
mtx_zero_buff.leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fake buffer, used in seek_file. Page space ID have no matter there
|
// Fake buffer, used in seek_file. Page space ID have no matter there
|
||||||
@ -562,22 +565,20 @@ USHORT PIO_init_data(Database* dbb, jrd_file* main_file, ISC_STATUS* status_vect
|
|||||||
SLONG to_write = write_pages * dbb->dbb_page_size;
|
SLONG to_write = write_pages * dbb->dbb_page_size;
|
||||||
SLONG written;
|
SLONG written;
|
||||||
|
|
||||||
|
for (int r = 0; r < IO_RETRY; r++)
|
||||||
{
|
{
|
||||||
for (int r = 0; r < IO_RETRY; r++)
|
if (!(file = seek_file(file, bdb, &offset, status_vector)))
|
||||||
{
|
return false;
|
||||||
if (!(file = seek_file(file, bdb, &offset, status_vector)))
|
|
||||||
return false;
|
|
||||||
#ifdef PREAD_PWRITE
|
#ifdef PREAD_PWRITE
|
||||||
if ((written = pwrite(file->fil_desc, zero_buff, to_write, LSEEK_OFFSET_CAST offset)) == to_write)
|
if ((written = pwrite(file->fil_desc, zero_buff, to_write, LSEEK_OFFSET_CAST offset)) == to_write)
|
||||||
break;
|
break;
|
||||||
#else
|
#else
|
||||||
if ((written = write(file->fil_desc, zero_buff, to_write)) == to_write)
|
if ((written = write(file->fil_desc, zero_buff, to_write)) == to_write)
|
||||||
break;
|
break;
|
||||||
THD_IO_MUTEX_UNLOCK(file->fil_mutex);
|
THD_IO_MUTEX_UNLOCK(file->fil_mutex);
|
||||||
#endif
|
#endif
|
||||||
if (written == (SLONG) -1 && !SYSCALL_INTERRUPTED(errno))
|
if (written == (SLONG) -1 && !SYSCALL_INTERRUPTED(errno))
|
||||||
return unix_error("write", file, isc_io_write_err, status_vector);
|
return unix_error("write", file, isc_io_write_err, status_vector);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef PREAD_PWRITE
|
#ifndef PREAD_PWRITE
|
||||||
|
@ -592,12 +592,15 @@ USHORT PIO_init_data(Database* dbb, jrd_file* main_file, ISC_STATUS* status_vect
|
|||||||
// we need a class here only to return memory on shutdown and avoid
|
// we need a class here only to return memory on shutdown and avoid
|
||||||
// false memory leak reports
|
// false memory leak reports
|
||||||
static Firebird::Array<char> zero_array(*getDefaultMemoryPool());
|
static Firebird::Array<char> zero_array(*getDefaultMemoryPool());
|
||||||
|
static Firebird::Mutex mtx_zero_buff;
|
||||||
static char* zero_buff = NULL;
|
static char* zero_buff = NULL;
|
||||||
const int zero_buf_size = 1024 * 128;
|
const int zero_buf_size = 1024 * 128;
|
||||||
if (!zero_buff)
|
if (!zero_buff)
|
||||||
{
|
{
|
||||||
|
mtx_zero_buff.enter();
|
||||||
zero_buff = zero_array.getBuffer(zero_buf_size);
|
zero_buff = zero_array.getBuffer(zero_buf_size);
|
||||||
memset(zero_buff, 0, zero_buf_size);
|
memset(zero_buff, 0, zero_buf_size);
|
||||||
|
mtx_zero_buff.leave();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileExtendLockGuard extLock(NULL,
|
FileExtendLockGuard extLock(NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user