From d263455d5ac0d87541144dd7a37eb6255b721a89 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 2 Feb 2017 11:55:03 +0200 Subject: Redesign target_set interface in preparation for locking --- build2/target | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'build2/target') 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> map; - typedef butl::map_iterator_adapter iterator; + using map_type = std::unordered_map>; - 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 T* @@ -1003,9 +1005,6 @@ namespace build2 return i != map_.end () ? static_cast (i->second.get ()) : nullptr; } - iterator begin () const {return map_.begin ();} - iterator end () const {return map_.end ();} - pair 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; + + 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; -- cgit v1.1