/** Initialize allocated memory as a slab cache */ static void _slab_cache_create(slab_cache_t *cache, size_t size, size_t align, int (*constructor)(void *obj, int kmflag), int (*destructor)(void *obj), int flags) { int pages; // ipl_t ipl; // memsetb((uintptr_t)cache, sizeof(*cache), 0); // cache->name = name; //if (align < sizeof(unative_t)) // align = sizeof(unative_t); // size = ALIGN_UP(size, align); cache->size = size; // cache->constructor = constructor; // cache->destructor = destructor; cache->flags = flags; list_initialize(&cache->full_slabs); list_initialize(&cache->partial_slabs); list_initialize(&cache->magazines); // spinlock_initialize(&cache->slablock, "slab_lock"); // spinlock_initialize(&cache->maglock, "slab_maglock"); // if (! (cache->flags & SLAB_CACHE_NOMAGAZINE)) // make_magcache(cache); /* Compute slab sizes, object counts in slabs etc. */ /* Minimum slab order */ pages = SIZE2FRAMES(cache->size); /* We need the 2^order >= pages */ if (pages <= 1) cache->order = 0; else cache->order = fnzb(pages-1)+1; while (badness(cache) > SLAB_MAX_BADNESS(cache)) { cache->order += 1; } cache->objects = comp_objects(cache); /* Add cache to cache list */ // ipl = interrupts_disable(); // spinlock_lock(&slab_cache_lock); list_append(&cache->link, &slab_cache_list); // spinlock_unlock(&slab_cache_lock); // interrupts_restore(ipl); }
int tex::vert_badness(int height) { int b; if (cur_height < height) { if (active_height[3] != 0 || active_height[4] != 0 || active_height[5] != 0) { b = 0; } else { b = badness(height - cur_height, active_height[2]); } } else if (cur_height - height > active_height[6]) { b = AWFUL_BAD; } else { b = badness(cur_height - height, active_height[6]); } return b; }
int tex::page_badness () { int b; if (page_total < page_goal) { if (page_so_far[3] != 0 || page_so_far[4] != 0 || page_so_far[5] != 0) { b = 0; } else { b = badness(page_goal - page_total, page_so_far[2]); } } else if (page_total - page_goal > page_shrink) { b = AWFUL_BAD; } else { b = badness(page_total - page_goal, page_shrink); } return b; }
int wordwrap (char *str, int n) { DP[n] = 0; for (i=n; i>=0; i++) { for (j=i+1; j<n+1; j++) { DP[i] = min (DP[i], badness(i,j)); } } }
/* * Simple selection loop. We chose the process with the highest * number of 'points'. We expect the caller will lock the tasklist. * * (not docbooked, we don't want this one cluttering up the manual) */ static struct task_struct * select_bad_process(void) { int maxpoints = 0; struct task_struct *p = NULL; struct task_struct *chosen = NULL; for_each_task(p) { if (p->pid) { int points = badness(p); if (points > maxpoints) { chosen = p; maxpoints = points; } } } return chosen; }
static void possible_break( CompositorIndex index, Coord* spans, CompositorIndex span_count, Coord natural, Coord stretch, Coord shrink, int penalty, int breakpenalty, BreakSet* breaks ) { BreakSet* best_break = nil; BreakSet* doomed; int least_demerits; BreakSet* b = breaks->next_; while (b != breaks) { Coord span = spans[Math::min(b->count_, span_count-1)]; b->no_break(natural, stretch, shrink); int break_badness = badness( span, b->natural_, b->stretch_, b->shrink_ ); boolean only_break = b == breaks->next_ && b->next_ == breaks; if (penalty <= PenaltyGood) { int break_demerits = demerits( break_badness, penalty, breakpenalty ); if (best_break == nil) { b->add_break(index, break_demerits); best_break = b; least_demerits = b->demerits_; } else if (b->demerits_ + break_demerits < least_demerits) { delete best_break; b->add_break(index, break_demerits); best_break = b; least_demerits = b->demerits_; } else { if (!only_break) { doomed = b; b = b->prev_; delete doomed; } } } else if (break_badness < -TOLERANCE) { if (only_break) { int break_demerits = demerits( break_badness, penalty, breakpenalty ); b->add_break(index, break_demerits); best_break = b; least_demerits = b->demerits_; } else { doomed = b; b = b->prev_; delete doomed; } } else if (break_badness <= TOLERANCE) { int break_demerits = demerits( break_badness, penalty, breakpenalty ); if (best_break == nil) { new BreakSet(b); b = b->next_; b->add_break(index, break_demerits); best_break = b; least_demerits = b->demerits_; } else if (b->demerits_ + break_demerits < least_demerits) { delete best_break; new BreakSet(b); b = b->next_; b->add_break(index, break_demerits); best_break = b; least_demerits = b->demerits_; } } b = b->next_; } }
int arr[256]; }; constexpr V v; constexpr int get(const int *p) { return *p; } // expected-note {{read of dereferenced one-past-the-end pointer}} constexpr int passLargeArray(V v) { return get(v.arr+256); } // expected-note {{in call to 'get(&v.arr[256])'}} static_assert(passLargeArray(v) == 0, ""); // expected-error {{constant expression}} expected-note {{in call to 'passLargeArray({{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ...}})'}} union Union { constexpr Union(int n) : b(n) {} constexpr Union(const Union &u) : b(u.b) {} int a, b; }; constexpr Union myUnion = 76; constexpr int badness(Union u) { return u.a + u.b; } // expected-note {{read of member 'a' of union with active member 'b'}} static_assert(badness(myUnion), ""); // expected-error {{constant expression}} \ expected-note {{in call to 'badness({.b = 76})'}} struct MemPtrTest { int n; void f(); }; MemPtrTest mpt; // expected-note {{here}} constexpr int MemPtr(int (MemPtrTest::*a), void (MemPtrTest::*b)(), int &c) { return c; // expected-note {{read of non-constexpr variable 'mpt'}} } static_assert(MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.*&MemPtrTest::n), ""); // expected-error {{constant expression}} \ expected-note {{in call to 'MemPtr(&MemPtrTest::n, &MemPtrTest::f, mpt.n)'}} template<typename CharT> constexpr CharT get(const CharT *p) { return p[-1]; } // expected-note 5{{}}