Optionally use c++11 stuff instead of boost in cycles where possible. We do and continue to depend on boost though

Reviewers: dingto, sergey

Reviewed By: sergey

Subscribers: #cycles

Differential Revision: https://developer.blender.org/D1185
This commit is contained in:
Martijn Berger 2015-03-29 22:12:22 +02:00
parent 70d9c01325
commit f01456aaa4
13 changed files with 129 additions and 31 deletions

View File

@ -152,6 +152,27 @@ add_definitions(
-DWITH_MULTI
)
TEST_UNORDERED_MAP_SUPPORT()
if(HAVE_STD_UNORDERED_MAP_HEADER)
if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
add_definitions(-DCYCLES_STD_UNORDERED_MAP)
else()
if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
else()
add_definitions(-DCYCLES_NO_UNORDERED_MAP)
message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
endif()
endif()
else()
if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
else()
add_definitions(-DCYCLES_NO_UNORDERED_MAP)
message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
endif()
endif()
# Logging capabilities using GLog library.
if(WITH_CYCLES_LOGGING)
add_definitions(-DWITH_CYCLES_LOGGING)

View File

@ -47,6 +47,18 @@ cxxflags = Split(env['CXXFLAGS'])
defs += env['BF_GL_DEFINITIONS']
if env['WITH_UNORDERED_MAP_SUPPORT']:
if env['UNORDERED_MAP_HEADER'] == 'unordered_map':
if env['UNORDERED_MAP_NAMESPACE'] == 'std':
defs.append('CYCLES_STD_UNORDERED_MAP')
elif env['UNORDERED_MAP_NAMESPACE'] == 'std::tr1':
defs.append('CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE')
elif env['UNORDERED_MAP_NAMESPACE'] == 'std::tr1':
defs.append('CYCLES_TR1_UNORDERED_MAP')
else:
print("-- Replacing unordered_map/set with map/set (warning: slower!)")
defs.append('CYCLES_NO_UNORDERED_MAP')
defs.append('CCL_NAMESPACE_BEGIN=namespace ccl {')
defs.append('CCL_NAMESPACE_END=}')

View File

