Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async: add re_thread_async #462

Merged
merged 25 commits into from
Aug 3, 2022
Merged

async: add re_thread_async #462

merged 25 commits into from
Aug 3, 2022

Conversation

sreimers
Copy link
Member

@sreimers sreimers commented Jul 30, 2022

Usage:

re_thread_async(blocking_work, callback, data);

Example:

#include <re.h>

enum { JOBS = 100 };

static int cnt = 0;


static int work(void *arg)
{
	(void)arg;
	
	sys_msleep(10);
	
	return 0;
}


static void callback(int err, void *arg)
{
	(void)arg;
	(void)err;

	if (++cnt >= JOBS)
		re_cancel();
}


int main(void)
{
	libre_init();
	re_thread_async_init(16);

	for (int i = 0; i < JOBS; i++) {
		re_thread_async(work, callback, NULL);
	}

	re_main(NULL);

	re_thread_async_close();
	libre_close();
}

@sreimers sreimers force-pushed the re_async branch 2 times, most recently from c57ed0f to 43c9888 Compare July 30, 2022 18:14
@sreimers sreimers changed the title async: add new re_async module (WIP) async: add new module (WIP) Jul 31, 2022
@sreimers sreimers added this to the v2.7.0 milestone Jul 31, 2022
@sreimers sreimers marked this pull request as ready for review August 1, 2022 18:06
@cspiel1
Copy link
Collaborator

cspiel1 commented Aug 2, 2022

Would the RX RTP "real-time" thread in baresip one possible application for this new API?

@sreimers
Copy link
Member Author

sreimers commented Aug 2, 2022

In first place I need it to make getaddrinfo or filesystem accesses async. But maybe its much easier with this new API, since the callback is executed by re main thread. Only the accessed data by work has to be thread-safe. Maybe its enough to make the heavy work async/multithreaded (video decoding for example).

@sreimers sreimers changed the title async: add new module (WIP) async: add new module Aug 2, 2022
@sreimers sreimers changed the title async: add new module async: add re_thread_async Aug 2, 2022
@sreimers sreimers merged commit 264297a into main Aug 3, 2022
@sreimers sreimers deleted the re_async branch August 3, 2022 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants