Today I did some work on "unifying" the basic kernel containers. Today's target was ObjectManager and DataManager.
Because they're hardly different, I combined them into something called "FixedArray."
FixedArray is basically an array that you can initialize with any size you want. Now it's got a feature where you can choose what memory allocator function(kstruct or pmem) you'd like to use for allocating the array.
The array comes with a wrapper structure with a field called "occupied", a boolean member who tells whether the slot is taken or not. Using this, the add() behavior of the FixedArray automatically searches the first-found non-occupied slot, insert the provided data, and return the index(id) of the occupied slot. It's nearly identical to ObjectManager and DataManager, but one key difference is that FixedArray also got add_empty_space() behavior(that's identical to register_space() in the DataManager).
max_t add_empty_space() {
if(container == 0x00) {
return INVALID;
}
if(count >= max_count) return INVALID;
max_t i = 0;
for(; i < max_count; i++) {
if(container[i].occupied == false) break;
}
if(i >= max_count) return INVALID; // all object is occupied
container[i].occupied = true;
count++;
return i;
}
It's identical to add(), but the key difference is that it doesn't "set" the data field of the data_container_s wrapper structure. The reason for this is because you sometimes want to only have the space and not initialize the data (yet.) This might become deprecated later, because there's actually no point of this if you have add() with the argument as constant reference to the data that'll be copied.
By the way, that problem I was taking about--it never disappeared. If I add completely unrelated code, like printing out random debug messages, the system would completely froze, and when debugged the point where error transpired, it's usually regarding on calling the singleton object accessor. The problem here is that the result of the address of the singleton object is not always consistent, which completely loses the meaning of using singleton object! I think it's definitely something to do with the static variables. I will fix it tomorrow.