comparison src/c/urweb.c @ 2001:16f5f136a807

uw_register_transactional() can return error codes
author Adam Chlipala <adam@chlipala.net>
date Thu, 17 Apr 2014 17:41:24 -0400
parents bddee3af70c4
children 93ff76058825
comparison
equal deleted inserted replaced
2000:bddee3af70c4 2001:16f5f136a807
3467 } 3467 }
3468 3468
3469 3469
3470 size_t uw_transactionals_max = SIZE_MAX; 3470 size_t uw_transactionals_max = SIZE_MAX;
3471 3471
3472 void uw_register_transactional(uw_context ctx, void *data, uw_callback commit, uw_callback rollback, 3472 int uw_register_transactional(uw_context ctx, void *data, uw_callback commit, uw_callback rollback,
3473 uw_callback_with_retry free) { 3473 uw_callback_with_retry free) {
3474 if (ctx->used_transactionals >= ctx->n_transactionals) { 3474 if (ctx->used_transactionals >= ctx->n_transactionals) {
3475 if (ctx->used_transactionals+1 > uw_transactionals_max) 3475 if (ctx->used_transactionals+1 > uw_transactionals_max)
3476 uw_error(ctx, FATAL, "Exceeded limit on number of transactionals"); 3476 // Exceeded limit on number of transactionals.
3477 return -1;
3477 ctx->transactionals = realloc(ctx->transactionals, sizeof(transactional) * (ctx->used_transactionals+1)); 3478 ctx->transactionals = realloc(ctx->transactionals, sizeof(transactional) * (ctx->used_transactionals+1));
3478 ++ctx->n_transactionals; 3479 ++ctx->n_transactionals;
3479 } 3480 }
3480 3481
3481 ctx->transactionals[ctx->used_transactionals].data = data; 3482 ctx->transactionals[ctx->used_transactionals].data = data;
3482 ctx->transactionals[ctx->used_transactionals].commit = commit; 3483 ctx->transactionals[ctx->used_transactionals].commit = commit;
3483 ctx->transactionals[ctx->used_transactionals].rollback = rollback; 3484 ctx->transactionals[ctx->used_transactionals].rollback = rollback;
3484 ctx->transactionals[ctx->used_transactionals++].free = free; 3485 ctx->transactionals[ctx->used_transactionals++].free = free;
3486
3487 return 0;
3485 } 3488 }
3486 3489
3487 3490
3488 // "Garbage collection" 3491 // "Garbage collection"
3489 3492