aboutsummaryrefslogtreecommitdiff
path: root/build2/target
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-02-02 11:55:03 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-02-13 12:42:41 +0200
commitd263455d5ac0d87541144dd7a37eb6255b721a89 (patch)
tree97b56b4f817c61de5fa543cfa6d94bab5f05c5c0 /build2/target
parent53f02bf28dae507a51515ed6ac03226d68816494 (diff)
Redesign target_set interface in preparation for locking
Diffstat (limited to 'build2/target')
-rw-r--r--build2/target27
1 files changed, 17 insertions, 10 deletions
diff --git a/build2/target b/build2/target
index 42c0361..fc6e782 100644
--- a/build2/target
+++ b/build2/target
@@ -971,16 +971,19 @@ namespace build2
// map. The key's hash ignores the extension, so the hash will stay stable
// across extension updates.
//
+ // Note also that once the extension is specified, it becomes immutable.
+ //
class target_set
{
public:
- typedef std::unordered_map<target_key, unique_ptr<target>> map;
- typedef butl::map_iterator_adapter<map::const_iterator> iterator;
+ using map_type = std::unordered_map<target_key, unique_ptr<target>>;
- iterator
+ // Return existing target or NULL.
+ //
+ target*
find (const target_key& k, tracer& trace) const;
- iterator
+ target*
find (const target_type& type,
const dir_path& dir,
const dir_path& out,
@@ -991,8 +994,7 @@ namespace build2
return find (target_key {&type, &dir, &out, &name, ext}, trace);
}
- // As above but ignore the extension and return the target or nullptr
- // instead of the iterator.
+ // As above but ignore the extension.
//
template <typename T>
T*
@@ -1003,9 +1005,6 @@ namespace build2
return i != map_.end () ? static_cast<T*> (i->second.get ()) : nullptr;
}
- iterator begin () const {return map_.begin ();}
- iterator end () const {return map_.end ();}
-
pair<target&, bool>
insert (const target_type&,
dir_path dir,
@@ -1057,11 +1056,19 @@ namespace build2
insert (T::static_type, dir, out, name, nullopt, false, t).first);
}
+ // Note: not MT-safe so can only be used during serial execution.
+ //
+ public:
+ using iterator = butl::map_iterator_adapter<map_type::const_iterator>;
+
+ iterator begin () const {return map_.begin ();}
+ iterator end () const {return map_.end ();}
+
void
clear () {map_.clear ();}
private:
- map map_;
+ map_type map_;
};
extern target_set targets;