CNMAT / CNMAT-Externs

CNMAT Max/MSP externals
Other
96 stars 11 forks source link

sdif-buffer: evaluate safety of [timeshift] message #76

Closed equilet closed 5 years ago

equilet commented 6 years ago
void SDIFbuffer_timeShift(SDIFBuffer *x) {
    SDIFBufferPrivate *privateStuff = (SDIFBufferPrivate *) x->internal;

    SDIFbuf_TimeShiftToZero(privateStuff->buf);
}

// ----->

SDIFresult SDIFbuf_TimeShiftToZero(SDIFbuf_Buffer b)
{
  SDIFmem_Frame f;
  sdif_float64 tMin;

  if(!(f = SDIFbuf_GetFirstFrame(b)))
    //  no frames in buffer -- we're done
    return ESDIF_SUCCESS;

  tMin = f->header.time;

  //  this loop couldn't be any less thread safe  
  while(f)
  {
    f->header.time -= tMin;
    f = SDIFbuf_GetNextFrame(f);
  }

  return ESDIF_SUCCESS;
}

The comment this loop couldn't be any less thread safe is obviously concerning; we should evaluate whether or not we should employ something like a thread lock here.

ramagottfried commented 6 years ago

added a lock for this, please give it a test