c++ - concurrent reference counter class and scoped retain: is this ok? -
This is a question about coding design, so please forgive the long code lists: Could not start and potentially damage without displaying the actual code.
I am writing a concurrent reference math class and appreciate some feedback on my implementation. Sub-classes of this class will get "Release" instead of being directly deleted.
There is a class:
category concurrent reference math: private non-usable {public: concurrent reference math (): Ref_count_ (1) {} virtual {concurrent reference math () {} Retaining zero () {scoddock lock (mute x_); ++ ref_count_; } Zero Release () {bool should_die = false; {ScopedLock lock (mutex_); Should_die = --ref_count_ == 0; } If (should_d) delete it; } Private: size_t ref_count_; Mute x Mute x_; };
And here a scope has been maintained:
class ScopedRetain {public: ScopedRetain (concurrent reference math * object): object_ (object) {retain (); } ScopedRetain (): object_ (NULL) {} ~ ScopedRetain () {Release}; } Zero hold (concurrent reference math * object) {emphasis (! Object_); // More if not 1 Object object_ = Object can not; to maintain (); } Private: Concurrent reference math * Object_; Zero release () {if object_) object _- & gt; Release (); } Zero maintained () {object_-> Maintain (); }};
And finally this is the case:
object * target; Scospratan SR; If (objects_.get (key, and target)) sr.hold (target); Other Returns; // There is no need to 'release' the use target //
Your Concurrent reference math
seems to be using a complete mute x, which is not necessary and is not very fast. Reference calculations can be executed using nuclear architecture-based interlocked instructions. Under Windows, the InterlaxxXX
function of Fasli wraps these instructions
Comments
Post a Comment