int gs_lib_ctx_init( gs_memory_t *mem ) { gs_lib_ctx_t *pio = 0; /* Check the non gc allocator is being passed in */ if (mem == 0 || mem != mem->non_gc_memory) return gs_error_Fatal; #ifndef GS_THREADSAFE mem_err_print = mem; #endif if (mem->gs_lib_ctx) /* one time initialization */ return 0; pio = (gs_lib_ctx_t*)gs_alloc_bytes_immovable(mem, sizeof(gs_lib_ctx_t), "gs_lib_ctx_init"); if( pio == 0 ) return -1; /* Wholesale blanking is cheaper than retail, and scales better when new * fields are added. */ memset(pio, 0, sizeof(*pio)); /* Now set the non zero/false/NULL things */ pio->memory = mem; gs_lib_ctx_get_real_stdio(&pio->fstdin, &pio->fstdout, &pio->fstderr ); pio->stdin_is_interactive = true; /* id's 1 through 4 are reserved for Device color spaces; see gscspace.h */ pio->gs_next_id = 5; /* this implies that each thread has its own complete state */ /* Need to set this before calling gs_lib_ctx_set_icc_directory. */ mem->gs_lib_ctx = pio; /* Initialize our default ICCProfilesDir */ pio->profiledir = NULL; pio->profiledir_len = 0; gs_lib_ctx_set_icc_directory(mem, DEFAULT_DIR_ICC, strlen(DEFAULT_DIR_ICC)); if (gs_lib_ctx_set_default_device_list(mem, gs_dev_defaults, strlen(gs_dev_defaults)) < 0) { gs_free_object(mem, pio, "gs_lib_ctx_init"); mem->gs_lib_ctx = NULL; } /* Initialise the underlying CMS. */ if (gscms_create(mem)) { gs_free_object(mem, mem->gs_lib_ctx->default_device_list, "gs_lib_ctx_fin"); gs_free_object(mem, pio, "gs_lib_ctx_init"); mem->gs_lib_ctx = NULL; return -1; } gp_get_realtime(pio->real_time_0); return 0; }
/* - realtime <int> */ static int zrealtime(i_ctx_t *i_ctx_p) { os_ptr op = osp; long secs_ns[2]; gs_lib_ctx_t *libctx = gs_lib_ctx_get_interp_instance(imemory); gp_get_realtime(secs_ns); secs_ns[1] -= libctx->real_time_0[1]; secs_ns[0] -= libctx->real_time_0[0]; push(1); make_int(op, secs_ns[0] * 1000 + secs_ns[1] / 1000000); return 0; }
/* and fraction (in nanoseconds). */ void gp_get_usertime(long *pdt) { #if use_times_for_usertime struct tms tms; long ticks; const long ticks_per_sec = CLK_TCK; times(&tms); ticks = tms.tms_utime + tms.tms_stime + tms.tms_cutime + tms.tms_cstime; pdt[0] = ticks / ticks_per_sec; pdt[1] = (ticks % ticks_per_sec) * (1000000000 / ticks_per_sec); #else gp_get_realtime(pdt); /* Use an approximation on other hosts. */ #endif }
int gs_lib_ctx_init( gs_memory_t *mem ) { gs_lib_ctx_t *pio = 0; if ( mem == 0 ) return -1; /* assert mem != 0 */ mem_err_print = mem; if (mem->gs_lib_ctx) /* one time initialization */ return 0; pio = mem->gs_lib_ctx = (gs_lib_ctx_t*)gs_alloc_bytes_immovable(mem, sizeof(gs_lib_ctx_t), "gs_lib_ctx_init"); if( pio == 0 ) return -1; /* Wholesale blanking is cheaper than retail, and scales better when new * fields are added. */ memset(pio, 0, sizeof(*pio)); /* Now set the non zero/false/NULL things */ pio->memory = mem; gs_lib_ctx_get_real_stdio(&pio->fstdin, &pio->fstdout, &pio->fstderr ); pio->stdin_is_interactive = true; /* id's 1 through 4 are reserved for Device color spaces; see gscspace.h */ pio->gs_next_id = 5; /* this implies that each thread has its own complete state */ /* Initialize our default ICCProfilesDir */ pio->profiledir = NULL; pio->profiledir_len = 0; gs_lib_ctx_set_icc_directory(mem, DEFAULT_DIR_ICC, strlen(DEFAULT_DIR_ICC)); gp_get_realtime(pio->real_time_0); return 0; }
/* and fraction (in nanoseconds). */ void gp_get_usertime(long *pdt) { gp_get_realtime(pdt); /* Use an approximation for now. */ }
/* and fraction (in nanoseconds). */ void gp_get_usertime(long *pdt) { return gp_get_realtime(pdt); /* not yet implemented */ }
void gp_get_clock (long *pdt) { gp_get_realtime(pdt); /* Use an approximation on other hosts. */ }
/* and fraction (in nanoseconds). */ void gp_get_usertime(long *pdt) { gp_get_realtime(pdt); /* Use an approximation on other hosts. */ pdt[0] -= (char)rand(); // was needed, if used for random generator seed (g3 is too fast) }