{"id":19554120,"url":"https://github.com/berndporr/cpptimer","last_synced_at":"2025-07-14T18:06:06.198Z","repository":{"id":53021866,"uuid":"119444736","full_name":"berndporr/cppTimer","owner":"berndporr","description":"C++ timer: wrapper around the standard Linux C timer to make your life easier","archived":false,"fork":false,"pushed_at":"2025-05-14T19:16:01.000Z","size":361,"stargazers_count":21,"open_issues_count":0,"forks_count":12,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T20:27:10.410Z","etag":null,"topics":["callback","linux","linux-library","linux-timer","timer","wrapper"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/berndporr.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,"zenodo":null}},"created_at":"2018-01-29T21:33:16.000Z","updated_at":"2025-05-14T19:16:05.000Z","dependencies_parsed_at":"2025-04-26T21:42:15.847Z","dependency_job_id":null,"html_url":"https://github.com/berndporr/cppTimer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/berndporr/cppTimer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2FcppTimer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2FcppTimer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2FcppTimer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2FcppTimer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/berndporr","download_url":"https://codeload.github.com/berndporr/cppTimer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/berndporr%2FcppTimer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265327767,"owners_count":23747765,"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":["callback","linux","linux-library","linux-timer","timer","wrapper"],"created_at":"2024-11-11T04:25:59.723Z","updated_at":"2025-07-14T18:06:06.191Z","avatar_url":"https://github.com/berndporr.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CppTimer\nGeneric C++ Timer for Linux\n\nIt's a wrapper around the Linux timers. The timer used is timerfd\nwhich is a file descriptor which blocks till a certain time has\nelapsed. This means it puts a thread to sleep till it unblocks\nwhich is the general approach for Linux events.\nThere are three ways of using\nthe timer: \n 1. by overloading the `timerEvent()` method in the `CppTimer` class itself (fastest)\n 2. by registering a callback class called `Runnable` with an overloaded `run()` method.\n 3. by registering a lambda function\n\n## Installation\n```\ncmake .\nmake\nsudo make install\n```\n\n## Usage (overloading the timer event)\nThe doxygen generated online docs are here: https://berndporr.github.io/cppTimer/\n\nInclude `CppTimer.h` in your program. That's it.\n```\nTARGET_LINK_LIBRARIES(your_project_title cpptimer rt)\n```\n\n### Create the Timer class\n```\nclass MyTimer : public CppTimer {\n\n\tvoid timerEvent() {\n\t\t// your timer event code here\n\t}\n};\n```\nwhere you override `timerEvent` with your function.\n\n### Run the Timer class\nThe timer is programmed in nanoseconds:\n```\n\tMyTimer myTimer;\n\t// every 500000ns\n\tmyTimer.startns(500000);\n```\nor milliseconds:\n```\n\t// every 200ms\n\tmyTimer.startms(200);\n```\nAs soon as start returns the timer fires instantly and\nthen at the specified interval.\n\n### Demo program\n\nTo run `demo.cpp` just do `cmake .`, `make` and then `./demo`.\n\n## Callback interface version\n\nInstead of overloading the `run()` method in the timer class you can\noverload the `run()` method in the `Runnable` class and then register\nthis class with the timer class.  Check out `demo_runnable` which\ndemonstrates how to use this method.\n\n## Callback via lambda function\n\nHere, the callback is established with the help of a lambda function\ninstead of a callback interface. This allows direct registering\nof a method of the receiving class but one needs to get used to the\nlambda function syntax. It also allows more flexibility in doing\nsome work inside of the lambda function and it's entirely pointer-free.\n\n## Unit tests\n\nRun:\n\n```\nctest\n```\n\n\nThat's it. Enjoy!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberndporr%2Fcpptimer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fberndporr%2Fcpptimer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fberndporr%2Fcpptimer/lists"}