diff options
author | Kevin Greenan <kmgreen2@gmail.com> | 2014-08-16 17:10:26 -0700 |
---|---|---|
committer | Kevin Greenan <kmgreen2@gmail.com> | 2014-08-16 17:10:26 -0700 |
commit | 3338e25b9faeab6a9b3cd34c6f86865f4e0fa687 (patch) | |
tree | e0d2e89fa8623577618c559b6a9a3255250c2571 | |
parent | 120e5ec42360f876a8a040be5cc51f87e34ac98d (diff) | |
parent | 9c6ba636ec1dbd931c69ef93b28534d1ab9f3925 (diff) | |
download | liberasurecode-3338e25b9faeab6a9b3cd34c6f86865f4e0fa687.tar.gz |
Merged in lock_checks (pull request #2)
Updated the backend instance register/unregister methods with lock
-rw-r--r-- | src/erasurecode.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/src/erasurecode.c b/src/erasurecode.c index 1e77896..2a5bd9b 100644 --- a/src/erasurecode.c +++ b/src/erasurecode.c @@ -131,30 +131,46 @@ int liberasurecode_backend_alloc_desc(void) */ int liberasurecode_backend_instance_register(ec_backend_t instance) { - int desc = -1; - - rwlock_wrlock(&active_instances_rwlock); - SLIST_INSERT_HEAD(&active_instances, instance, link); - desc = liberasurecode_backend_alloc_desc(); - if (desc <= 0) - goto register_out; - instance->idesc = desc; + int desc = -1; /* descriptor to return */ + int rc = 0; /* return call value */ + + rc = rwlock_wrlock(&active_instances_rwlock); + if (rc == 0) { + SLIST_INSERT_HEAD(&active_instances, instance, link); + desc = liberasurecode_backend_alloc_desc(); + if (desc <= 0) + goto register_out; + instance->idesc = desc; + } else { + goto exit; + } register_out: rwlock_unlock(&active_instances_rwlock); +exit: return desc; } /** * Unregister a backend instance + * + * @returns 0 on success, non-0 on error */ int liberasurecode_backend_instance_unregister(ec_backend_t instance) { - rwlock_wrlock(&active_instances_rwlock); - SLIST_REMOVE(&active_instances, instance, ec_backend, link); - rwlock_unlock(&active_instances_rwlock); + int rc = 0; /* return call value */ + + rc = rwlock_wrlock(&active_instances_rwlock); + if (rc == 0) { + SLIST_REMOVE(&active_instances, instance, ec_backend, link); + } else { + goto exit; + } - return 0; +register_out: + rwlock_unlock(&active_instances_rwlock); +exit: + return rc; } /* =~=*=~==~=*=~== liberasurecode backend API helpers =~=*=~==~=*=~== */ |