sc_mutex_destroy should have a return value

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2832 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
nils 2006-02-05 19:35:55 +00:00
parent ca2a5e11fd
commit 8e77e87551
7 changed files with 38 additions and 20 deletions

View File

@ -87,8 +87,11 @@ static void sc_card_free(sc_card_t *card)
free(card->ops);
if (card->algorithms != NULL)
free(card->algorithms);
if (card->mutex != NULL)
sc_mutex_destroy(card->ctx, card->mutex);
if (card->mutex != NULL) {
int r = sc_mutex_destroy(card->ctx, card->mutex);
if (r != SC_SUCCESS)
sc_error(card->ctx, "unable to destroy mutex\n");
}
sc_mem_clear(card, sizeof(*card));
free(card);
}

View File

@ -158,7 +158,7 @@ ctbcs_pin_cmd(sc_reader_t *reader, sc_slot_info_t *slot,
sc_card_t dummy_card, *card;
sc_apdu_t apdu;
struct sc_card_operations ops;
int r;
int r, s;
switch (data->cmd) {
case SC_PIN_CMD_VERIFY:
@ -185,7 +185,11 @@ ctbcs_pin_cmd(sc_reader_t *reader, sc_slot_info_t *slot,
card = &dummy_card;
r = sc_transmit_apdu(card, &apdu);
sc_mutex_destroy(reader->ctx, card->mutex);
s = sc_mutex_destroy(reader->ctx, card->mutex);
if (s != SC_SUCCESS) {
sc_error(reader->ctx, "unable to destroy mutex\n");
return s;
}
SC_TEST_RET(card->ctx, r, "APDU transmit failed");
/* Check CTBCS status word */

View File

@ -746,16 +746,21 @@ int sc_release_context(sc_context_t *ctx)
if (drv->atr_map)
_sc_free_atr(ctx, drv);
}
if (ctx->preferred_language != NULL)
free(ctx->preferred_language);
if (ctx->mutex != NULL) {
int r = sc_mutex_destroy(ctx, ctx->mutex);
if (r != SC_SUCCESS) {
sc_error(ctx, "unable to destroy mutex\n");
return r;
}
}
if (ctx->conf != NULL)
scconf_free(ctx->conf);
if (ctx->debug_file && ctx->debug_file != stdout)
fclose(ctx->debug_file);
if (ctx->error_file && ctx->error_file != stderr)
fclose(ctx->error_file);
if (ctx->preferred_language != NULL)
free(ctx->preferred_language);
if (ctx->conf != NULL)
scconf_free(ctx->conf);
if (ctx->mutex != NULL)
sc_mutex_destroy(ctx, ctx->mutex);
if (ctx->app_name != NULL)
free(ctx->app_name);
sc_mem_clear(ctx, sizeof(*ctx));

View File

@ -148,8 +148,9 @@ int sc_mutex_unlock(const sc_context_t *ctx, void *mutex);
* SC_SUCCESS.
* @param ctx sc_context_t object with the thread context
* @param mutex mutex object to be destroyed
* @return SC_SUCCESS on success and an error code otherwise
*/
void sc_mutex_destroy(const sc_context_t *ctx, void *mutex);
int sc_mutex_destroy(const sc_context_t *ctx, void *mutex);
/**
* Returns a unique id for every thread.
* @param ctx sc_context_t object with the thread context

View File

@ -629,7 +629,7 @@ typedef struct {
/** unlocks a mutex object */
int (*unlock_mutex)(void *);
/** destroys a mutex object */
void (*destroy_mutex)(void *);
int (*destroy_mutex)(void *);
/** returns unique identifier for the thread (can be NULL) */
unsigned long (*thread_id)(void);
} sc_thread_context_t;

View File

@ -705,12 +705,14 @@ int sc_mutex_unlock(const sc_context_t *ctx, void *mutex)
return SC_SUCCESS;
}
void sc_mutex_destroy(const sc_context_t *ctx, void *mutex)
int sc_mutex_destroy(const sc_context_t *ctx, void *mutex)
{
if (ctx == NULL || ctx->thread_ctx == NULL ||
ctx->thread_ctx->destroy_mutex == NULL)
return;
ctx->thread_ctx->destroy_mutex(mutex);
if (ctx == NULL)
return SC_ERROR_INVALID_ARGUMENTS;
if (ctx->thread_ctx != NULL && ctx->thread_ctx->destroy_mutex != NULL)
return ctx->thread_ctx->destroy_mutex(mutex);
else
return SC_SUCCESS;
}
unsigned long sc_thread_id(const sc_context_t *ctx)

View File

@ -151,11 +151,14 @@ static int sc_unlock_mutex(void *m)
}
static void sc_destroy_mutex(void *m)
static int sc_destroy_mutex(void *m)
{
if (_locking == NULL)
return;
_locking->DestroyMutex(m);
return SC_SUCCESS;
if (_locking->DestroyMutex(m) == CKR_OK)
return SC_SUCCESS;
else
return SC_ERROR_INTERNAL;
}
static sc_thread_context_t sc_thread_ctx = {