mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 10:35:22 -04:00
Safer RsGxsChannel API
Deprecated old method which exposed interna async mechanism to the API users, making their and out life difficult Things that really need to be async like turtle search/requests now accept callbacks, so the caller can be notified everytime some result is got back Implement RsThread::async commodity wrapper to execute blocking API calls without blocking the caller, this could be optimized trasparently using a thread pool if necessary Added hints into some retroshare-gui files on how to use RsThread::async thoghether with QMetaObject::invokeMethod and blocking RetroShare API to simplyfy interaction between GUI and libretroshare
This commit is contained in:
parent
8fd22c8fd1
commit
ea86fe2615
8 changed files with 507 additions and 236 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 lamba 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