void xa_shaders_destroy(struct xa_shaders *sc) { cache_destroy(sc->r->cso, sc->vs_hash, PIPE_SHADER_VERTEX); cache_destroy(sc->r->cso, sc->fs_hash, PIPE_SHADER_FRAGMENT); FREE(sc); }
/* Shuts down the file system module, writing any unwritten data to disk. */ void filesys_done (void) { free_map_close (); cache_destroy (fs_cache); fs_cache = NULL; }
/* cache_sim_fini */ int cache_sim_fini(cache_handle_t *cache) { /* is reuse distance calculation enabled? */ if (NULL != cache->reuse_data) { cache_sim_reuse_disable(cache); } /* is symbols tracking enabled? */ if (NULL != cache->symbol_data) { cache_sim_symbol_disable(cache); } printf("--------------------------------\n"); printf("Total accesses: %16"PRIu64"\n", cache->access); printf("Cache hits: %16"PRIu64"\n", cache->hit); printf(" -> rate %15.2f%%\n", (((double)cache->hit / (double)cache->access) * 100)); printf(" -> prefetched %16"PRIu64"\n", cache->prefetcher_hit); printf("Cache misses: %16"PRIu64"\n", cache->miss); printf(" -> rate %15.2f%%\n", (((double)cache->miss / (double)cache->access) * 100)); printf("Set conflicts: %16"PRIu64"\n", cache->conflict); printf(" -> rate %15.2f%%\n", (((double)cache->conflict / (double)cache->miss) * 100)); printf("Prefetcher: \n"); printf(" -> next line %16"PRIu64"\n", cache->prefetcher_next_line); printf(" -> pollution %16"PRIu64"\n", cache->prefetcher_evict); printf(" Cache finalized successfully \n"); printf("--------------------------------\n"); /* destroy the cache and free memory */ cache_destroy(cache); return CACHE_SIM_SUCCESS; }
void run_test(int num_threads, int num_iters, int cache_size, int lock_type) { int rc; long t; struct timespec start, end; pthread_t* threads = malloc(sizeof(pthread_t) * num_threads); shared.num_iters = num_iters; shared.cache = malloc(sizeof(Cache)); cache_init(shared.cache, cache_size, lock_type); pthread_barrier_init(&shared.barrier, NULL, num_threads); tracepoint(tl, start_test, num_threads, num_iters, (!lock_type ? "mutex" : "rwlock")); clock_gettime(CLOCK_MONOTONIC, &start); for(t = 0; t < num_threads; t++) { rc = pthread_create(&threads[t], NULL, run_thread, (void *)t); if (rc != 0) { fprintf(stderr, "Error at pthread_create() with id %d\n", rc); exit(-1); } } for(t = 0; t < num_threads; t++) { pthread_join(threads[t], NULL); } clock_gettime(CLOCK_MONOTONIC, &end); tracepoint(tl, end_test, ELAPSED_TIME(start, end)); cache_destroy(shared.cache); free(shared.cache); pthread_barrier_destroy(&shared.barrier); free(threads); }
int main_(int argc, char *argv[]) { int cache_params[CACHE_COUNT * 3]; parse_args(argc, argv, cache_params); struct cache caches[CACHE_COUNT]; int j = 0; for (int i = 0; i < CACHE_COUNT; ++i) { int level = i + 1; int c = cache_params[j++]; int b = cache_params[j++]; int s = cache_params[j++]; cache_init(&caches[i], &caches[i+1], level, c, b, s); } caches[CACHE_COUNT - 1].next = NULL; void *addr; char rw; while (!feof(stdin)) { fscanf(stdin, "%c %p\n", &rw, &addr); cache_access(caches, rw2access_type(rw), addr); } print_results(caches); for (int i = 0; i < CACHE_COUNT; ++i) { cache_destroy(&caches[i]); } return 0; }
static void cuda_free_ctx(cuda_context *ctx) { gpuarray_blas_ops *blas_ops; gpudata *next, *curr; ASSERT_CTX(ctx); ctx->refcnt--; if (ctx->refcnt == 0) { assert(ctx->enter == 0 && "Context was active when freed!"); if (ctx->blas_handle != NULL) { ctx->err = cuda_property(ctx, NULL, NULL, GA_CTX_PROP_BLAS_OPS, &blas_ops); blas_ops->teardown(ctx); } cuMemFreeHost((void *)ctx->errbuf->ptr); deallocate(ctx->errbuf); cuStreamDestroy(ctx->s); /* Clear out the freelist */ for (curr = ctx->freeblocks; curr != NULL; curr = next) { next = curr->next; cuMemFree(curr->ptr); deallocate(curr); } if (!(ctx->flags & DONTFREE)) cuCtxDestroy(ctx->ctx); cache_destroy(ctx->extcopy_cache); CLEAR(ctx); free(ctx); } }
/* cache_sim_init */ cache_handle_t* cache_sim_init(const unsigned int total_size, const unsigned int line_size, const unsigned int associativity, const char *policy) { /* safety checks */ if ((0 >= total_size) || (0 >= line_size) || (0 >= associativity)) { return NULL; } /* variables declaration and initialization */ cache_handle_t *cache = NULL; printf("--------------------------------\n"); /* create the cache */ if (NULL == (cache = cache_create(total_size, line_size, associativity))) { return NULL; } /* set the cache replacement policy (or algorithm) */ if (CACHE_SIM_SUCCESS != (set_policy(cache, policy))) { cache_destroy(cache); return NULL; } printf(" Cache initialized successfully \n"); printf("--------------------------------\n"); return cache; }
void case_teardown() { if (0 > cache_destroy(fixture.cache_ctrl)) { g_message("destroy cache error"); return; } }
void opengl_texture_cache_cleanup(void) { if (inited) { cache_destroy(&txarray_cache); inited = FALSE; } }
static enum test_return cache_create_test(void) { cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), NULL, NULL); assert(cache != NULL); cache_destroy(cache); return TEST_PASS; }
void *cuda_make_ctx(CUcontext ctx, int flags) { cuda_context *res; void *p; res = malloc(sizeof(*res)); if (res == NULL) return NULL; res->ctx = ctx; res->err = CUDA_SUCCESS; res->blas_handle = NULL; res->refcnt = 1; res->flags = flags; res->enter = 0; res->freeblocks = NULL; if (detect_arch(ARCH_PREFIX, res->bin_id, &err)) { goto fail_cache; } res->extcopy_cache = cache_lru(64, 32, (cache_eq_fn)extcopy_eq, (cache_hash_fn)extcopy_hash, (cache_freek_fn)extcopy_free, (cache_freev_fn)cuda_freekernel); if (res->extcopy_cache == NULL) { goto fail_cache; } err = cuStreamCreate(&res->s, 0); if (err != CUDA_SUCCESS) { goto fail_stream; } err = cuStreamCreate(&res->mem_s, CU_STREAM_NON_BLOCKING); if (err != CUDA_SUCCESS) { goto fail_mem_stream; } err = cuMemAllocHost(&p, 16); if (err != CUDA_SUCCESS) { goto fail_errbuf; } memset(p, 0, 16); /* Need to tag for new_gpudata */ TAG_CTX(res); res->errbuf = new_gpudata(res, (CUdeviceptr)p, 16); if (res->errbuf == NULL) { err = res->err; goto fail_end; } res->errbuf->flags |= CUDA_MAPPED_PTR; return res; fail_end: cuMemFreeHost(p); fail_errbuf: cuStreamDestroy(res->mem_s); fail_mem_stream: cuStreamDestroy(res->s); fail_stream: cache_destroy(res->extcopy_cache); fail_cache: free(res); return NULL; }
void gpucontext_deref(gpucontext *ctx) { if (ctx->blas_handle != NULL) ctx->blas_ops->teardown(ctx); if (ctx->extcopy_cache != NULL) { cache_destroy(ctx->extcopy_cache); ctx->extcopy_cache = NULL; } ctx->ops->buffer_deinit(ctx); }
int topo_cleanup(){ pthread_cancel(topo_node_thread); pthread_join(topo_node_thread,NULL); //close(topo_inotify_fd); free(topo_file); cache_destroy(node_cache); return 0; }
/* destroy all caches */ int cache_destroy_all() { int i; for(i=0; i<CACHE_MAX; i++) { if (caches[i].name != NULL) cache_destroy(caches[i].name); } return(1); }
/* * Closes a database, automatically committing any unsaved changes. * Also frees any associated memory. */ void gio_close(GapIO *io) { if (io->base) { cache_destroy(io); free(io); return; } #ifdef DO_LOGGING { char buf[256]; snprintf(buf, sizeof(buf), "closing database %s ...", io->name ? io->name : ""); log_file(NULL, buf); } #endif cache_decr(io, io->db); cache_decr(io, io->contig_order); if (io->scaffold) cache_decr(io, io->scaffold); cache_decr(io, io->library); cache_flush(io); cache_destroy(io); contig_register_destroy(io); io->iface->commit(io->dbh); io->iface->disconnect(io->dbh); actf_unlock(io->read_only, io->name); #ifdef DO_LOGGING log_file(NULL, "...closed."); #endif if (io->name) free(io->name); free(io); }
static void stormfs_destroy(void *data) { cache_destroy(); proxy_destroy(); free(stormfs.bucket); free(stormfs.mountpoint); free(stormfs.access_key); free(stormfs.secret_key); free(stormfs.virtual_url); g_hash_table_destroy(stormfs.mime_types); }
int cache_create(size_t concurrency, size_t capacity, uint64_t duration, void (*destroy_cb)(h2o_iovec_t value), cache_t *cache) { memset(cache, 0, sizeof(*cache)); assert(is_power_of_2(CONCURRENCY_FACTOR)); // Rounding up to a power of 2 simplifies the calculations a little bit, and, as any increase in // the number of caches, potentially reduces thread contention. cache->cache_num = CONCURRENCY_FACTOR * round_up_to_power_of_2(concurrency); cache->cache_num = MAX(cache->cache_num, 1); capacity = (capacity + cache->cache_num - 1) / cache->cache_num; pthread_mutexattr_t attr; if (pthread_mutexattr_init(&attr)) return EXIT_FAILURE; if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ADAPTIVE_NP)) goto error; cache->cache = malloc(cache->cache_num * sizeof(*cache->cache)); if (!cache->cache) goto error; cache->cache_lock = malloc(cache->cache_num * sizeof(*cache->cache_lock)); if (!cache->cache_lock) goto error_malloc; for (size_t i = 0; i < cache->cache_num; i++) { cache->cache[i] = h2o_cache_create(0, capacity, duration, destroy_cb); if (!cache->cache[i] || pthread_mutex_init(cache->cache_lock + i, &attr)) { if (cache->cache[i]) h2o_cache_destroy(cache->cache[i]); cache->cache_num = i; cache_destroy(cache); goto error; } } pthread_mutexattr_destroy(&attr); return EXIT_SUCCESS; error_malloc: free(cache->cache); error: pthread_mutexattr_destroy(&attr); return EXIT_FAILURE; }
/** * Deinit NuAuth: * - Stop NuAuth: close_nufw_servers(), close_clients(), end_tls(), end_audit() ; * - Free memory ; * - Unload modules: unload_modules() ; * - Destroy pid file ; * - And finally exit. * */ void nuauth_deinit(gboolean soft) { log_message(CRITICAL, DEBUG_AREA_MAIN, "[+] NuAuth deinit"); #if 0 signal(SIGTERM, SIG_DFL); signal(SIGKILL, SIG_DFL); signal(SIGHUP, SIG_DFL); #endif stop_threads(soft); log_message(INFO, DEBUG_AREA_MAIN, "Unloading modules"); unload_modules(); #if 0 end_tls(); #endif log_message(INFO, DEBUG_AREA_MAIN, "Ending audit"); end_audit(); log_message(INFO, DEBUG_AREA_MAIN, "Freeing memory"); free_nuauth_params(nuauthconf); if (nuauthconf->acl_cache) { cache_destroy(nuauthdatas->acl_cache); } if (nuauthconf->user_cache) { cache_destroy(nuauthdatas->user_cache); } g_free(nuauthdatas->program_fullpath); free_threads(); clear_push_queue(); g_hash_table_destroy(conn_list); g_static_mutex_free(&insert_mutex); /* destroy pid file */ unlink(NUAUTH_PID_FILE); }
// allocate gadget cache by copy struct cache_t *cache_new_copy (struct cache_t *cache) { struct cache_t *copy, *res; // allocate copy copy = cache_new(cache_get_capacity(cache)); // make copy res = cache_copy(copy, cache); if (res == NULL) cache_destroy(©, NULL); return copy; }
static enum test_return cache_constructor_test(void) { uint64_t *ptr; uint64_t pattern; cache_t *cache = cache_create("test", sizeof(uint64_t), sizeof(uint64_t), cache_constructor, NULL); assert(cache != NULL); ptr = cache_alloc(cache); pattern = *ptr; cache_free(cache, ptr); cache_destroy(cache); return (pattern == constructor_pattern) ? TEST_PASS : TEST_FAIL; }
static enum test_return cache_destructor_test(void) { cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), NULL, cache_destructor); char *ptr; assert(cache != NULL); ptr = cache_alloc(cache); cache_free(cache, ptr); cache_destroy(cache); return (ptr == destruct_data) ? TEST_PASS : TEST_FAIL; }
int main(int argc, char **argv) { struct tm tm; // pid = getpid(); init_abt_log(NULL, LOG_NOTICE); if (sqlite3_config(SQLITE_CONFIG_MULTITHREAD) != SQLITE_OK) { //多线程模式防止并发锁 log_error(LOG_ERROR, "mutile thread error"); } if (init_ds3231() < 0) { log_error(LOG_EMERG, "init_ds3231"); return -1; } getTime(&tm); if (cache_init() < 0) { log_error(LOG_EMERG, "cache_init"); return -1; } if (init_at24c02b() < 0) { log_error(LOG_NOTICE, "init_at24c02b"); } g_dev_version = zigdev_version(); if (zigdev_init() < 0) { log_error(LOG_NOTICE, "zigdev_init"); return -1; } signal_propose(); zigdev_test(); //zigadd_dev(0x256833, 1, 1, 0, 1); tcp_server(NULL); cache_destroy(); close_abt_log(); return 0; }
/* * Closes a database, automatically committing any unsaved changes. * Also frees any associated memory. */ void gio_close(GapIO *io) { if (io->base) { cache_destroy(io); free(io); return; } cache_decr(io, io->db); cache_decr(io, io->contig_order); cache_decr(io, io->library); cache_flush(io); cache_destroy(io); contig_register_destroy(io); io->iface->commit(io->dbh); io->iface->disconnect(io->dbh); if (io->name) free(io->name); free(io); }
void testCreateCached() { char *name = "imichael"; cache_t *cache = cache_create(name ,sizeof(uint32_t),sizeof(char*),NULL,NULL); assert(cache != NULL); printf("uunit32_t :%i\n",sizeof(uint32_t)); printf("char* size :%i\n",sizeof(char*)); printf("name :%s\n",cache->name ); printf("bufsize:%i\n",cache->bufsize); printf("freetotal:%i\n",cache->freetotal); printf("freecurr:%i\n",cache->freecurr); cache_destroy(cache); return ; }
static enum test_return cache_reuse_test(void) { int ii; cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), NULL, NULL); char *ptr = cache_alloc(cache); cache_free(cache, ptr); for (ii = 0; ii < 100; ++ii) { char *p = cache_alloc(cache); assert(p == ptr); cache_free(cache, ptr); } cache_destroy(cache); return TEST_PASS; }
static enum test_return cache_fail_constructor_test(void) { enum test_return ret = TEST_PASS; cache_t *cache = cache_create("test", sizeof(uint64_t), sizeof(uint64_t), cache_fail_constructor, NULL); uint64_t *ptr; assert(cache != NULL); ptr = cache_alloc(cache); if (ptr != NULL) { ret = TEST_FAIL; } cache_destroy(cache); return ret; }
static int callback_release(const char *path, struct fuse_file_info *finfo) { (void) path; (void) finfo; mylog("::release(%s, -)\n", path); /* close the cache entry if any. just don't check if it is a file or if it is opened. */ cache_destroy(path); stat_used--; if (stat_used < 0) stat_used = 0; /* call update-meta to check for new stuff */ update_meta_if_needed(); return(0); }
static int _dict_destroy(void *data) { struct _dict_stream *str = data; if (str->zstr_ready) { if (inflateEnd(&str->zstream)) dico_log(L_ERR, 0, _("%s:%d: INTERNAL ERROR: " "cannot shut down inflation engine: %s"), __FILE__, __LINE__, str->zstream.msg); /* Continue anyway */ } cache_destroy(str); free(str->buffer); dico_stream_destroy(&str->transport); free(str); return 0; }
int main(int argc, char **argv) { cache_t *ret = cache_create("charliezhao", 1024, 0, NULL, NULL); std::cout<<"ret->name = "<<ret->name; std::cout<<std::endl; std::cout<<std::flush; void *ptr = cache_alloc(ret); memcpy(ptr, (const void *)"hello, from charlie", 100); std::cout<<"ptr = "<<(char *)ptr; std::cout<<std::endl; std::cout<<std::flush; cache_free(ret, ptr); std::cout<<"cache_free ok"<<std::endl; std::cout<<std::flush; cache_destroy(ret); std::cout<<"cache_destroy ok"<<std::endl; std::cout<<std::flush; return 0; }
static enum test_return cache_redzone_test(void) { #ifndef HAVE_UMEM_H cache_t *cache = cache_create("test", sizeof(uint32_t), sizeof(char*), NULL, NULL); char *p; char old; /* Ignore SIGABORT */ struct sigaction old_action; struct sigaction action; memset(&action, 0, sizeof(action)); action.sa_handler = SIG_IGN; sigemptyset(&action.sa_mask); sigaction(SIGABRT, &action, &old_action); /* check memory debug.. */ p = cache_alloc(cache); old = *(p - 1); *(p - 1) = 0; cache_free(cache, p); assert(cache_error == -1); *(p - 1) = old; p[sizeof(uint32_t)] = 0; cache_free(cache, p); assert(cache_error == 1); /* restore signal handler */ sigaction(SIGABRT, &old_action, NULL); cache_destroy(cache); return TEST_PASS; #else return TEST_SKIP; #endif }