8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-30 20:03:03 +01:00
firebird-mirror/src/jrd/trace/TraceLog.h

106 lines
2.2 KiB
C
Raw Normal View History

2009-02-01 23:07:35 +01:00
/*
* PROGRAM: Firebird Trace Services
* MODULE: TraceLog.h
* DESCRIPTION: Trace API shared log file
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Khorsun Vladyslav
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2008 Khorsun Vladyslav <hvlad@users.sourceforge.net>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*/
#ifndef TRACE_LOG
#define TRACE_LOG
#include "../../common/classes/fb_string.h"
#include "../../jrd/ntrace.h"
#include "../../jrd/isc.h"
namespace Jrd {
class TraceLogImpl : public TraceLogWriter
{
public:
2009-02-02 15:46:24 +01:00
TraceLogImpl(Firebird::MemoryPool& pool, const Firebird::PathName& fileName, bool reader);
2009-02-01 23:07:35 +01:00
virtual ~TraceLogImpl();
size_t read(void* buf, size_t size);
virtual size_t write(const void* buf, size_t size);
virtual void release()
{ delete this; }
// returns approximate log size in MB
size_t getApproxLogSize() const;
private:
static void checkMutex(const TEXT*, int);
static void initShMem(void*, SH_MEM_T*, bool);
void lock();
void unlock();
int openFile(int fileNum);
int removeFile(int fileNum);
struct ShMemHeader
{
volatile unsigned int readFileNum;
volatile unsigned int writeFileNum;
#ifndef WIN_NT
struct mtx mutex;
#endif
};
SH_MEM_T m_handle;
2009-02-02 15:46:24 +01:00
ShMemHeader* m_base;
2009-02-01 23:07:35 +01:00
#ifdef WIN_NT
struct mtx m_mutex;
#endif
Firebird::PathName m_baseFileName;
unsigned int m_fileNum;
int m_fileHandle;
bool m_reader;
friend class TraceLogGuard;
};
class TraceLogGuard
{
public:
explicit TraceLogGuard(TraceLogImpl* log) : m_log(*log)
2009-02-01 23:07:35 +01:00
{
m_log.lock();
2009-02-01 23:07:35 +01:00
}
~TraceLogGuard()
{
m_log.unlock();
2009-02-01 23:07:35 +01:00
}
private:
TraceLogImpl& m_log;
2009-02-01 23:07:35 +01:00
};
} // namespace Jrd
2009-02-02 15:46:24 +01:00
2009-02-01 23:07:35 +01:00
#endif // TRACE_LOG