void init_depth(ulong depth) { ulong i; max_depth = depth; /* we count from 0 to n */ stack = (frame_t *)malloc((depth + 1) * sizeof(frame_t)); for (i = 0; i <= max_depth; ++i) { QINIT(&stack[i].q, "stack[%lu].q", i); stack[i].actual = (ulong)0; stack[i].best_bits_num = (ulong)0; stack[i].best_bits_den = (ulong)0; } solved = 0; QINIT(&limit_calc, "depth limit_calc"); ZINIT(&limit_div, "depth limit_div"); }
/*! \internal \brief Preps a thread for use with kmq \note Obtains ::cs_kmq_global */ void kmqint_attach_this_thread(void) { kmq_queue * q; EnterCriticalSection(&cs_kmq_global); q = (kmq_queue *) TlsGetValue(kmq_tls_queue); if(!q) { q = PMALLOC(sizeof(kmq_queue)); InitializeCriticalSection(&q->cs); q->thread = GetCurrentThreadId(); QINIT(q); LINIT(q); q->wait_o = CreateEvent(NULL, FALSE, FALSE, NULL); q->load = 0; q->last_post = 0; q->flags = 0; LPUSH(&queues, q); TlsSetValue(kmq_tls_queue, (LPVOID) q); } LeaveCriticalSection(&cs_kmq_global); }
void kcdbint_identpro_init(void) { InitializeCriticalSection(&cs_identpro); QINIT(&id_providers); deleted_id_providers = NULL; n_id_providers = 0; }
void pp_save_r(int n, int prime, int power) { pp_pp* pp = &pppp[power]; pp_value* v; int i, raise; mpq_t q; if (!pp->p) new_pp(pp, prime, power); QINIT(&q, "pp_save_r temp"); mpq_set_ui(q, 1, n); pp_save_any(pp, q, n, 1); QCLEAR(&q, "pp_save_r temp"); }
void new_pp(pp_pp* pp, int prime, int power) { int i, set; mpz_t reduced_denom; mpx_support* xsup; if (prime > MAX_P) { fprintf(stderr, "prime %d exceeds max %d\n", prime, MAX_P); exit(1); } pp->p = prime; pp->pp = power; if (pp->p == pp->pp) inverse_table(pp->p); pp_pushlist(pp); ZINIT(&pp->total, "pp_%d.total", pp->pp); ZINIT(&pp->denominator, "pp_%d.denominator", pp->pp); ZINIT(&pp->min_discard, "pp_%d.min_discard", pp->pp); QINIT(&pp->spare, "pp_%d.spare", pp->pp); /* required denominator is the lcm of (power, S) where S contains those * pp such that pp * power <= k. */ ZINIT(&reduced_denom, "new_pp reduced_denom"); set = 0; /* start from pplist[1], because we've already been inserted at [0] */ for (i = 1; i < pplistsize; ++i) { if (pplist[i]->pp * power <= k0) { mpz_mul_ui(pp->denominator, pplist[i]->denominator, power / mpz_gcd_ui(NULL, pplist[i]->denominator, power)); set = 1; break; } } if (!set) { /* power == 1 */ if (power != 1) { fprintf(stderr, "new_pp: did not find denominator for %d\n", power); exit(1); } mpz_set_ui(pp->denominator, 1); } mpz_divexact_ui(reduced_denom, pp->denominator, power); pp->invdenom = invfast(mod_ui(reduced_denom, pp->p), pp->p); ZCLEAR(&reduced_denom, "new_pp reduced_denom"); xsup = mpx_support_z(pp->denominator); pp->valnumsize = xsup->size; pp->adder = xsup->adder; pp->cmper = xsup->cmper; pp_grow(pp, MINPPSET); }
void pp_init_spare(int target) { int i; pp_pp *pp, *top; mpq_t spare; QINIT(&spare, "pp_study spare"); top = pplist[0]; mpq_set_si(top->spare, -target, 1); for (i = 0; i < pplistsize; ++i) { int g; pp = pplist[i]; mpz_sub(mpq_numref(spare), pp->total, pp->min_discard); mpz_set(mpq_denref(spare), pp->denominator); mpq_canonicalize(spare); mpq_add(top->spare, top->spare, spare); } QCLEAR(&spare, "pp_study spare"); Dprintf("study: spare = %Qd\n", top->spare); }
/* create new service queue. return current queue if exists. */ struct tpservice *new_service(char *svcname) { assert(svcname); debug(1, "new_service(%.*s)", XATMI_SERVICE_NAME_LENGTH, svcname); struct tpservice *svc = malloc(sizeof(struct tpservice)); if (svc) { strncpy(svc->svcname, svcname, XATMI_SERVICE_NAME_LENGTH); QINIT(svc->waitq); svc->wait_contains_transactions = 0; svc->ttrans = svc->tmsec = 0; struct tpservice **svc2 = tsearch(svc, &services, cmp_service); if (svc2 == 0 || *svc2 != svc) { debug(1, "existing service found. freeing new duplicate."); free(svc); svc = svc2 ? *svc2 : 0; } } debug(2, "new_service(%.*s) -> 0x%x", XATMI_SERVICE_NAME_LENGTH, svcname, svc); return svc; }
KHMEXP khm_int32 KHMAPI kmq_init(void) { if (InterlockedIncrement(&kmq_init_once) == 1) { EnterCriticalSection(&cs_kmq_global); InitializeCriticalSection(&cs_compl); compl_wx = CreateEvent(NULL, FALSE, FALSE, NULL); compl_continue = TRUE; QINIT(&kmq_completion_xfer); kmq_h_compl = CreateThread(NULL, 0, kmqint_completion_thread_proc, NULL, 0, &kmq_tid_compl); assert(kmq_h_compl != NULL); LeaveCriticalSection(&cs_kmq_global); } return KHM_ERROR_SUCCESS; }
void pp_save_w(whp wh, wrhp wrh, pp_pp* from) { mpq_t actual; mpz_t discard; int pp_effective = from->pp; int pp_applied = 1; int pp_p = from->p; int q, to, shared; pp_pp* pp; pp_value* v; ZINIT(&discard, "pp_save_w discard"); QINIT(&actual, "pp_save_w temp"); mpz_set_x(discard, wr_discard(wh, wrh), from->valnumsize); Dprintf("save wr: %Zd / %Zd [%d] from %d (%d)\n", discard, from->denominator, wr_vec(wh, wrh)[0], from->pp, from->p); mpz_sub(mpq_numref(actual), from->total, discard); mpz_set(mpq_denref(actual), from->denominator); mpq_canonicalize(actual); to = z_greatest_prime_power(mpq_denref(actual), (int*)NULL); pp_save_any(&pppp[to], actual, from->pp, 0); QCLEAR(&actual, "pp_save_w temp"); ZCLEAR(&discard, "pp_save_w discard"); }