Skip to content

Commit

Permalink
forward declare instead of including boost/thread.hpp (BVLC#1009)
Browse files Browse the repository at this point in the history
This means that Caffe::Get has to be moved to common.cpp, and loses its
"inline" (but there are no real performance implications).
  • Loading branch information
longjon committed Mar 27, 2015
1 parent 4fe9305 commit c4590db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 4 additions & 7 deletions include/caffe/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#define CAFFE_COMMON_HPP_

#include <boost/shared_ptr.hpp>
#include <boost/thread.hpp>
#include <gflags/gflags.h>
#include <glog/logging.h>

Expand Down Expand Up @@ -69,6 +68,9 @@ private:\
// See PR #1236
namespace cv { class Mat; }

// Avoid issues with including boost/thread in NVCC source (#1009).
namespace boost { template <typename T> class thread_specific_ptr; }

namespace caffe {

// We will use the boost shared_ptr instead of the new C++11 one mainly
Expand Down Expand Up @@ -99,12 +101,7 @@ void GlobalInit(int* pargc, char*** pargv);
class Caffe {
public:
~Caffe();
inline static Caffe& Get() {
if (!singleton_.get()) {
singleton_.reset(new Caffe());
}
return *singleton_;
}
static Caffe& Get();
enum Brew { CPU, GPU };

// This random number generator facade hides boost and CUDA rng
Expand Down
8 changes: 8 additions & 0 deletions src/caffe/common.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <boost/thread.hpp>
#include <glog/logging.h>
#include <cstdio>
#include <ctime>
Expand Down Expand Up @@ -39,6 +40,13 @@ void GlobalInit(int* pargc, char*** pargv) {
::google::InstallFailureSignalHandler();
}

Caffe& Caffe::Get() {
if (!singleton_.get()) {
singleton_.reset(new Caffe());
}
return *singleton_;
}

#ifdef CPU_ONLY // CPU-only Caffe.

Caffe::Caffe()
Expand Down

0 comments on commit c4590db

Please sign in to comment.