Improve journaling... Add transactions.

This commit is contained in:
Jonathan Moore Liles 2008-02-24 04:04:14 -06:00
parent 66414fe6b8
commit 49628da177
3 changed files with 54 additions and 9 deletions

View File

@ -27,6 +27,7 @@
FILE *Loggable::_fp;
int Loggable::_log_id = 0;
int Loggable::_level = 0;
vector <Loggable *> Loggable::_loggables;
@ -92,11 +93,11 @@ log_print( char **o, char **n )
/** compare elements of dumps s1 and s2, removing those elements
of dst which are not changed from src */
static
void
bool
log_diff ( char **sa1, char **sa2 )
{
if ( ! sa1 )
return;
return true;
int w = 0;
for ( int i = 0; sa1[ i ]; ++i )
@ -117,6 +118,8 @@ log_diff ( char **sa1, char **sa2 )
sa1[ w ] = NULL;
sa2[ w ] = NULL;
return w == 0 ? false : true;
}
@ -126,8 +129,12 @@ log_diff ( char **sa1, char **sa2 )
void
Loggable::log_start ( void )
{
if ( ! _old_state )
_old_state = log_dump();
// if ( _old_state )
// log_end();
if ( _old_state )
return;
_old_state = log_dump();
}
void
@ -137,11 +144,13 @@ Loggable::log_end ( void )
// if ( _old_state )
log_diff( _old_state, _new_state );
if ( log_diff( _old_state, _new_state ) )
{
indent();
printf( "%s 0x%X set ", class_name(), _id );
printf( "%s 0x%X set ", class_name(), _id );
log_print( _old_state, _new_state );
log_print( _old_state, _new_state );
}
free_sa( _old_state );
if ( _new_state )
@ -153,6 +162,7 @@ Loggable::log_end ( void )
void
Loggable::log_create ( void )
{
indent();
printf( "%s 0x%X new ", class_name(), _id );
char **sa = log_dump();
@ -165,6 +175,7 @@ Loggable::log_create ( void )
void
Loggable::log_destroy ( void )
{
indent();
printf( "%s 0x%X destroy ", class_name(), _id );
char **sa = log_dump();

View File

@ -24,7 +24,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <vector>
using std::vector;
@ -34,6 +34,7 @@ class Loggable
static FILE *_fp;
static int _log_id;
static int _level;
static vector <Loggable *> _loggables;
@ -43,10 +44,36 @@ private:
char **_old_state;
char **_new_state;
static
void indent ( void )
{
int n = Loggable::_level;
while ( n-- )
printf( "\t" );
}
public:
static bool open ( const char *filename );
static
void
block_start ( void )
{
indent();
printf( "{\n" );
++Loggable::_level;
}
static
void
block_end ( void )
{
assert( --Loggable::_level >= 0 );
indent();
printf( "}\n" );
}
static
Loggable *

View File

@ -184,12 +184,19 @@ Region::handle ( int m )
/* split */
if ( ! copied )
{
Loggable::block_start();
Region *copy = new Region( *this );
trim( RIGHT, X );
copy->trim( LEFT, X );
_track->add( copy );
log_end();
Loggable::block_end();
return 1;
}
}
default: