public import "ecere"
#endif
-// For idRowCache connection...
-import "idList"
-
#include <stdarg.h>
#ifdef _DEBUG
Field memberIdField;
};
+Mutex idRowCacheMutex { };
+
public class Table
{
class_no_expansion;
Table prev, next;
Database db;
OldList listRows { offset = (uint)&((Row)0).prev };
+ Row cachedIdRow;
public:
virtual String GetName();
virtual Field GetFirstField();
~Table()
{
Row row;
- MapIterator<Table, Row> it { map = idRowCache };
- // Remove row from Id row cache
- idRowCache.mutex.Wait();
- if(it.Index(this, false))
- {
- Row r = it.data;
- if(_refCount < 2)
- _refCount = 2; // Removing the Table entry will try to decref the table ('this') again
- it.Remove(r);
- delete r;
- }
- idRowCache.mutex.Release();
+ // Delete cached Id row
+ idRowCacheMutex.Wait();
+ delete cachedIdRow;
+ idRowCacheMutex.Release();
#ifdef AUTO_DELETE_TABLES
if(db)
}
private:
-class IdRowCache : Map<Table, Row>
-{
- Mutex mutex { };
- Row GetRow(Table tbl)
- {
- MapIterator<Table, Row> it { map = this };
- mutex.Wait();
- if(it.Index(tbl, false))
- {
- Row r = it.data;
- return it.data;
- }
- else
- {
- Row r { tbl };
- this[tbl] = r;
- return r;
- }
- }
- ~IdRowCache()
- {
- Free();
- }
-}
-IdRowCache idRowCache { };
-
public class Id : uint
{
class_data Table * table; class_property Table * table { set { class_data(table) = value; } get { return class_data(table); } };
// FIXME
Table tbl = *class_data(table);
Field idField = tbl.FindField(defaultIdField);
- Row r = idRowCache.GetRow(tbl);
+ Row r;
+ idRowCacheMutex.Wait();
+ if(!tbl.cachedIdRow)
+ {
+ tbl.cachedIdRow = Row { tbl };
+ incref tbl.cachedIdRow;
+ }
+ r = tbl.cachedIdRow;
if(this)
{
sprintf(tempString, $"(Click to add a new %s...)", $"item"/*class_data(addText)*/);
}
// delete r;
- idRowCache.mutex.Release();
+ idRowCacheMutex.Release();
}
return tempString;
}