Kitura / SwiftKafka

Swift SDK for Apache Kafka
60 stars 19 forks source link

Add locking around dictionary as computed property #3

Closed djones6 closed 5 years ago

djones6 commented 5 years ago

KafkaProducer.kafkaHandleToMessageCallback is a dictionary that is accessed by multiple threads. The code in KafkaProducer used a semaphore to prevent concurrent access, but this was missed in accesses outside of that class (such as in KafkaConfig.setDeliveredMessageCallback()).

This replaces the semaphore with a computed property and NSLock approach similar to https://github.com/IBM-Swift/LoggerAPI/pull/47 .

djones6 commented 5 years ago

As discussed, closing as the (now fixed) semaphore approach is much faster.