Merging upstream version 0.8.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
78a0eaf2b7
commit
211f2dec81
15 changed files with 391 additions and 272 deletions
|
@ -1,6 +1,6 @@
|
|||
/* Plzip - A parallel compressor compatible with lzip
|
||||
Copyright (C) 2009 Laszlo Ersek.
|
||||
Copyright (C) 2009, 2010 Antonio Diaz Diaz.
|
||||
Copyright (C) 2009, 2010, 2011, 2012 Antonio Diaz Diaz.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
|
@ -73,6 +73,9 @@ private:
|
|||
pthread_cond_t slot_av; // free output slot available
|
||||
bool eof; // splitter done
|
||||
|
||||
Packet_courier( const Packet_courier & ); // declared as private
|
||||
void operator=( const Packet_courier & ); // declared as private
|
||||
|
||||
public:
|
||||
Packet_courier( const int workers, const int slots )
|
||||
: icheck_counter( 0 ), iwait_counter( 0 ),
|
||||
|
@ -82,14 +85,14 @@ public:
|
|||
opacket_queues( workers ), num_working( workers ),
|
||||
num_workers( workers ), num_free( 8 * slots ), eof( false )
|
||||
{
|
||||
xinit( &iav_or_eof, &imutex );
|
||||
xinit( &oav_or_exit, &omutex ); xinit( &slot_av, 0 );
|
||||
xinit( &imutex ); xinit( &iav_or_eof );
|
||||
xinit( &omutex ); xinit( &oav_or_exit ); xinit( &slot_av );
|
||||
}
|
||||
|
||||
~Packet_courier()
|
||||
{
|
||||
xdestroy( &iav_or_eof, &imutex );
|
||||
xdestroy( &oav_or_exit, &omutex ); xdestroy( &slot_av, 0 );
|
||||
xdestroy( &slot_av ); xdestroy( &oav_or_exit ); xdestroy( &omutex );
|
||||
xdestroy( &iav_or_eof ); xdestroy( &imutex );
|
||||
}
|
||||
|
||||
const Slot_tally & tally() const { return slot_tally; }
|
||||
|
@ -207,6 +210,29 @@ public:
|
|||
};
|
||||
|
||||
|
||||
// Search forward from 'pos' for "LZIP" (Boyer-Moore algorithm)
|
||||
// Return pos of found string or 'pos+size' if not found.
|
||||
//
|
||||
int find_magic( const uint8_t * const buffer, const int pos, const int size ) throw()
|
||||
{
|
||||
const uint8_t table[256] = {
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,1,4,4,3,4,4,4,4,4,4,4,4,4,4,4,4,4,2,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
|
||||
4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 };
|
||||
|
||||
for( int i = pos; i <= pos + size - 4; i += table[buffer[i+3]] )
|
||||
if( buffer[i] == 'L' && buffer[i+1] == 'Z' &&
|
||||
buffer[i+2] == 'I' && buffer[i+3] == 'P' )
|
||||
return i; // magic string found
|
||||
return pos + size;
|
||||
}
|
||||
|
||||
|
||||
struct Splitter_arg
|
||||
{
|
||||
Packet_courier * courier;
|
||||
|
@ -235,8 +261,7 @@ extern "C" void * dsplitter( void * arg )
|
|||
bool at_stream_end = ( size < buffer_size );
|
||||
if( size != buffer_size && errno )
|
||||
{ pp(); show_error( "Read error", errno ); fatal(); }
|
||||
if( size <= tsize || buffer[0] != 'L' || buffer[1] != 'Z' ||
|
||||
buffer[2] != 'I' || buffer[3] != 'P' )
|
||||
if( size <= tsize || find_magic( buffer, 0, 4 ) != 0 )
|
||||
{ pp( "Bad magic number (file not in lzip format)" ); fatal(); }
|
||||
|
||||
long long partial_member_size = 0;
|
||||
|
@ -244,15 +269,16 @@ extern "C" void * dsplitter( void * arg )
|
|||
{
|
||||
int pos = 0;
|
||||
for( int newpos = 1; newpos <= size; ++newpos )
|
||||
if( buffer[newpos] == 'L' && buffer[newpos+1] == 'Z' &&
|
||||
buffer[newpos+2] == 'I' && buffer[newpos+3] == 'P' )
|
||||
{
|
||||
newpos = find_magic( buffer, newpos, size + 4 - newpos );
|
||||
if( newpos <= size )
|
||||
{
|
||||
long long member_size = 0;
|
||||
for( int i = 1; i <= 8; ++i )
|
||||
{ member_size <<= 8; member_size += base_buffer[tsize+newpos-i]; }
|
||||
if( partial_member_size + newpos - pos == member_size )
|
||||
{ // header found
|
||||
uint8_t * data = new( std::nothrow ) uint8_t[newpos - pos];
|
||||
uint8_t * const data = new( std::nothrow ) uint8_t[newpos - pos];
|
||||
if( data == 0 ) { pp( "Not enough memory" ); fatal(); }
|
||||
std::memcpy( data, buffer + pos, newpos - pos );
|
||||
courier.receive_packet( data, newpos - pos );
|
||||
|
@ -261,6 +287,7 @@ extern "C" void * dsplitter( void * arg )
|
|||
pos = newpos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( at_stream_end )
|
||||
{
|
||||
|
@ -317,7 +344,7 @@ extern "C" void * dworker( void * arg )
|
|||
|
||||
while( true )
|
||||
{
|
||||
Packet * ipacket = courier.distribute_packet( worker_id );
|
||||
const Packet * const ipacket = courier.distribute_packet( worker_id );
|
||||
if( ipacket == 0 ) break; // no more packets to process
|
||||
if( ipacket->data == 0 ) LZ_decompress_finish( decoder );
|
||||
|
||||
|
@ -362,7 +389,7 @@ extern "C" void * dworker( void * arg )
|
|||
}
|
||||
if( LZ_decompress_finished( decoder ) == 1 )
|
||||
{
|
||||
LZ_decompress_reset( decoder );
|
||||
LZ_decompress_reset( decoder ); // prepare for new ipacket
|
||||
Packet * opacket = new Packet; // end of member token
|
||||
opacket->data = 0;
|
||||
opacket->size = 0;
|
||||
|
@ -379,9 +406,10 @@ extern "C" void * dworker( void * arg )
|
|||
}
|
||||
|
||||
delete[] new_data;
|
||||
if( LZ_decompress_total_in_size( decoder ) != 0 )
|
||||
if( LZ_decompress_member_position( decoder ) != 0 )
|
||||
{ pp( "Error, some data remains in decoder" ); fatal(); }
|
||||
LZ_decompress_close( decoder );
|
||||
if( LZ_decompress_close( decoder ) < 0 )
|
||||
{ pp( "LZ_decompress_close failed" ); fatal(); }
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -413,10 +441,13 @@ void muxer( Packet_courier & courier, const Pretty_print & pp, const int outfd )
|
|||
|
||||
// init the courier, then start the splitter and the workers and
|
||||
// call the muxer.
|
||||
int decompress( const int num_workers, const int num_slots,
|
||||
const int infd, const int outfd, const Pretty_print & pp,
|
||||
const int debug_level, const bool testing )
|
||||
int decompress( const int num_workers, const int infd, const int outfd,
|
||||
const Pretty_print & pp, const int debug_level,
|
||||
const bool testing )
|
||||
{
|
||||
const int slots_per_worker = 2;
|
||||
const int num_slots = ( ( INT_MAX / num_workers >= slots_per_worker ) ?
|
||||
num_workers * slots_per_worker : INT_MAX );
|
||||
in_size = 0;
|
||||
out_size = 0;
|
||||
Packet_courier courier( num_workers, num_slots );
|
||||
|
@ -460,6 +491,11 @@ int decompress( const int num_workers, const int num_slots,
|
|||
if( errcode )
|
||||
{ show_error( "Can't join splitter thread", errcode ); fatal(); }
|
||||
|
||||
if( verbosity >= 3 && out_size > 0 && in_size > 0 )
|
||||
std::fprintf( stderr, "%6.3f:1, %6.3f bits/byte, %5.2f%% saved. ",
|
||||
(double)out_size / in_size,
|
||||
( 8.0 * in_size ) / out_size,
|
||||
100.0 * ( 1.0 - ( (double)in_size / out_size ) ) );
|
||||
if( verbosity >= 2 )
|
||||
std::fprintf( stderr, "decompressed size %9lld, size %9lld. ",
|
||||
out_size, in_size );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue