Merge pull request #1385 from G10h4ck/safer_api

0.6.5 Safer rsGxsChannel API
This commit is contained in:
csoler 2018-11-20 21:44:40 +01:00 committed by GitHub
commit 8c8ce53e4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 966 additions and 539 deletions

View file

@ -27,6 +27,8 @@
#include <iostream>
#include <unistd.h>
#include <semaphore.h>
#include <thread>
#include <functional>
#include <util/rsmemory.h>
#include "util/rstime.h"
@ -239,7 +241,7 @@ pthread_t createThread(RsThread &thread);
class RsThread
{
public:
public:
RsThread();
virtual ~RsThread() {}
@ -259,6 +261,17 @@ class RsThread
void ask_for_stop();
/**
* Execute given function on another thread without blocking the caller
* execution.
* This can be generalized with variadic template, ATM it is enough to wrap
* any kind of function call or job into a lambda which get no paramethers
* and return nothing but can capture
* This can be easly optimized later by using a thread pool
*/
static void async(const std::function<void()>& fn)
{ std::thread(fn).detach(); }
protected:
virtual void runloop() =0; /* called once the thread is started. Should be overloaded by subclasses. */
void go() ; // this one calls runloop and also sets the flags correctly when the thread is finished running.