Core: new blenlib library for implicit-sharing #105994

Merged
Jacques Lucke merged 17 commits from JacquesLucke/blender:implicit-sharing into main 2023-03-28 13:58:02 +02:00
5 changed files with 11 additions and 11 deletions
Showing only changes of commit d63aca8865 - Show all commits

View File

@ -4,7 +4,7 @@
#include <atomic> #include <atomic>
#include "BLI_implicit_sharing_user.hh" #include "BLI_implicit_sharing_ptr.hh"
#include "BLI_set.hh" #include "BLI_set.hh"
#include "BLI_string_ref.hh" #include "BLI_string_ref.hh"
@ -32,7 +32,7 @@ namespace blender::bke {
* because that is not available in C code. If possible, the #AutoAnonymousAttributeID wrapper * because that is not available in C code. If possible, the #AutoAnonymousAttributeID wrapper
* should be used to avoid manual reference counting in C++ code. * should be used to avoid manual reference counting in C++ code.
*/ */
class AnonymousAttributeID : public ImplicitShareMixin { class AnonymousAttributeID : public ImplicitSharingMixin {
protected: protected:
std::string name_; std::string name_;

View File

@ -43,7 +43,7 @@ class Instances;
* copy-on-write behavior to avoid read-only copies. It also integrates with attribute API, which * copy-on-write behavior to avoid read-only copies. It also integrates with attribute API, which
* generalizes storing and modifying generic information on a geometry. * generalizes storing and modifying generic information on a geometry.
*/ */
class GeometryComponent : public blender::ImplicitShareMixin { class GeometryComponent : public blender::ImplicitSharingMixin {
private: private:
GeometryComponentType type_; GeometryComponentType type_;

View File

@ -32,18 +32,18 @@ namespace blender {
* #bCopyOnWrite is used in two ways: * #bCopyOnWrite is used in two ways:
* - It can be allocated separately from the referenced data as is typically the case with raw * - It can be allocated separately from the referenced data as is typically the case with raw
* arrays (e.g. for mesh attributes). * arrays (e.g. for mesh attributes).
* - It can be embedded into another struct. For that it's best to use #ImplicitShareMixin. * - It can be embedded into another struct. For that it's best to use #ImplicitSharingMixin.
*/ */
struct ImplicitShareInfo : blender::NonCopyable, blender::NonMovable { struct ImplicitSharingInfo : blender::NonCopyable, blender::NonMovable {
private: private:
mutable std::atomic<int> users_; mutable std::atomic<int> users_;
public: public:
ImplicitShareInfo(const int initial_users) : users_(initial_users) ImplicitSharingInfo(const int initial_users) : users_(initial_users)
{ {
} }
virtual ~ImplicitShareInfo() virtual ~ImplicitSharingInfo()
{ {
BLI_assert(this->is_mutable()); BLI_assert(this->is_mutable());
} }
@ -69,7 +69,7 @@ struct ImplicitShareInfo : blender::NonCopyable, blender::NonMovable {
BLI_assert(old_user_count >= 1); BLI_assert(old_user_count >= 1);
const bool was_last_user = old_user_count == 1; const bool was_last_user = old_user_count == 1;
if (was_last_user) { if (was_last_user) {
const_cast<ImplicitShareInfo *>(this)->delete_self_with_data(); const_cast<ImplicitSharingInfo *>(this)->delete_self_with_data();
} }
} }
@ -81,9 +81,9 @@ struct ImplicitShareInfo : blender::NonCopyable, blender::NonMovable {
/** /**
* Makes it easy to embed copy-on-write behavior into a struct. * Makes it easy to embed copy-on-write behavior into a struct.
*/ */
JacquesLucke marked this conversation as resolved Outdated

This comment is a bit hard to follow, maybe replacing the subclass with something more specific would help (like saying the ptr class can be used with a class that derives from the mixin class).

This comment is a bit hard to follow, maybe replacing `the subclass` with something more specific would help (like saying the ptr class can be used with a class that derives from the mixin class).
struct ImplicitShareMixin : public ImplicitShareInfo { struct ImplicitSharingMixin : public ImplicitSharingInfo {
public: public:
ImplicitShareMixin() : ImplicitShareInfo(1) ImplicitSharingMixin() : ImplicitSharingInfo(1)
{ {
} }

View File

@ -199,7 +199,7 @@ set(SRC
BLI_console.h BLI_console.h
BLI_convexhull_2d.h BLI_convexhull_2d.h
BLI_implicit_sharing.hh BLI_implicit_sharing.hh
BLI_implicit_sharing_user.hh BLI_implicit_sharing_ptr.hh
BLI_cpp_type.hh BLI_cpp_type.hh
BLI_cpp_type_make.hh BLI_cpp_type_make.hh
BLI_cpp_types.hh BLI_cpp_types.hh