static void *eb_insert(struct eb *eb) { unsigned char *p; unsigned long flags; int n, c; spin_lock_irqsave(&eb->lock, flags); p = eb->buf + (eb->in * eb->elem_size); /* in is where we want to put the frame in the buffer */ /* * Update the index to reflect the next frame to remove. * If the buffer's full, overwrite the oldest data and update the 'out' */ n = eb->in + 1; if(n >= eb->depth) n = 0; if(n == eb->out) { eb->over++; eb->out++; /* update the tail (overwrite oldest data) */ if(eb->out >= eb->depth) /* wrap the tail if needed */ eb->out = 0; } eb->in = n; /* update stats */ c = cycles(); eb->dt_in = c - eb->lastin; if(eb->dt_in < 0) eb->dt_in += INT_MAX; /* update max and maxlife */ if(eb->dt_in > eb->dt_in_max) eb->dt_in_max = eb->dt_in; if(eb->dt_in > eb->dt_in_maxlife) eb->dt_in_maxlife = eb->dt_in; eb->lastin = c; if(eb->lastop == EB_OP_INSERT) { eb->inin++; eb->dt_2in = c - eb->last2in; if(eb->dt_2in < 0) eb->dt_2in += INT_MAX; eb->last2in = c; } eb->lastop = EB_OP_INSERT; spin_unlock_irqrestore(&eb->lock, flags); return p; } static void *eb_remove(struct eb *eb) { unsigned char *p; unsigned long flags; int n, c; spin_lock_irqsave(&eb->lock, flags); p = eb->buf + (eb->out * eb->elem_size); /* out is the frame we want to pull out of the buffer */ /* update the index to reflect the next frame to remove. If the buffer's empty, don't update the pointer. */ n = eb->out + 1; if(n >= eb->depth) n = 0; if(n == eb->in) { // p = interpolate(eb); /* TODO: eventually... */ //printk("underrun...\n"); n = eb->out; eb->under++; } eb->out = n; /* update stats */ c = cycles(); eb->dt_out = c - eb->lastout; if(eb->dt_out < 0) eb->out += INT_MAX; if(eb->dt_out > eb->dt_out_max) eb->dt_out_max = eb->dt_out; if(eb->dt_out > eb->dt_out_maxlife) eb->dt_out_maxlife = eb->dt_out; eb->lastout = c; if(eb->lastop == EB_OP_REMOVE) { eb->outout++; eb->dt_2out = c - eb->last2out; if(eb->dt_2out < 0) eb->dt_2out += INT_MAX; eb->last2out = c; } eb->lastop = EB_OP_REMOVE; spin_unlock_irqrestore(&eb->lock, flags); return p; }