2 # Finite size ring buffer creation and access routines
4 # Copyright (c) - 1998 Dirk Koopman G1TLH
13 use vars qw($VERSION $BRANCH);
14 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
15 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
16 $main::build += $VERSION;
17 $main::branch += $BRANCH;
31 return bless [$size, 0, 0, 0, 0, []], (ref $pkg || $pkg);
38 $self->[5]->[$self->[2]++] = shift;
39 $self->[2] = 0 if $self->[2] >= $self->[0];
40 if ($self->[1] < $self->[0]) {
41 $self->[1] = ++$self->[1];
43 $self->[2] = $self->[2];
44 if ($self->[1] == $self->[0] && $self->[2] == $self->[3]) {
45 $self->[3] = $self->[2]+1;
46 $self->[3] = 0 if $self->[3] >= $self->[0];
53 return unless $self->[1];
56 if ($self->[4] != $self->[2]) {
57 $r = $self->[5]->[$self->[4]++];
58 $self->[4] = 0 if $self->[4] >= $self->[0];
66 $self->[4] = $self->[3];
81 while (my $r = $self->read) {