Skip to content

Commit

Permalink
Don't mark buffers as allocated until the end.
Browse files Browse the repository at this point in the history
This was lock-free nonsense, so it can go away now.
  • Loading branch information
icculus committed Jun 28, 2019
1 parent 2b55449 commit ecd231a
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions mojoal.c
Expand Up @@ -4138,14 +4138,11 @@ static void _alGenBuffers(const ALsizei n, ALuint *names)
block->tmp = 0;
if (block->used < SDL_arraysize(block->buffers)) { /* skip if full */
for (i = 0; i < SDL_arraysize(block->buffers); i++) {
FIXME("doesn't have to be 2 now, since API access is serialized");
if (SDL_AtomicCAS(&block->buffers[i].allocated, 0, 2)) { /* 0==unused, 1==in use, 2==trying to acquire. */
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
}

Expand Down Expand Up @@ -4178,24 +4175,17 @@ static void _alGenBuffers(const ALsizei n, ALuint *names)
ctx->device->playback.num_buffer_blocks++;

for (i = 0; i < SDL_arraysize(block->buffers); i++) {
FIXME("doesn't have to be 2 now, since API access is serialized");
if (SDL_AtomicCAS(&block->buffers[i].allocated, 0, 2)) { /* 0==unused, 1==in use, 2==trying to acquire. */
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
block->tmp++;
objects[found] = &block->buffers[i];
names[found++] = (i + block_offset) + 1; /* +1 so it isn't zero. */
if (found == n) {
break;
}
}
block_offset += SDL_arraysize(block->buffers);
}

if (out_of_memory) {
FIXME("just officially acquire at the end now that we're serialized");
for (i = 0; i < found; i++) {
SDL_AtomicSet(&objects[i]->allocated, 0); /* return any temp-acquired buffers. */
}
if (objects != stackobjs) SDL_free(objects);
SDL_memset(names, '\0', sizeof (*names) * n);
set_al_error(ctx, AL_OUT_OF_MEMORY);
Expand All @@ -4221,14 +4211,10 @@ static void _alGenBuffers(const ALsizei n, ALuint *names)

for (i = 0; i < n; i++) {
ALbuffer *buffer = objects[i];
/* don't SDL_zerop() this buffer, because we need buffer->allocated to stay at 2 until initialized. */
SDL_zerop(buffer);
buffer->name = names[i];
buffer->channels = 1;
buffer->bits = 16;
buffer->frequency = 0;
buffer->len = 0;
buffer->data = NULL;
SDL_AtomicSet(&buffer->refcount, 0);
SDL_AtomicSet(&buffer->allocated, 1); /* we officially own it. */
}

Expand Down

0 comments on commit ecd231a

Please sign in to comment.