int BlurZoomMain::start_realtime() { buf_width_blocks = project_frame_w / 32; buf_width = buf_width_blocks * 32; buf_height = project_frame_h; buf_area = buf_width * buf_height; buf_margin_left = (project_frame_w - buf_width) / 2; buf_margin_right = project_frame_w - buf_width - buf_margin_left; blurzoombuf = new unsigned char[buf_area * 2]; blurzoomx = new int[buf_width]; blurzoomy = new int[buf_height]; set_table(); make_palette(); bzero(blurzoombuf, buf_area * 2); background = new uint16_t[project_frame_w * project_frame_h]; diff = new unsigned char[project_frame_w * project_frame_h]; image_set_threshold_y(MAGIC_THRESHOLD); blurzoom_server = new BlurZoomServer(this, 1, 1); return 0; }
static int kplib_table_new(ktap_state *ks) { ktap_tab *h; int narr = 0, nrec = 0; if (kp_arg_nr(ks) >= 1) { kp_arg_check(ks, 1, KTAP_TYPE_NUMBER); narr = nvalue(kp_arg(ks, 1)); } if (kp_arg_nr(ks) >= 2) { kp_arg_check(ks, 2, KTAP_TYPE_NUMBER); nrec = nvalue(kp_arg(ks, 2)); } h = kp_tab_new(ks, narr, nrec); if (!h) { set_nil(ks->top); } else { set_table(ks->top, h); } incr_top(ks); return 1; }
static int kplib_sort_pairs(ktap_state *ks) { ktap_value *v = kp_arg(ks, 1); ktap_closure *cmp_func = NULL; ktap_tab *t; if (is_table(v)) { t = hvalue(v); } else if (is_ptable(v)) { t = kp_ptab_synthesis(ks, phvalue(v)); } else if (is_nil(v)) { kp_error(ks, "table is nil in pairs\n"); return 0; } else { kp_error(ks, "wrong argument for pairs\n"); return 0; } if (kp_arg_nr(ks) > 1) { kp_arg_check(ks, 2, KTAP_TYPE_FUNCTION); cmp_func = clvalue(kp_arg(ks, 2)); } kp_tab_sort(ks, t, cmp_func); set_cfunction(ks->top++, table_sort_iter_next); set_table(ks->top++, t); set_nil(ks->top++); return 3; }
static int kplib_pairs(ktap_state_t *ks) { kp_arg_check(ks, 1, KTAP_TTAB); set_cfunc(ks->top++, (ktap_cfunction)kp_tab_next); set_table(ks->top++, hvalue(kp_arg(ks, 1))); set_nil(ks->top++); return 3; }
int main(int argc, char **argv) { int i; int deadlock; deadlock = 0; srand(time(NULL)); set_table(); do { /* * Let the philosophers do some thinking and eating */ sleep(5); /* * Check for deadlock (i.e. none of the philosophers are * making progress) */ deadlock = 0; if (check_for_deadlock()) { deadlock = 1; break; } /* * Print out the philosophers progress */ print_progress(); } while (!deadlock); stop = 1; printf ("Reached deadlock\n"); /* * Release all locks so philosophers can exit */ for (i = 0; i < NUM_CHOPS; i++) pthread_mutex_unlock(&chopstick[i]); /* * Wait for philosophers to finish */ for (i = 0; i < NUM_PHILS; i++) pthread_join(diners[i].thread, NULL); return 0; }
static int kplib_pairs(ktap_state *ks) { ktap_value *v = kp_arg(ks, 1); ktap_tab *t; if (is_table(v)) { t = hvalue(v); } else if (is_ptable(v)) { t = kp_ptab_synthesis(ks, phvalue(v)); } else if (is_nil(v)) { kp_error(ks, "table is nil in pairs\n"); return 0; } else { kp_error(ks, "wrong argument for pairs\n"); return 0; } set_cfunction(ks->top++, table_iter_next); set_table(ks->top++, t); set_nil(ks->top++); return 3; }
int main(int argc, char **argv) { int i; int deadlock; int iter; iter = 0; /* * Randomly seed the random number generator used to control how * long philosophers eat and think. */ srand(time(NULL)); /* * Set the table means create the chopsticks and the philosophers. * Print out a header for the periodic updates on Philosopher state. */ set_table(); printf("\n"); printf("Dining Philosophers Update every %d seconds\n", ACCOUNTING_PERIOD); printf("-------------------------------------------\n"); do { /* * Reset the philosophers eating progress to 0. If the * philosopher is making progress, the philosopher will * increment it. */ for (i = 0; i < NUM_PHILS; i++) Diners[i].prog = 0; /* * Let the philosophers do some thinking and eating over a period * of ACCOUNTING_PERIOD seconds, which is a *long* time compared * to the time-scale of a philosopher thread, so *some* progress * should be made by each in this waiting time, unless deadlock * has occurred. */ sleep(ACCOUNTING_PERIOD); /* * Check for deadlock (i.e. none of the philosophers have * made progress in 5 seconds) */ deadlock = 1; for (i = 0; i < NUM_PHILS; i++) if (Diners[i].prog) deadlock = 0; /* * Print out the philosophers progress */ print_progress(); iter++; } while (!deadlock && iter < ITERATION_LIMIT); /* * Set the "Stop flag to tell all diners to stop */ Stop = 1; if (deadlock) { printf ("Deadlock Detected\n"); } else { printf ("Finished without Deadlock\n"); } /* * Release all locks so philosophers can exit even if they are * deadlocked. */ for (i = 0; i < NUM_CHOPS; i++) pthread_mutex_unlock(&chopstick[i]); /* * Wait for philosophers to finish */ for (i = 0; i < NUM_PHILS; i++) pthread_join(Diners[i].thread, NULL); return 0; }
Lua_table::Lua_table(lua_State* const lua,std::string const& name) :m_lua(lua),m_table_ref(lua) { set_table(name); }
void lutok::state::set_field(const std::string& name, const bool value, const int index){ push_literal(name); push_boolean(value); set_table(index); }
void lutok::state::set_field(const std::string& name, const lua_Number value, const int index){ push_literal(name); push_number(value); set_table(index); }
void loadtable() { set_table(table_DNA1,table_DNA2,DNA1_size,DNA2_size); }
Table::Table(lua_State* const vm, std::string const& name) :m_table_ref(vm) { set_table(name); }