Some cleanup to make travis happy.
authorKevin James Matzen <kmatzen@cs.cornell.edu>
Tue, 7 Oct 2014 20:14:29 +0000 (16:14 -0400)
committerKevin James Matzen <kmatzen@cs.cornell.edu>
Tue, 14 Oct 2014 23:25:01 +0000 (19:25 -0400)
include/caffe/database_factory.hpp
include/caffe/leveldb_database.hpp
include/caffe/lmdb_database.hpp
src/caffe/database_factory.cpp
src/caffe/layers/data_layer.cpp

index a6e39e7..91185e9 100644 (file)
@@ -5,6 +5,7 @@
 
 #include "caffe/common.hpp"
 #include "caffe/database.hpp"
+#include "caffe/proto/caffe.pb.h"
 
 namespace caffe {
 
index 5daf0e5..ee8c5f2 100644 (file)
@@ -19,6 +19,11 @@ class LeveldbDatabase : public Database {
   void commit();
   void close();
 
+  const_iterator begin() const;
+  const_iterator cbegin() const;
+  const_iterator end() const;
+  const_iterator cend() const;
+
   ~LeveldbDatabase() { this->close(); }
 
  protected:
@@ -37,12 +42,6 @@ class LeveldbDatabase : public Database {
   void increment(shared_ptr<DatabaseState> state) const;
   pair<string, string>& dereference(shared_ptr<DatabaseState> state) const;
 
-  const_iterator begin() const;
-  const_iterator cbegin() const;
-  const_iterator end() const;
-  const_iterator cend() const;
-
- protected:
   shared_ptr<leveldb::DB> db_;
   shared_ptr<leveldb::WriteBatch> batch_;
 };
index f275cb4..7387afd 100644 (file)
@@ -14,7 +14,9 @@ namespace caffe {
 class LmdbDatabase : public Database {
  public:
   LmdbDatabase()
-      : dbi_(0) { }
+      : env_(NULL),
+        dbi_(0),
+        txn_(NULL) { }
   ~LmdbDatabase() { this->close(); }
 
   void open(const string& filename, Mode mode);
@@ -22,6 +24,11 @@ class LmdbDatabase : public Database {
   void commit();
   void close();
 
+  const_iterator begin() const;
+  const_iterator cbegin() const;
+  const_iterator end() const;
+  const_iterator cend() const;
+
  protected:
   class LmdbState : public Database::DatabaseState {
    public:
@@ -38,15 +45,9 @@ class LmdbDatabase : public Database {
   void increment(shared_ptr<DatabaseState> state) const;
   pair<string, string>& dereference(shared_ptr<DatabaseState> state) const;
 
- protected:
-  const_iterator begin() const;
-  const_iterator cbegin() const;
-  const_iterator end() const;
-  const_iterator cend() const;
-
-  MDB_env *env_ = NULL;
+  MDB_env *env_;
   MDB_dbi dbi_;
-  MDB_txn *txn_ = NULL;
+  MDB_txn *txn_;
 };
 
 }  // namespace caffe
index 393635b..062de8c 100644 (file)
@@ -15,6 +15,7 @@ shared_ptr<Database> DatabaseFactory(const DataParameter_DB& type) {
     return shared_ptr<Database>(new LmdbDatabase());
   default:
     LOG(FATAL) << "Unknown database type " << type;
+    return shared_ptr<Database>();
   }
 }
 
@@ -25,6 +26,7 @@ shared_ptr<Database> DatabaseFactory(const string& type) {
     return DatabaseFactory(DataParameter_DB_LMDB);
   } else {
     LOG(FATAL) << "Unknown database type " << type;
+    return shared_ptr<Database>();
   }
 }
 
index b746bc8..1d37170 100644 (file)
@@ -18,6 +18,9 @@ template <typename Dtype>
 DataLayer<Dtype>::~DataLayer<Dtype>() {
   this->JoinPrefetchThread();
   // clean up the database resources
+
+  // Very important to invalidate iterators before closing the database.
+  // TODO(kmatzen): Figure out a better design to avoid this.
   iter_ = database_->end();
   database_->close();
 }