class MTRefCountedObject
{
public:
void AddRef (const ThreadID&);
void Release (const ThreadID&);
protected:
map<ThreadID, uint> mdRefMap;
status_bitset mdStatus;
};
so, when using addref and release, we need to provide the "users" thread id. if object is used in nonMT enviroment, only one item is created in the map and the status is having the "notshared" flag. if used by multiple threads, more items are created and the status flag is chaneged to "shared".
now, this class provides a base for smart pointer templated class.
the next thing is the actuall data wrapper. as i see it, we need accessor functions which work based on the status. if shared flag is set, these functions will use internal locking, if not, "normal" way will be used.
pseudocode
template
class SharedData<TYPE>: public MTRefCountedObject
{
public:
TYPE ReadData ();
WriteData (TYPE);
protected:
private:
TYPE mdData; // actuall data
};
1) however, one thing is giving me troubles. how should read data be returned? as a temporary? is it logical to assume that "users" have their local copy of that object? what bout writing?
2) one idea is also to make a double buffered SharedData. now, this gives me an idea to make a base class (abstract?) "SharedData", on which SharedDataSimple and SharedDataDoubleBuf would be implemented. this makes any sense?
Abnormal behaviour of abnormal brain makes me normal...