{"id":21033349,"url":"https://github.com/aosync/spin","last_synced_at":"2026-04-21T08:37:53.481Z","repository":{"id":174129729,"uuid":"389302171","full_name":"aosync/spin","owner":"aosync","description":"A simple spinlock library","archived":false,"fork":false,"pushed_at":"2021-07-25T08:57:34.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-29T02:17:38.179Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aosync.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-07-25T08:48:41.000Z","updated_at":"2021-07-25T08:57:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"3eba3b77-3cb8-4055-83fc-8cf3ad301690","html_url":"https://github.com/aosync/spin","commit_stats":null,"previous_names":["aosync/spin"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/aosync/spin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosync%2Fspin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosync%2Fspin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosync%2Fspin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosync%2Fspin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aosync","download_url":"https://codeload.github.com/aosync/spin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aosync%2Fspin/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32084387,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T06:27:27.065Z","status":"ssl_error","status_checked_at":"2026-04-21T06:27:21.250Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":[],"created_at":"2024-11-19T12:54:50.800Z","updated_at":"2026-04-21T08:37:53.451Z","avatar_url":"https://github.com/aosync.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spin\n\nA trivial spinlock library.\n\n## documentation\n\nSpinlocks keep a reference to a variable, and they ensure it is being accessed only at one place at a time.\n\n### spinlock creation\n\nYou can create a spinlock like this\n```c\nint myvar = 10;\nstruct spin sl = spin_new(\u0026myvar);\n```\nbut it is also possible to create spinlock statically, outside functions using the `spin_const_new` macro.\n\n### locking and unlocking.\n\nWhen the spinlock is locked, it returns a reference to the data pointed by the spinlock:\n```c\nint *myvarref = spin_lock(\u0026sl);\n*myvarref *= 2;\nspin_unlock(\u0026sl);\n```\n\nThere is also a macro to make locking and unlocking scoped, and tidier:\n```c\nspin(int *myvarref, \u0026sl){\n\t*myvarref *= 2;\n}\n```\n**note**: It is incorrect to `return` in a `spin` scope. To exit safely from a `spin` scope, use `continue`. \n\n## safety considerations\n\nA variable should only be referenced by one spinlock.  \nSpinlocks should live longer than all threads it is referenced by.  \nDo not forcibly terminate threads.\n\n## use the library in projects\n\nFree free to ship `spin.c` and `spin.h` in your projects.  \nHowever, if you are using the meson build system, I recommend using the [wrap dependency system](https://mesonbuild.com/Wrap-dependency-system-manual.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faosync%2Fspin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faosync%2Fspin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faosync%2Fspin/lists"}