Json::Value SkJSONCanvas::makePaint(const SkPaint& paint) { Json::Value result(Json::objectValue); store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_STROKEWIDTH, paint.getStrokeWidth(), 0.0f); store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_STROKEMITER, paint.getStrokeMiter(), SkPaintDefaults_MiterLimit); store_bool(&result, SKJSONCANVAS_ATTRIBUTE_ANTIALIAS, paint.isAntiAlias(), false); store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSIZE, paint.getTextSize(), SkPaintDefaults_TextSize); store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextScaleX(), SK_Scalar1); store_scalar(&result, SKJSONCANVAS_ATTRIBUTE_TEXTSCALEX, paint.getTextSkewX(), 0.0f); apply_paint_color(paint, &result); apply_paint_style(paint, &result); apply_paint_cap(paint, &result); apply_paint_textalign(paint, &result); apply_paint_patheffect(paint, &result, fSendBinaries); apply_paint_maskfilter(paint, &result, fSendBinaries); apply_paint_shader(paint, &result, fSendBinaries); apply_paint_xfermode(paint, &result, fSendBinaries); apply_paint_imagefilter(paint, &result, fSendBinaries); apply_paint_colorfilter(paint, &result, fSendBinaries); apply_paint_typeface(paint, &result, fSendBinaries); return result; }
__CILKRTS_BEGIN_EXTERN_C /** * @brief Returns the global state object. If called for the first time, * initializes the user-settable values in the global state, but does not * initialize the rest of the structure. */ global_state_t* cilkg_get_user_settable_values() { // Environment variable value. More than big enough for a 64-bit signed // integer. char envstr[24]; // Abbreviating &global_state_singleton as g is not only shorter, it also // facilitates grepping for the string "g->", which appears ubiquitously // in the runtime code. global_state_t* g = &global_state_singleton; // TBD: We need synchronization around this loop to prevent // multiple threads from initializing this data. if (! cilkg_user_settable_values_initialized) { size_t len; // Preserve stealing disabled since it may have been set by the // debugger int stealing_disabled = g->stealing_disabled; // All fields will be zero until set. In particular std::memset(g, 0, sizeof(global_state_t)); // Fetch the number of cores. There must be at last 1, since we're // executing on *something*, aren't we!? int hardware_cpu_count = __cilkrts_hardware_cpu_count(); CILK_ASSERT(hardware_cpu_count > 0); bool under_ptool = __cilkrts_running_under_sequential_ptool(); if (under_ptool) hardware_cpu_count = 1; g->stealing_disabled = stealing_disabled; g->under_ptool = under_ptool; g->force_reduce = 0; // Default Off g->P = hardware_cpu_count; // Defaults to hardware CPU count g->max_user_workers = 0; // 0 unless set by user g->fiber_pool_size = 7; // Arbitrary default g->global_fiber_pool_size = 3 * 3* g->P; // Arbitrary default // 3*P was the default size of the worker array (including // space for extra user workers). This parameter was chosen // to match previous versions of the runtime. if (4 == sizeof(void *)) g->max_stacks = 1200; // Only 1GB on 32-bit machines else g->max_stacks = 2400; // 2GB on 64-bit machines // If we have 2400 1MB stacks, that is 2 gb. If we reach this // limit on a single-socket machine, we may have other // problems. Is 2400 too small for large multicore machines? // TBD(jsukha, 11/27/2012): I set this limit on stacks to be a // value independent of P. When running on a Xeon Phi with // small values of P, I recall seeing a few microbenchmarks // (e.g., fib) where a limit of 10*P seemed to be // unnecessarily slowing things down. // // That being said, the code has changed sufficiently that // this observation may no longer be true. // // Note: in general, the worst-case number of stacks required // for a Cilk computation with spawn depth "d" on P workers is // O(Pd). Code with unbalanced recursion may run into issues // with this stack usage. g->max_steal_failures = 128; // TBD: depend on max_workers? g->stack_size = 0; // 0 unless set by the user // Assume no record or replay log for now g->record_replay_file_name = NULL; g->record_or_replay = RECORD_REPLAY_NONE; // set by user if (always_force_reduce()) g->force_reduce = true; else if (cilkos_getenv(envstr, sizeof(envstr), "CILK_FORCE_REDUCE")) store_bool(&g->force_reduce, envstr); if (under_ptool) g->P = 1; // Ignore environment variable if under cilkscreen else if (cilkos_getenv(envstr, sizeof(envstr), "CILK_NWORKERS")) // Set P to environment variable, but limit to no less than 1 // and no more than 16 times the number of hardware threads. store_int(&g->P, envstr, 1, 16 * hardware_cpu_count); if (cilkos_getenv(envstr, sizeof(envstr), "CILK_MAX_USER_WORKERS")) // Set max_user_workers to environment variable, but limit to no // less than 1 and no more 16 times the number of hardware // threads. If not specified, defaults (somewhat arbitrarily) to // the larger of 3 and twice the number of hardware threads. store_int(&g->max_user_workers, envstr, 1, 16*hardware_cpu_count); if (cilkos_getenv(envstr, sizeof(envstr), "CILK_STEAL_FAILURES")) // Set the number of times a worker should fail to steal before // it looks to see whether it should suspend itself. store_int<unsigned>(&g->max_steal_failures, envstr, 1, INT_MAX); // Compute the total number of workers to allocate. Subtract one from // nworkers and user workers so that the first user worker isn't // factored in twice. // // total_workers must be computed now to support __cilkrts_get_total_workers g->total_workers = g->P + calc_max_user_workers(g) - 1; #ifdef CILK_RECORD_REPLAY // RecordReplay: See if we've been asked to replay a log len = cilkos_getenv(envstr, 0, "CILK_REPLAY_LOG"); if (len > 0) { len += 1; // Allow for trailing NUL g->record_or_replay = REPLAY_LOG; g->record_replay_file_name = (char *)__cilkrts_malloc(len); cilkos_getenv(g->record_replay_file_name, len, "CILK_REPLAY_LOG"); } // RecordReplay: See if we've been asked to record a log len = cilkos_getenv(envstr, 0, "CILK_RECORD_LOG"); if (len > 0) { if (RECORD_REPLAY_NONE != g->record_or_replay) cilkos_warning("CILK_RECORD_LOG ignored since CILK_REPLAY_LOG is defined.\n"); else { len += 1; // Allow for trailing NUL g->record_or_replay = RECORD_LOG; g->record_replay_file_name = (char *)__cilkrts_malloc(len); cilkos_getenv(g->record_replay_file_name, len, "CILK_RECORD_LOG"); } } #endif cilkg_user_settable_values_initialized = true; } return g; }
static int opt_set(void *opts, const struct opt_def *def, const char **val, struct region *region, uint32_t errcode, uint32_t field_no) { int64_t ival; uint64_t uval; char *errmsg = tt_static_buf(); double dval; uint32_t str_len; const char *str; char *ptr; char *opt = ((char *) opts) + def->offset; switch (def->type) { case OPT_BOOL: if (mp_typeof(**val) != MP_BOOL) goto type_mismatch_err; store_bool(opt, mp_decode_bool(val)); break; case OPT_UINT32: if (mp_typeof(**val) != MP_UINT) goto type_mismatch_err; uval = mp_decode_uint(val); if (uval > UINT32_MAX) goto type_mismatch_err; store_u32(opt, uval); break; case OPT_INT64: if (mp_read_int64(val, &ival) != 0) goto type_mismatch_err; store_u64(opt, ival); break; case OPT_FLOAT: if (mp_read_double(val, &dval) != 0) goto type_mismatch_err; store_double(opt, dval); break; case OPT_STR: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); str_len = MIN(str_len, def->len - 1); memcpy(opt, str, str_len); opt[str_len] = '\0'; break; case OPT_STRPTR: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); if (str_len > 0) { ptr = (char *) region_alloc(region, str_len + 1); if (ptr == NULL) { diag_set(OutOfMemory, str_len + 1, "region", "opt string"); return -1; } memcpy(ptr, str, str_len); ptr[str_len] = '\0'; assert (strlen(ptr) == str_len); } else { ptr = NULL; } *(const char **)opt = ptr; break; case OPT_ENUM: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); if (def->to_enum == NULL) { ival = strnindex(def->enum_strs, str, str_len, def->enum_max); } else { ival = def->to_enum(str, str_len); } switch(def->enum_size) { case sizeof(uint8_t): store_u8(opt, (uint8_t)ival); break; case sizeof(uint16_t): store_u16(opt, (uint16_t)ival); break; case sizeof(uint32_t): store_u32(opt, (uint32_t)ival); break; case sizeof(uint64_t): store_u64(opt, (uint64_t)ival); break; default: unreachable(); }; break; case OPT_ARRAY: if (mp_typeof(**val) != MP_ARRAY) goto type_mismatch_err; ival = mp_decode_array(val); assert(def->to_array != NULL); if (def->to_array(val, ival, opt, errcode, field_no) != 0) return -1; break; case OPT_LEGACY: mp_next(val); break; default: unreachable(); } return 0; type_mismatch_err: snprintf(errmsg, TT_STATIC_BUF_LEN, "'%s' must be %s", def->name, opt_type_strs[def->type]); diag_set(ClientError, errcode, field_no, errmsg); return -1; }
STORAGE_SET *persistentDataStore(PERSISTENT_DATA *data) { STORAGE_SET *set = new_storage_set(); store_bool(set, "persistent", data->persistent); store_int(set, "activity", data->activity); return set; }