| 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); |
no test coverage detected