Fix osx apr pool initialization (required apr_initialize() to have been called)

This commit is contained in:
Josh Faust 2009-12-11 00:29:40 +00:00
parent 93fe93a762
commit 3d7aa54ac9
3 changed files with 27 additions and 12 deletions

View File

@ -54,6 +54,8 @@
#include <roslib/Time.h>
#include <roslib/Clock.h>
#include <apr_general.h>
#include <algorithm>
#include <signal.h>
@ -88,7 +90,7 @@ namespace file_log
void init(const M_string& remappings);
}
CallbackQueue g_global_queue;
CallbackQueuePtr g_global_queue;
ROSOutAppenderPtr g_rosout_appender;
static bool g_initialized = false;
@ -132,6 +134,8 @@ void atexitCallback()
ROSCPP_LOG_DEBUG("shutting down due to exit() or end of main() without cleanup of all NodeHandles");
shutdown();
}
apr_terminate();
}
void shutdownCallback(XmlRpc::XmlRpcValue& params, XmlRpc::XmlRpcValue& result)
@ -331,7 +335,6 @@ void start()
}
g_internal_queue_thread = boost::thread(internalCallbackQueueThreadFunc);
g_global_queue.enable();
getGlobalCallbackQueue()->enable();
ROSCPP_LOG_DEBUG("Started node [%s], pid [%d], bound on [%s], xmlrpc port [%d], tcpros port [%d], logging to [%s], using [%s] time", this_node::getName().c_str(), getpid(), network::getHost().c_str(), XMLRPCManager::instance()->getServerPort(), ConnectionManager::instance()->getTCPPort(), file_log::getLogFilename().c_str(), Time::useSystemTime() ? "real" : "sim");
@ -351,10 +354,17 @@ void init(const M_string& remappings, const std::string& name, uint32_t options)
{
if (!g_atexit_registered)
{
apr_initialize();
g_atexit_registered = true;
atexit(atexitCallback);
}
if (!g_global_queue)
{
g_global_queue.reset(new CallbackQueue);
}
if (!g_initialized)
{
g_init_options = options;
@ -445,7 +455,7 @@ void spin(Spinner& s)
void spinOnce()
{
g_global_queue.callAvailable(ros::WallDuration());
g_global_queue->callAvailable(ros::WallDuration());
}
void waitForShutdown()
@ -458,7 +468,7 @@ void waitForShutdown()
CallbackQueue* getGlobalCallbackQueue()
{
return &g_global_queue;
return g_global_queue.get();
}
bool ok()
@ -478,8 +488,8 @@ void shutdown()
g_shutting_down = true;
g_global_queue.disable();
g_global_queue.clear();
g_global_queue->disable();
g_global_queue->clear();
if (g_internal_queue_thread.get_id() != boost::this_thread::get_id())
{

View File

@ -30,7 +30,7 @@
#include <apr_pools.h>
#include <ros/assert.h>
#include <boost/thread/tss.hpp>
#include <boost/thread.hpp>
namespace ros
{
@ -38,7 +38,13 @@ namespace ros
#define CHECK_APR_STATUS(x) \
{ \
apr_status_t status = x; \
ROS_ASSERT(status == APR_SUCCESS); \
if (status != APR_SUCCESS) \
{ \
char str_status[200]; \
apr_strerror(status, str_status, sizeof(str_status)); \
ROS_FATAL("APR status checked failed: %s (%d)", str_status, status); \
ROS_BREAK(); \
} \
}
class APRPool
@ -65,6 +71,7 @@ void createPoolIfNecessary()
{
if (!g_rwmutex_pool.get())
{
ROS_DEBUG_STREAM("Creating rwmutex pool in thread " << boost::this_thread::get_id());
g_rwmutex_pool.reset(new APRPool);
}
}

View File

@ -34,15 +34,13 @@
namespace ros
{
extern CallbackQueue g_global_queue;
void SingleThreadedSpinner::spin(CallbackQueue* queue)
{
ros::WallDuration d(0.01f);
if (!queue)
{
queue = &g_global_queue;
queue = getGlobalCallbackQueue();
}
ros::NodeHandle n;
@ -104,7 +102,7 @@ AsyncSpinnerImpl::AsyncSpinnerImpl(uint32_t thread_count, CallbackQueue* queue)
if (!queue)
{
callback_queue_ = &g_global_queue;
callback_queue_ = getGlobalCallbackQueue();
}
}