void main_loop(void) { const char *s[] = { "001.jpg", "002.jpg", 0, "003.jpg", "004.jpg", "005.jpg", "006.jpg", "007.jpg", "008.jpg", "009.jpg", "010.jpg", "011.jpg", "012.jpg", 0 }; char **p = (char**)s; unsigned short fseq = 1; while (*p) { unsigned short seq; unsigned short client_fseq; load_buff_pool(p_bp, *p); p_bp->f.fseq = fseq; /* send filename, send chunks, send EOF */ do { push_fileinfo(p_bp); } while (CPAPP_IOF != wait_ack(10, &client_fseq)); for (unsigned int i = 0; i <= p_bp->f.filesize / CPAPP_MAX_CHUNKSIZE; i++) { push_chunk(p_bp, i); } push_eof(p_bp); while (((seq = wait_ack(10, &client_fseq)) != CPAPP_EOF) || (client_fseq != fseq)) { // printf("ACK LOOP: ack, cliseq, seq = %04x, %04x, %04x\n", seq, client_fseq, fseq); switch (seq) { case CPAPP_TMO: push_eof(p_bp); break; case CPAPP_IGN: break; case CPAPP_EOF: break; case CPAPP_IOF: break; default: push_chunk(p_bp, seq); break; } } printf("Step to next file. (%d finished)\n", client_fseq); p++; fseq++; } }
uint64_t memory::pmm::frame_stack::pop() { if (!_size) { if (_global) { if (_global->size() <= frame_stack_chunk::max) { processor::smp::parallel_execute(processor::smp::policies::others, [](uint64_t){ for (uint64_t i = 0; i < 16 && processor::get_current_core()->frame_stack().size() > frame_stack_chunk::max * 128; ++i) { screen::debug("\nRebalancing: pushing frame stack chunk to global from #", processor::id()); _global_stack.push_chunk(processor::get_current_core()->frame_stack().pop_chunk()); } }); } for (uint64_t i = 0; i < 8 && _global->size() > frame_stack_chunk::max; ++i) { screen::debug("\nRebalancing: pushing frame stack chunk from global to #", processor::id()); push_chunk(_global->pop_chunk()); } } else { if (_first) { PANIC("TODO: deallocate available chunk"); } else { PANIC("TODO: ultimate OOM case"); } } } LOCK(_last->lock); uint64_t ret = _last->stack[--_last->size]; --_size; if (_last != _first && _last->size == frame_stack_chunk::max - 50) { LOCK(_last->lock); LOCK(_last->next->lock); if (_last->next->next) { // free _last->next->next } } screen::debug("\nPopped ", (void *)ret, " from ", (_global ? "local" : "global"), " frame stack on #", processor::id()); return ret; }
void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@CONDITION")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); wpl_text *text_else = NULL; wpl_text_chunks::condition *condition = new wpl_text_chunks::condition(text, exp); chunks.emplace_back(condition); parse_expression(parent_namespace, exp); ignore_string_match(NEWLINE, NON_NEWLINE_WS); parse_text(parent_namespace, text); start = get_string_pointer(); } else if (ignore_string("@TEMPLATE")) { push_chunk (start, end); wpl_matcher_position pos = get_position(); char name[WPL_VARNAME_SIZE]; ignore_whitespace(); get_word(name); wpl_template *my_template = parent_namespace->find_template(name); if (!my_template) { load_position(pos); THROW_ELEMENT_EXCEPTION("Unknown template name"); } chunks.emplace_back(new wpl_text_chunks::html_template(my_template)); ignore_whitespace(); if (!ignore_letter ('}')) { THROW_ELEMENT_EXCEPTION("Expected } after TEMPLATE call definition"); } start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }
mulk_type_return_t create_chunks(metalink_file_list_t *file) { int chunk_number = CHUNK_NUMBER, i; off_t last_chunk_size = 0, chunk_size = 0, chunk_remainder, filesize; #ifdef ENABLE_CHECKSUM checksum_type_t cs = CS_NONE; #endif if (!file || file->size < 0 || !file->file) return MULK_RET_FILE_ERR; filesize = file->size; #ifdef ENABLE_CHECKSUM /* chunk size derived from checksum piece size */ if (file->file->chunk_checksum) { chunk_number = get_number_of_piece_hashes(file->file->chunk_checksum->piece_hashes); chunk_size = file->file->chunk_checksum->length; last_chunk_size = filesize - chunk_size * (chunk_number - 1); if (chunk_number && chunk_size > 0 && last_chunk_size > 0 && last_chunk_size < 2 * chunk_size) { cs = string2checksum_type(file->file->chunk_checksum->type); if (cs > CS_NONE) MULK_NOTE((_("Found chunk checksum of %s type.\n"), checksum_type2string(cs))); else MULK_NOTE((_("No compatible checksum to verify.\n"))); } else { MULK_ERROR((_("ERROR: wrong length in chunk checksum.\n"))); return MULK_RET_ERR; } } else cs = CS_NONE; if (cs == CS_NONE) #endif /* ENABLE_CHECKSUM */ { chunk_size = filesize / chunk_number; if (chunk_size < MIN_CHUNK_SIZE) { chunk_number = filesize / MIN_CHUNK_SIZE; if (!chunk_number) chunk_number = 1; chunk_size = filesize / chunk_number; } else if (chunk_size > MAX_CHUNK_SIZE) { chunk_number = filesize / MAX_CHUNK_SIZE + 1; if (!chunk_number) chunk_number = 1; chunk_size = filesize / chunk_number; } chunk_remainder = filesize % chunk_number; last_chunk_size = chunk_size + chunk_remainder; } MULK_DEBUG((_("filesize: %" PRIdMAX "\n"), (intmax_t) filesize)); MULK_DEBUG((_("number of chunks: %d\n"), chunk_number)); MULK_DEBUG((_("chunk size: %" PRIdMAX "\n"), (intmax_t) chunk_size)); MULK_DEBUG((_("last chunk size: %" PRIdMAX "\n"), (intmax_t) last_chunk_size)); for (i = 0; i < chunk_number && filesize > 0; i++) { off_t size = i ? chunk_size : last_chunk_size; filesize -= size; #ifdef ENABLE_CHECKSUM push_chunk(file, filesize >= 0 ? filesize : 0, size, cs, cs > CS_NONE ? get_piece_hash(file->file->chunk_checksum->piece_hashes, chunk_number - i - 1) : NULL); #else push_chunk(file, filesize >= 0 ? filesize : 0, size); #endif } file->chunk_number = chunk_number; return MULK_RET_OK; }
void wpl_text::parse_value(wpl_namespace *parent_namespace) { ignore_string_match(NEWLINE, NON_NEWLINE_WS); const char *start = get_string_pointer(); const char *end; int par_level = 1; while (par_level > 0 && !at_end()) { end = get_string_pointer(); if (ignore_letter('{')) { if (ignore_string("@LOOP")) { push_chunk (start, end); wpl_text *text = new wpl_text(); wpl_expression *exp = new wpl_expression_par_enclosed(); chunks.emplace_back(new wpl_text_chunks::loop(text, exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(NEWLINE, NON_NEWLINE_WS); text->load_position(get_position()); text->parse_value(parent_namespace); load_position(text->get_position()); start = get_string_pointer(); } else if (ignore_string("@")) { push_chunk (start, end); wpl_expression *exp = new wpl_expression_loose_end(); chunks.emplace_back(new wpl_text_chunks::expression(exp)); exp->load_position(get_position()); exp->parse_value(parent_namespace); load_position(exp->get_position()); ignore_string_match(WHITESPACE, 0); if (!ignore_letter('}')) { THROW_ELEMENT_EXCEPTION("Expected '}' after expression-in-TEXT"); } start = get_string_pointer(); } else { par_level++; } } else if (ignore_letter('}')) { par_level--; } else { if (!ignore_string_match(NON_CURLY|UTF8, 0)) { cerr << "Unknown character '" << hex << get_letter(ALL) << "'\n"; THROW_ELEMENT_EXCEPTION("Syntax error in text-string"); } } } if (par_level != 0) { THROW_ELEMENT_EXCEPTION("Excepted '}' after TEXT-block"); } end = get_string_pointer() - 2; while (M_NON_NEWLINE_WHITESPACE (*end)) { end--; } end++; if (end > start) { push_chunk (start, end); } }
gchar * hdr_format_string (const gchar *data, gssize len) { g_autofree gchar *copy = NULL; g_autoptr(GString) out = NULL; g_autoptr(GArray) ar = NULL; g_auto(GStrv) chunks = NULL; guint long_ret = 0; guint long_ret_star = 0; guint long_ident = 0; guint long_ptype = 0; guint long_star = 0; ar = g_array_new (FALSE, FALSE, sizeof (Chunk)); g_array_set_clear_func (ar, (GDestroyNotify)clear_chunk); if (data == NULL || *data == 0) return g_strdup (""); if (len < 0) len = strlen (data); copy = g_strndup (data, len); chunks = g_strsplit (copy, ";", 0); for (guint i = 0; chunks[i]; i++) { g_strstrip (chunks[i]); if (!*chunks[i]) continue; if (!push_chunk (ar, chunks[i])) return NULL; } if (ar->len == 0) return NULL; out = g_string_new (NULL); #if 0 for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); } #endif for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); g_autofree gchar *rtype = NULL; guint n_star = 0; parse_rtype (chunk->return_type, &rtype, &n_star); long_ret = MAX (long_ret, strlen (rtype)); long_ret_star = MAX (long_ret_star, n_star); long_ident = MAX (long_ident, strlen (chunk->identifier)); for (const GSList *iter = chunk->params; iter; iter = iter->next) { Parameter *p = iter->data; long_star = MAX (long_star, p->n_star); if (p->type) long_ptype = MAX (long_ptype, strlen (p->type)); } } for (guint i = 0; i < ar->len; i++) { const Chunk *chunk = &g_array_index (ar, Chunk, i); guint n_star = 0; guint off; guint space; guint rlen; if (chunk->pre) g_string_append_printf (out, "%s\n", chunk->pre); off = out->len; if (chunk->return_type) { g_autofree gchar *rtype = NULL; parse_rtype (chunk->return_type, &rtype, &n_star); rlen = strlen (rtype); g_string_append (out, rtype); } else { g_string_append (out, "void"); rlen = 4; } for (guint j = rlen; j < long_ret; j++) g_string_append_c (out, ' '); g_string_append_c (out, ' '); for (guint j = 0; j < long_ret_star - n_star; j++) g_string_append_c (out, ' '); for (guint j = 0; j < n_star; j++) g_string_append_c (out, '*'); g_string_append (out, chunk->identifier); rlen = strlen (chunk->identifier); for (guint j = rlen; j < long_ident; j++) g_string_append_c (out, ' '); g_string_append (out, " ("); space = out->len - off; if (chunk->params == NULL) g_string_append (out, "void"); for (const GSList *iter = chunk->params; iter; iter = iter->next) { Parameter *p = iter->data; if (p->ellipsis) { g_string_append (out, "..."); break; } if (p->type == NULL) { g_warning ("Unexpected NULL value for type"); continue; } g_string_append (out, p->type); for (guint j = strlen (p->type); j < long_ptype; j++) g_string_append_c (out, ' '); g_string_append_c (out, ' '); for (guint j = p->n_star; j < long_star; j++) g_string_append_c (out, ' '); for (guint j = 0; j < p->n_star; j++) g_string_append_c (out, '*'); g_string_append (out, p->name); if (iter->next) { g_string_append (out, ",\n"); for (guint j = 0; j < space; j++) g_string_append_c (out, ' '); } } g_string_append_c (out, ')'); if (chunk->post) g_string_append_printf (out, " %s", chunk->post); g_string_append (out, ";\n"); } return g_string_free (g_steal_pointer (&out), FALSE); }