mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 10:35:22 -04:00
Merge pull request #1385 from G10h4ck/safer_api
0.6.5 Safer rsGxsChannel API
This commit is contained in:
commit
8c8ce53e4b
16 changed files with 966 additions and 539 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue