Skip to content

Commit

Permalink
reader-cryptotokenkit: support thread-wise separation
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Mar 19, 2020
1 parent dc29b0f commit ae80fb5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libopensc/reader-cryptotokenkit.m
Expand Up @@ -32,6 +32,7 @@
struct cryptotokenkit_private_data {
TKSmartCardSlot* tksmartcardslot;
TKSmartCard* tksmartcard;
dispatch_semaphore_t sema_lock;
};

static struct sc_reader_operations cryptotokenkit_ops;
Expand Down Expand Up @@ -219,6 +220,8 @@ static int cryptotokenkit_lock(sc_reader_t *reader)
goto err;
}

dispatch_semaphore_wait(priv->sema_lock, DISPATCH_TIME_FOREVER);

[priv->tksmartcard beginSessionWithReply:^(BOOL success, NSError *error) {
if (success != TRUE) {
r = convertError(error);
Expand All @@ -244,6 +247,8 @@ static int cryptotokenkit_unlock(sc_reader_t *reader)

[priv->tksmartcard endSession];

dispatch_semaphore_signal(priv->sema_lock);

LOG_FUNC_RETURN(reader->ctx, SC_SUCCESS);
}

Expand Down Expand Up @@ -495,6 +500,8 @@ int cryptotokenkit_use_reader(sc_context_t *ctx, void *pcsc_context_handle, void
priv->tksmartcard = [tksmartcard retain];
[priv->tksmartcardslot autorelease];
priv->tksmartcardslot = [tksmartcardslot retain];
[priv->sema_lock autorelease];
priv->sema_lock = dispatch_semaphore_create(1);

reader->drv_data = priv;
reader->ops = &cryptotokenkit_ops;
Expand Down

0 comments on commit ae80fb5

Please sign in to comment.