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

Method remove_at

Kernel/include/list.h:375–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

373 }
374
375 T remove_at(unsigned pos) {
376 assert(num > 0);
377 assert(pos < num);
378 assert(front != nullptr);
379
380 acquireLock(&lock);
381
382 ListNode<T>* current = front;
383
384 for (unsigned int i = 0; i < pos && current; i++) current = current->next;
385
386 assert(current);
387
388 T obj = current->obj;
389
390 num--;
391
392 if (current->next) current->next->prev = current->prev;
393 if (current->prev) current->prev->next = current->next;
394 if (pos == 0) front = current->next;
395 if (pos == num) back = current->prev;
396
397 if(cache.get_length() >= maxCache){
398 kfree(current);
399 } else {
400 cache.add_back(current);
401 }
402
403 if(!num) front = back = nullptr;
404
405 releaseLock(&lock);
406
407 return obj;
408 }
409
410 void remove(T val){
411 if(num <= 0 || !front){

Callers 15

WriteMethod · 0.45
ReadMethod · 0.45
EndProcessFunction · 0.45
HandlerFunction · 0.45
Master_WriteMethod · 0.45
Slave_WriteMethod · 0.45
AcceptMethod · 0.45
ConnectMethod · 0.45
WriteMethod · 0.45
ConnectToMethod · 0.45
OnDisconnectMethod · 0.45
AcceptMethod · 0.45

Calls 3

kfreeFunction · 0.85
get_lengthMethod · 0.45
add_backMethod · 0.45

Tested by

no test coverage detected