@ -72,8 +72,8 @@ public:
/* Device */
struct DeviceDrawParams {
boost::function<void(void)> bind_display_space_shader_cb;
boost::function<void(void)> unbind_display_space_shader_cb;
function<void(void)> bind_display_space_shader_cb;
function<void(void)> unbind_display_space_shader_cb;
};
class Device {

View File

@ -57,11 +57,11 @@ public:
void update_progress(RenderTile *rtile);
boost::function<bool(Device *device, RenderTile&)> acquire_tile;
boost::function<void(void)> update_progress_sample;
boost::function<void(RenderTile&)> update_tile_sample;
boost::function<void(RenderTile&)> release_tile;
boost::function<bool(void)> get_cancel;
function<bool(Device *device, RenderTile&)> acquire_tile;
function<void(void)> update_progress_sample;
function<void(RenderTile&)> update_tile_sample;
function<void(RenderTile&)> release_tile;
function<bool(void)> get_cancel;
bool need_finish_queue;
bool integrator_branched;

View File

@ -73,9 +73,9 @@ public:
bool need_update;
boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
struct Image {
string filename;

View File

@ -125,8 +125,8 @@ public:
TileManager tile_manager;
Stats stats;
boost::function<void(RenderTile&)> write_render_tile_cb;
boost::function<void(RenderTile&)> update_render_tile_cb;
function<void(RenderTile&)> write_render_tile_cb;
function<void(RenderTile&)> update_render_tile_cb;
Session(const SessionParams& params);
~Session();

View File

@ -19,8 +19,12 @@
/* Use Boost to get nice foreach() loops for STL data structures. */
#include <boost/foreach.hpp>
#define foreach BOOST_FOREACH
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
# define foreach(x, y) for(x : y)
#else
# include <boost/foreach.hpp>
# define foreach BOOST_FOREACH
#endif
#endif /* __UTIL_FOREACH_H__ */

View File

@ -17,14 +17,31 @@
#ifndef __UTIL_FUNCTION_H__
#define __UTIL_FUNCTION_H__
#include <boost/bind.hpp>
#include <boost/function.hpp>
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
# include <functional>
#else
# include <boost/bind.hpp>
# include <boost/function.hpp>
#endif
CCL_NAMESPACE_BEGIN
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
# define function_bind std::bind
using std::function;
using std::placeholders::_1;
using std::placeholders::_2;
using std::placeholders::_3;
using std::placeholders::_4;
using std::placeholders::_5;
using std::placeholders::_6;
using std::placeholders::_7;
using std::placeholders::_8;
using std::placeholders::_9;
#else
using boost::function;
#define function_bind boost::bind
# define function_bind boost::bind
#endif
CCL_NAMESPACE_END
#endif /* __UTIL_FUNCTION_H__ */

View File

@ -18,13 +18,38 @@
#define __UTIL_MAP_H__
#include <map>
#include <boost/tr1/unordered_map.hpp>
#if defined(CYCLES_TR1_UNORDERED_MAP)
# include <tr1/unordered_map>
#endif
#if defined(CYCLES_STD_UNORDERED_MAP) || defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
# include <unordered_map>
#endif
#if !defined(CYCLES_NO_UNORDERED_MAP) && !defined(CYCLES_TR1_UNORDERED_MAP) && \
!defined(CYCLES_STD_UNORDERED_MAP) && !defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE) // NOLINT
# error One of: CYCLES_NO_UNORDERED_MAP, CYCLES_TR1_UNORDERED_MAP,\
CYCLES_STD_UNORDERED_MAP, CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE must be defined! // NOLINT
#endif
CCL_NAMESPACE_BEGIN
using std::map;
using std::pair;
#if defined(CYCLES_NO_UNORDERED_MAP)
typedef std::map unordered_map;
#endif
#if defined(CYCLES_TR1_UNORDERED_MAP) || defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
using std::tr1::unordered_map;
#endif
#if defined(CYCLES_STD_UNORDERED_MAP)
using std::unordered_map;
#endif
CCL_NAMESPACE_END

View File

@ -110,7 +110,7 @@ public:
return cancel_message;
}
void set_cancel_callback(boost::function<void(void)> function)
void set_cancel_callback(function<void(void)> function)
{
cancel_cb = function;
}
@ -275,7 +275,7 @@ public:
}
}
void set_update_callback(boost::function<void(void)> function)
void set_update_callback(function<void(void)> function)
{
update_cb = function;
}
@ -283,8 +283,8 @@ public:
protected:
thread_mutex progress_mutex;
thread_mutex update_mutex;
boost::function<void(void)> update_cb;
boost::function<void(void)> cancel_cb;
function<void(void)> update_cb;
function<void(void)> cancel_cb;
int tile; /* counter for rendered tiles */
int sample; /* counter of rendered samples, global for all tiles */

View File

@ -18,13 +18,19 @@
#define __UTIL_SET_H__
#include <set>
#include <boost/tr1/unordered_set.hpp>
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
# include <unordered_set>
#else
# include <boost/tr1/unordered_set.hpp>
#endif
CCL_NAMESPACE_BEGIN
using std::set;
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
using std::unordered_set;
#else
using std::tr1::unordered_set;
#endif
CCL_NAMESPACE_END
#endif /* __UTIL_SET_H__ */

View File

@ -27,7 +27,7 @@ class Task;
class TaskPool;
class TaskScheduler;
typedef boost::function<void(void)> TaskRunFunction;
typedef function<void(void)> TaskRunFunction;
/* Task
*

View File

@ -17,7 +17,14 @@
#ifndef __UTIL_THREAD_H__
#define __UTIL_THREAD_H__
#include <boost/thread.hpp>
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
# include <thread>
# include <mutex>
# include <condition_variable>
# include <functional>
#else
# include <boost/thread.hpp>
#endif
#include <pthread.h>
#include <queue>
@ -25,18 +32,24 @@
CCL_NAMESPACE_BEGIN
#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
typedef std::mutex thread_mutex;
typedef std::unique_lock<std::mutex> thread_scoped_lock;
typedef std::condition_variable thread_condition_variable;
#else
/* use boost for mutexes */
typedef boost::mutex thread_mutex;
typedef boost::mutex::scoped_lock thread_scoped_lock;
typedef boost::condition_variable thread_condition_variable;
#endif
/* own pthread based implementation, to avoid boost version conflicts with
* dynamically loaded blender plugins */
class thread {
public:
thread(boost::function<void(void)> run_cb_)
thread(function<void(void)> run_cb_)
{
joined = false;
run_cb = run_cb_;
@ -63,7 +76,7 @@ public:
}
protected:
boost::function<void(void)> run_cb;
function<void(void)> run_cb;
pthread_t pthread_id;
bool joined;
};