Fixed crash at end if threads could not be created. Added appropriate

warning, and made more prints depend on verbosity level.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@8097 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2011-03-28 23:06:21 +00:00
parent 51c134c2af
commit 6bd2d0b3b5
2 changed files with 17 additions and 6 deletions

View File

@ -18,6 +18,7 @@
#include "addons/network_http.hpp"
#include <curl/curl.h>
#include <errno.h>
#include <stdio.h>
#include <string>
@ -76,7 +77,12 @@ NetworkHttp::NetworkHttp() : m_news(std::vector<NewsMessage>()),
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
pthread_create(&m_thread_id, &attr, &NetworkHttp::mainLoop, this);
int error=pthread_create(&m_thread_id, &attr, &NetworkHttp::mainLoop, this);
if(error)
{
m_thread_id = 0;
printf("[addons] Warning: could not create thread, error=%d.\n", errno);
}
pthread_attr_destroy(&attr);
} // NetworkHttp
@ -193,11 +199,16 @@ NetworkHttp::~NetworkHttp()
pthread_cond_signal(&m_cond_command);
}
pthread_mutex_unlock(&m_mutex_command);
printf("[addons] Mutex unlocked.\n");
if(UserConfigParams::m_verbosity>=3)
printf("[addons] Mutex unlocked.\n");
void *result;
pthread_join(m_thread_id, &result);
printf("[addons] Network thread joined.\n");
if(m_thread_id)
{
void *result;
pthread_join(m_thread_id, &result);
if(UserConfigParams::m_verbosity>=3)
printf("[addons] Network thread joined.\n");
}
pthread_mutex_destroy(&m_mutex_command);
pthread_cond_destroy(&m_cond_command);

View File

@ -580,10 +580,10 @@ void MinimalRaceGUI::drawRankLap(const KartIconDisplayInfo* info,
- m_lap_width -20 );
pos.UpperLeftCorner.Y = viewport.LowerRightCorner.Y-60;
printf("x %d %d\n", pos.UpperLeftCorner.Y, pos.LowerRightCorner.Y);
char str[256];
sprintf(str, "%d/%d", lap+1, race_manager->getNumLaps());
core::stringw s = m_string_lap+" "+str;
float scale = font->getScale();
font->draw(s.c_str(), pos, color);
}
}