{"id":19272647,"url":"https://github.com/grype/rwlock-swift","last_synced_at":"2025-08-25T01:05:58.291Z","repository":{"id":77659684,"uuid":"356776947","full_name":"grype/RWLock-Swift","owner":"grype","description":"Read-Write lock in Swift","archived":false,"fork":false,"pushed_at":"2021-04-11T06:27:33.000Z","size":5,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-04-24T11:24:57.144Z","etag":null,"topics":["concurrency","lock","pthreads","readwritelock","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grype.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-04-11T05:38:48.000Z","updated_at":"2022-04-18T05:18:42.000Z","dependencies_parsed_at":"2023-03-22T02:33:12.789Z","dependency_job_id":null,"html_url":"https://github.com/grype/RWLock-Swift","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grype%2FRWLock-Swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grype%2FRWLock-Swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grype%2FRWLock-Swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grype%2FRWLock-Swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grype","download_url":"https://codeload.github.com/grype/RWLock-Swift/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240378874,"owners_count":19792038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["concurrency","lock","pthreads","readwritelock","swift"],"created_at":"2024-11-09T20:37:30.639Z","updated_at":"2025-02-23T20:40:38.707Z","avatar_url":"https://github.com/grype.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RWLock\n\nSwift wrapper around pthread_rwlock.\n\nSee [Read-Write Lock](https://en.wikipedia.org/wiki/Readers–writer_lock) for details.\n\nUsage:\n\n```swift\nlet lock = RWLock()\nlock.readProtected {\n    // do something concurrently with other reads and until write lock is acquired \n}\nlock.writeProtected {\n    // do something that requires exclusive access\n}\n```\n\nUsing propety wrapper:\n\n```swift\nclass Foo {\n    @RWLocked var items = [Any]()\n    \n    func add(_ item: Any) {\n        items.append(item)\n    }\n    \n    func removeAll() {\n        items.removeAll()\n    }\n    \n    func iterate() {\n        items.forEach { \n            // do something with each item\n        }\n    }\n    \n}\n```\n\nAny modifications to `items` array will require write protection - this applies to methods `add(_:)` and `removeAll()`. In contrast, `iterate()`ing over the array requires read access. This means that you won't be able to `add(_:)` or `removeAll()` until iteration is complete, and you won't be able to `iterate()` until `add(_:)` or `removeAll()` had finished. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrype%2Frwlock-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrype%2Frwlock-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrype%2Frwlock-swift/lists"}