diff --git a/src/backend.cmod b/src/backend.cmod index b9830e1d6af231587b1a325f7a83a893229557b5..c6e21962cbba6bd09b883e7aee5b5f756e872411 100644 --- a/src/backend.cmod +++ b/src/backend.cmod @@ -612,164 +612,164 @@ PIKECLASS Backend if(!adjust_up(me,pos)) adjust_down(me,pos); } -/* start a new call out, return 1 for success */ - static struct array * new_call_out(struct Backend_struct *me, - int num_arg) - { - call_out *new; - struct array *args; - size_t fun_hval; - size_t hval; + /* start a new call out, return 1 for success */ + static struct array *new_call_out(struct Backend_struct *me, + int num_arg) + { + call_out *new; + struct array *args; + size_t fun_hval; + size_t hval; - /* NOTE: hash_svalue() can run Pike code! */ - fun_hval = hash_svalue(Pike_sp + 1 - num_arg); + /* NOTE: hash_svalue() can run Pike code! */ + fun_hval = hash_svalue(Pike_sp + 1 - num_arg); - PROTECT_CALL_OUTS(); - if(me->num_pending_calls == me->call_heap_size) - { - /* here we need to allocate space for more pointers */ - call_out **new_heap; + PROTECT_CALL_OUTS(); + if(me->num_pending_calls == me->call_heap_size) + { + /* here we need to allocate space for more pointers */ + call_out **new_heap; - if(!me->call_heap) - { - me->call_heap_size = 128; - me->call_heap = - (call_out **)xalloc(sizeof(call_out *)*me->call_heap_size); - if(!me->call_heap) return 0; - MEMSET(me->call_heap, 0, sizeof(call_out *)*me->call_heap_size); - me->num_pending_calls=0; - - me->hash_size=hashprimes[me->hash_order]; - me->call_hash = - (struct hash_ent *)xalloc(sizeof(struct hash_ent)*me->hash_size); - MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); - }else{ - struct hash_ent *new_hash; - int e; - - new_heap = (call_out **) - realloc((char *)me->call_heap, - sizeof(call_out *)*me->call_heap_size*2); - if(!new_heap) - Pike_error("Not enough memory for another call_out\n"); - MEMSET(new_heap + me->call_heap_size, 0, - sizeof(call_out *)*me->call_heap_size); - me->call_heap_size *= 2; - me->call_heap = new_heap; - - if((new_hash=(struct hash_ent *)malloc(sizeof(struct hash_ent)* - hashprimes[me->hash_order+1]))) - { - free((char *)me->call_hash); - me->call_hash=new_hash; - me->hash_size=hashprimes[++me->hash_order]; - MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); + if(!me->call_heap) + { + me->call_heap_size = 128; + me->call_heap = + (call_out **)xalloc(sizeof(call_out *)*me->call_heap_size); + if(!me->call_heap) return 0; + MEMSET(me->call_heap, 0, sizeof(call_out *)*me->call_heap_size); + me->num_pending_calls = 0; + + me->hash_size = hashprimes[me->hash_order]; + me->call_hash = + (struct hash_ent *)xalloc(sizeof(struct hash_ent)*me->hash_size); + MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); + }else{ + struct hash_ent *new_hash; + int e; + + new_heap = (call_out **) + realloc((char *)me->call_heap, + sizeof(call_out *)*me->call_heap_size*2); + if(!new_heap) + Pike_error("Not enough memory for another call_out\n"); + MEMSET(new_heap + me->call_heap_size, 0, + sizeof(call_out *)*me->call_heap_size); + me->call_heap_size *= 2; + me->call_heap = new_heap; + + if((new_hash=(struct hash_ent *)malloc(sizeof(struct hash_ent)* + hashprimes[me->hash_order+1]))) + { + free((char *)me->call_hash); + me->call_hash = new_hash; + me->hash_size = hashprimes[++me->hash_order]; + MEMSET(me->call_hash, 0, sizeof(struct hash_ent)*me->hash_size); - /* Re-hash */ - for(e=0;e<me->num_pending_calls;e++) - { - call_out *c=CALL(e); - hval=PTR_TO_INT(c->args); + /* Re-hash */ + for(e=0;e<me->num_pending_calls;e++) + { + call_out *c = CALL(e); + hval = PTR_TO_INT(c->args); #define LINK(X,c) \ - hval%=me->hash_size; \ - if((c->PIKE_CONCAT(next_,X)=me->call_hash[hval].X)) \ - c->PIKE_CONCAT(next_,X)->PIKE_CONCAT(prev_,X)= \ - &c->PIKE_CONCAT(next_,X); \ - c->PIKE_CONCAT(prev_,X)=&me->call_hash[hval].X; \ - me->call_hash[hval].X=c - - LINK(arr,c); - hval=c->fun_hval; - LINK(fun,c); - } - } - } - } + hval %= me->hash_size; \ + if((c->PIKE_CONCAT(next_,X) = me->call_hash[hval].X)) \ + c->PIKE_CONCAT(next_,X)->PIKE_CONCAT(prev_,X) = \ + &c->PIKE_CONCAT(next_,X); \ + c->PIKE_CONCAT(prev_,X) = &me->call_hash[hval].X; \ + me->call_hash[hval].X = c + + LINK(arr,c); + hval = c->fun_hval; + LINK(fun,c); + } + } + } + } - /* time to allocate a new call_out struct */ - push_array(args=aggregate_array(num_arg-1)); + /* time to allocate a new call_out struct */ + push_array(args = aggregate_array(num_arg-1)); #ifdef PIKE_DEBUG - if (CALL(me->num_pending_calls)) { - Pike_fatal("Lost call out in heap.\n"); - } + if (CALL(me->num_pending_calls)) { + Pike_fatal("Lost call out in heap.\n"); + } #endif /* PIKE_DEBUG */ - - CALL_(me->num_pending_calls) = new = alloc_call_out(); - new->pos=me->num_pending_calls; - - { - hval=PTR_TO_INT(args); - LINK(arr,new); - hval = new->fun_hval = fun_hval; - LINK(fun,new); - } - - switch(TYPEOF(Pike_sp[-2])) - { - case T_INT: - new->tv.tv_sec=Pike_sp[-2].u.integer; - new->tv.tv_usec=0; - break; - - case T_FLOAT: - { - FLOAT_TYPE tmp=Pike_sp[-2].u.float_number; - new->tv.tv_sec = DO_NOT_WARN((long)floor(tmp)); - new->tv.tv_usec = DO_NOT_WARN((long)(1000000.0 * (tmp - floor(tmp)))); - break; - } - - default: - Pike_fatal("Bad timeout to new_call_out!\n"); - } - + + CALL_(me->num_pending_calls) = new = alloc_call_out(); + new->pos = me->num_pending_calls; + + { + hval = PTR_TO_INT(args); + LINK(arr,new); + hval = new->fun_hval = fun_hval; + LINK(fun,new); + } + + switch(TYPEOF(Pike_sp[-2])) + { + case T_INT: + new->tv.tv_sec = Pike_sp[-2].u.integer; + new->tv.tv_usec = 0; + break; + + case T_FLOAT: + { + FLOAT_TYPE tmp = Pike_sp[-2].u.float_number; + new->tv.tv_sec = DO_NOT_WARN((long)floor(tmp)); + new->tv.tv_usec = DO_NOT_WARN((long)(1000000.0 * (tmp - floor(tmp)))); + break; + } + + default: + Pike_fatal("Bad timeout to new_call_out!\n"); + } + #ifdef _REENTRANT - if(num_threads>1) - { - struct timeval tmp; - ACCURATE_GETTIMEOFDAY(&tmp); - my_add_timeval(& new->tv, &tmp); - IF_CO (fprintf (stderr, "BACKEND[%d]: Adding call out at %ld.%ld " - "(current time is %ld.%ld)\n", me->id, - new->tv.tv_sec, new->tv.tv_usec, - tmp.tv_sec, tmp.tv_usec)); - }else + if(num_threads>1) + { + struct timeval tmp; + ACCURATE_GETTIMEOFDAY(&tmp); + my_add_timeval(& new->tv, &tmp); + IF_CO (fprintf (stderr, "BACKEND[%d]: Adding call out at %ld.%ld " + "(current time is %ld.%ld)\n", me->id, + new->tv.tv_sec, new->tv.tv_usec, + tmp.tv_sec, tmp.tv_usec)); + } else #endif - { - struct timeval tmp; - INACCURATE_GETTIMEOFDAY(&tmp); - my_add_timeval(& new->tv, &tmp); - IF_CO (fprintf (stderr, "BACKEND[%d]: Adding call out at %ld.%ld " - "(current_time is %ld.%ld)\n", me->id, - new->tv.tv_sec, new->tv.tv_usec, - tmp.tv_sec, tmp.tv_usec)); - } + { + struct timeval tmp; + INACCURATE_GETTIMEOFDAY(&tmp); + my_add_timeval(& new->tv, &tmp); + IF_CO (fprintf (stderr, "BACKEND[%d]: Adding call out at %ld.%ld " + "(current_time is %ld.%ld)\n", me->id, + new->tv.tv_sec, new->tv.tv_usec, + tmp.tv_sec, tmp.tv_usec)); + } - if(Pike_fp && Pike_fp->current_object) - { - add_ref(new->caller=Pike_fp->current_object); - }else{ - new->caller=0; - } - - new->args=args; - Pike_sp -= 2; - dmalloc_touch_svalue(Pike_sp); - + if(Pike_fp && Pike_fp->current_object) + { + add_ref(new->caller = Pike_fp->current_object); + } else { + new->caller = 0; + } - me->num_pending_calls++; - adjust_up(me, me->num_pending_calls-1); - backend_verify_call_outs(me); + new->args = args; + Pike_sp -= 2; + dmalloc_touch_svalue(Pike_sp); + + + me->num_pending_calls++; + adjust_up(me, me->num_pending_calls-1); + backend_verify_call_outs(me); #ifdef _REENTRANT - backend_wake_up_backend(me); + backend_wake_up_backend(me); #endif - UNPROTECT_CALL_OUTS(); - return args; - } + UNPROTECT_CALL_OUTS(); + return args; + } static void backend_count_memory_in_call_outs(struct Backend_struct *me) {