mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-11 18:45:17 -04:00
* Added new interface functions for start / stop DHT and to get stats.
* Implemented start/stop interface in udpbitdht and bemanager * added Restart of DHT if it fails to get going. * added start / stop functionality to bdnode and bdstore * added cleanup code to rest of bitdht classes. * reworked NetworkSize calc functions. * added thread debugging (prints at start / stop / join). * TESTS: added utest.h header file for automated unit testing (from libretroshare) * TESTS: bdmetric_test started conversion to automated tests * TESTS: udpbitdht_nettest. Added dht start / stop and network reset (thread join) functionality. * TESTS: fresh bdboot.txt git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3678 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
884f0e7a22
commit
74961774cc
18 changed files with 1193 additions and 601 deletions
|
@ -32,15 +32,26 @@
|
|||
* #define DEBUG_THREADS 1
|
||||
*******/
|
||||
|
||||
#define DEBUG_THREADS 1
|
||||
|
||||
#ifdef DEBUG_THREADS
|
||||
#include <iostream>
|
||||
#endif
|
||||
|
||||
extern "C" void* bdthread_init(void* p)
|
||||
{
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdthread_init()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
bdThread *thread = (bdThread *) p;
|
||||
if (!thread)
|
||||
{
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdthread_init() Error Invalid thread pointer.";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
thread -> run();
|
||||
|
@ -53,19 +64,45 @@ pthread_t createThread(bdThread &thread)
|
|||
pthread_t tid;
|
||||
void *data = (void *) (&thread);
|
||||
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "createThread() creating a bdThread";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
thread.mMutex.lock();
|
||||
{
|
||||
pthread_create(&tid, 0, &bdthread_init, data);
|
||||
thread.mTid = tid;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "createThread() created Thread.mTid: ";
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
std::cerr << "WIN32: Cannot print mTid ";
|
||||
#else
|
||||
std::cerr << thread.mTid;
|
||||
#endif
|
||||
std::cerr << std::endl;
|
||||
|
||||
#endif
|
||||
|
||||
thread.mMutex.unlock();
|
||||
|
||||
|
||||
|
||||
return tid;
|
||||
|
||||
}
|
||||
|
||||
bdThread::bdThread()
|
||||
{
|
||||
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdThread::bdThread()";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
#else
|
||||
|
@ -75,16 +112,59 @@ bdThread::bdThread()
|
|||
|
||||
void bdThread::join() /* waits for the the mTid thread to stop */
|
||||
{
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdThread::join() Called! Waiting for Thread.mTid: ";
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
std::cerr << "WIN32: Cannot print mTid ";
|
||||
#else
|
||||
std::cerr << mTid;
|
||||
#endif
|
||||
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
mMutex.lock();
|
||||
{
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
/* Its a struct in Windows compile and the member .p ist checked in the pthreads library */
|
||||
#else
|
||||
if(mTid > 0)
|
||||
#endif
|
||||
pthread_join(mTid, NULL);
|
||||
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdThread::join() Joined Thread.mTid: ";
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
std::cerr << "WIN32: Cannot print mTid ";
|
||||
#else
|
||||
std::cerr << mTid;
|
||||
#endif
|
||||
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "bdThread::join() Setting mTid = 0";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(__MINGW32__)
|
||||
memset (&mTid, 0, sizeof(mTid));
|
||||
#else
|
||||
mTid = 0;
|
||||
#endif
|
||||
|
||||
}
|
||||
mMutex.unlock();
|
||||
|
||||
}
|
||||
|
||||
void bdThread::stop()
|
||||
{
|
||||
#ifdef DEBUG_THREADS
|
||||
std::cerr << "bdThread::stop() Called!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue