MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / insert

Method insert

Kernel/include/list.h:302–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

300 }
301
302 void insert(const T& obj, size_t pos){
303 if(!num){
304 add_back(obj);
305 return;
306 }
307
308 if(!pos){
309 add_front(obj);
310 return;
311 }
312
313 acquireLock(&lock);
314 ListNode<T>* current = front;
315
316 for (unsigned int i = 0; i < pos && i < num && current->next; i++) current = current->next;
317
318 ListNode<T>* node;
319 if(!cache.get_length()){
320 node = (ListNode<T>*)kmalloc(sizeof(ListNode<T>));
321 } else {
322 node = cache.remove_at(0);
323 }
324
325 assert(node);
326
327 node->obj = obj;
328 node->prev = current;
329 node->next = current->next;
330 current->next = node;
331
332 num++;
333
334 releaseLock(&lock);
335 }
336
337 T& operator[](unsigned pos) {
338 return get_at(pos);

Callers 15

DoAnsiCSIFunction · 0.45
JSONParserMethod · 0.45
CFGParserMethod · 0.45
OnKeyPressMethod · 0.45
GetAllHandlesMethod · 0.45
DoAnsiCSIFunction · 0.45
ReadLineFunction · 0.45
PollCommandsMethod · 0.45
AddWindowFunction · 0.45
SysFutexWaitFunction · 0.45
BlockMethod · 0.45
ReadBlockCachedMethod · 0.45

Calls 3

kmallocFunction · 0.85
get_lengthMethod · 0.45
remove_atMethod · 0.45

Tested by

no test coverage detected