void interruptHandler(IntType which) { switch (which) { case TimerInt: DEBUG('e', "TimerInt interruput\n"); if(current!=NULL){ //printf("reinserting pid %d\n",current->pid); l_insert(readyq,current); } else{ //printf("current is NULL at timer interrupt\n"); } scheduler(); break; case ConsoleReadInt: DEBUG('e', "ConsoleReadInt interrupt\n"); if(consolewait !=NULL){ V_kt_sem(consolewait); } if(current!=NULL){ l_insert(readyq,current); } scheduler(); break; case ConsoleWriteInt: DEBUG('e', "ConsoleWriteInt interrupt\n"); if(writeok!=NULL){ //printf("increment writeok\n"); V_kt_sem(writeok); } /* if(current!=NULL){ printf("reinserting pid %d\n",p->pid); l_insert(readyq,*p); } */ else{ //printf("this shouldn't happen\n"); } scheduler(); break; default: DEBUG('e', "Unknown interrupt\n"); scheduler(); break; } }
/* RETURN 0 - ok -1 - out of memory */ static int initialize_bucket(LF_HASH *hash, LF_SLIST * volatile *node, uint bucket, LF_PINS *pins) { uint parent= my_clear_highest_bit(bucket); LF_SLIST *dummy= (LF_SLIST *)my_malloc(sizeof(LF_SLIST), MYF(MY_WME)); LF_SLIST **tmp= 0, *cur; LF_SLIST * volatile *el= _lf_dynarray_lvalue(&hash->array, parent); if (unlikely(!el || !dummy)) return -1; if (*el == NULL && bucket && unlikely(initialize_bucket(hash, el, parent, pins))) return -1; dummy->hashnr= my_reverse_bits(bucket) | 0; /* dummy node */ dummy->key= dummy_key; dummy->keylen= 0; if ((cur= l_insert(el, hash->charset, dummy, pins, LF_HASH_UNIQUE))) { my_free(dummy); dummy= cur; } my_atomic_casptr((void **)node, (void **)(char*) &tmp, dummy); /* note that if the CAS above failed (after l_insert() succeeded), it would mean that some other thread has executed l_insert() for the same dummy node, its l_insert() failed, it picked up our dummy node (in "dummy= cur") and executed the same CAS as above. Which means that even if CAS above failed we don't need to retry, and we should not free(dummy) - there's no memory leak here */ return 0; }
/* DESCRIPTION inserts a new element to a hash. it will have a _copy_ of data, not a pointer to it. RETURN 0 - inserted 1 - didn't (unique key conflict) -1 - out of memory NOTE see l_insert() for pin usage notes */ int lf_hash_insert(LF_HASH *hash, LF_PINS *pins, const void *data) { int csize, bucket, hashnr; LF_SLIST *node, * volatile *el; lf_rwlock_by_pins(pins); node= (LF_SLIST *)_lf_alloc_new(pins); if (unlikely(!node)) return -1; memcpy(node+1, data, hash->element_size); node->key= hash_key(hash, (uchar *)(node+1), &node->keylen); hashnr= calc_hash(hash, node->key, node->keylen); bucket= hashnr % hash->size; el= _lf_dynarray_lvalue(&hash->array, bucket); if (unlikely(!el)) return -1; if (*el == NULL && unlikely(initialize_bucket(hash, el, bucket, pins))) return -1; node->hashnr= my_reverse_bits(hashnr) | 1; /* normal node */ if (l_insert(el, hash->charset, node, pins, hash->flags)) { _lf_alloc_free(pins, node); lf_rwunlock_by_pins(pins); return 1; } csize= hash->size; if ((my_atomic_add32(&hash->count, 1)+1.0) / csize > MAX_LOAD) my_atomic_cas32(&hash->size, &csize, csize*2); lf_rwunlock_by_pins(pins); return 0; }
// Fill with ptr to random int upto location void populate_random_ints(list *l, int howmuch){ for (int i = 0; i < howmuch ; i++){ int *number = malloc(sizeof(number)); *number = i; l_insert(l, number, 0); } }
int main(void) { List *tp, *root_p = NULL; int i, ins[] = {4,2,6,1,3,4,7}; for(i = 0; i < 7; i++) if(!(root_p = l_insert(root_p, ins[i]))) err(1, "Malloc error"); // can't insert for(i = 0; i < 9; i++){ tp = l_search(root_p, i, NULL, NULL); printf("%d ", i); if(!tp) printf("not "); printf("found\n"); } printf("now delete items 1, 4 and 8\n"); l_remove(&root_p, 1); l_remove(&root_p, 4); l_remove(&root_p, 8); for(i = 0; i < 9; i++){ tp = l_search(root_p, i, NULL, NULL); printf("%d ", i); if(!tp) printf("not "); printf("found\n"); } return 0; }
void dl_insert(List list, int index, double value) { assert_argument_not_null(list); dl_assert_element_size(list); l_insert(list, index, &value); }
FUNCTION objend () { register Ocb * o; extern int aggressive; Debug o = xqting_ocb; destroy_message_vector (o); if ( o->centry == DCRT || o->centry == DDES ) { unmark_macro ( o->ci ); } else { register Msgh * n; for ( n = fstigb ( o->ci ); n; n = nxtigb ( n ) ) { if ( n->mtype != DYNDSMSG ) unmark_macro ( n ); } } if ( o->centry == INIT || o->centry == DCRT || o->centry == DDES ) { #ifdef SOM /* Update the phase's highest-seen ept field to the Ept of the event just completed. Also update the amount of total unrolled back work done by the phase. */ o->Ept = o->sb->Ept; #endif SOM save_state (o); } if ( o->centry == EVENT ) { o->stats.numecomp++; o->eventTimePermitted -= o->sb->effectWork; #ifdef SOM /* Update the phase's highest-seen ept field to the Ept of the event just completed. Also update the amount of total unrolled back work done by the phase. */ o->Ept = o->sb->Ept; #endif SOM save_state ( o ); } else if ( o->centry == TERM ) { #ifdef RBC if ( o->uses_rbc ) l_destroy ( o->sb ); else /* destroy_state and rollback chip don't mix */ #endif destroy_state ( o->sb ); o->sb = NULL; l_destroy ( o->stk ); o->stk = NULL; #ifdef RBC if ( o->uses_rbc && rollback_op ( o, 1, posinfPlus1 ) ) { printf ( "weird error term objend for %s\n", o->name ); tester(); } #endif o->ci = NULL; o->co = NULL; o->control = EDGE; o->runstat = BLKINF; if ( ! aggressive ) cancel_omsgs ( o, o->svt, o->phase_end ); l_remove ( o ); o->svt = posinfPlus1; l_insert ( l_prev_macro ( _prqhd ), o ); dispatch (); return; } go_forward ( o ) ; dispatch (); }
void pl_insert(List list, int index, Any value) { assert_argument_not_null(list); pl_assert_element_size(list); l_insert(list, index, &value); }