void tcp3_read(io_handle_t *handle, io_buf_t *buf, int status) { if(status == -1) { storage_free(&storage, buf->base); io_tcp_close(&tcp3); tcp3.fd = -1; puts("tcp3 disconnected."); } else { if(tcp3.fd != -1) { char *str = (char*)buf->base; switch(*str) { case 'L': if(io_sendall(&backup, handle, backup_sent) == -1) perror("backup sending"); break; case 'C': if(ftruncate(backup.fd, 0) == -1) perror("backup deletion"); else puts("backup deleted."); break; } storage_free(&storage, buf->base); } else { puts("tcp3 not connected."); storage_free(&storage, buf->base); } } }
void queue_free(queue *q) { bytestring_free(q->name); storage_free(q->storage); xfree(q); }
void rfcm_read(io_handle_t *handle, io_buf_t *buf, int status) { if(status == -1) { storage_free(&storage, buf->base); io_rfcomm_close(&rfcm); rfcm.fd = -1; puts("bluetooth disconnected."); } else { if(tcp2.fd != -1) { ((char*)buf->base)[status++] = '\n'; TELL_IF_ERR(io_write(&tcp2, buf->base, status, rfcm_written)); } else { puts("tcp2 not connected."); storage_free(&storage, buf->base); } } }
ut_cleanup() { int i; stream_close(stream); stream_close(memory_stream); rain1_group_free(rxg, sto); storage_free(sto); for (i = 0; i < NUM_SPOF_GROUPS; i++) os_free(rdevs[i]); os_random_cleanup(); }
static void __common_cleanup(void) { int i; assembly_group_cleanup(ag); os_free(ag); storage_free(sto); /* FIXME Should use vrt_realdev_free() but can we use the real vrt_realdev.c here and now? */ for (i = 0; i < NUM_SPOF_GROUPS; i++) os_free(rdevs[i]); os_random_cleanup(); }
void i_fn_args_free(struct i_fn_args *a) { if (a != NULL) { if (a->temp_files != NULL) { temp_files_clean(a); aura_dict_free(a->temp_files); } if (a->cmd_names != NULL) { config_vars_free(a->cmd_names); } if (a->s != NULL) { storage_free(a->s); } if (a->c != NULL) { dfui_be_stop(a->c); } if (a->log != NULL) { fclose(a->log); } AURA_FREE(a, i_fn_args); } }
//----------------------------------------------------------------------------- // Main... process command line parameters, and if we have enough information, then create an empty stash. int main(int argc, char **argv) { int c; storage_t *storage = NULL; stash_t *stash = NULL; int result; const char *basedir = NULL; const char *newuser = NULL; const char *newpass = NULL; const char *host = NULL; const char *username = NULL; const char *password = NULL; user_t *user; stash_result_t res; assert(argc >= 0); assert(argv); // process arguments /// Need to check the options in here, there're possibly ones that we dont need. while ((c = getopt(argc, argv, "hvd:u:p:H:U:P:")) != -1) { switch (c) { case 'h': usage(); exit(EXIT_SUCCESS); case 'v': verbose++; break; case 'd': basedir = optarg; break; case 'u': newuser = optarg; break; case 'p': newpass = optarg; break; case 'H': host = optarg; break; case 'U': username = optarg; break; case 'P': password = optarg; break; default: fprintf(stderr, "Illegal argument \"%c\"\n", c); exit(1); } } // check that our required params are there: if (basedir == NULL && host == NULL) { fprintf(stderr, "missing required option, either -d or -H\n"); exit(1); } else if (basedir && host) { fprintf(stderr, "cannot specify both a directory and a host.\n"); exit(1); } else if (newpass == NULL) { fprintf(stderr, "missing required parameter: -p\n"); exit(1); } else if (newuser == NULL) { fprintf(stderr, "missing required parameter: -u\n"); exit(1); } result = 0; if (basedir) { // we are using a basedir direct method. For this we will need to use // the stash_storage functionality (that is part of the libstash // library). storage = storage_init(NULL); assert(storage); // process the main meta file; assert(basedir); storage_lock_master(storage, basedir); storage_process(storage, basedir, KEEP_OPEN, IGNORE_DATA); // if the namespace is available, then create it. assert(newuser); user = storage_getuser(storage, NULL_USER_ID, newuser); if (user == NULL) { fprintf(stderr, "Username '%s' does not exist.\n", newuser); result = 1; } else { assert(user->uid > 0); storage_set_password(storage, NULL_USER_ID, user->uid, newpass); if (verbose) { printf("Password for user '%s' changed.\n", newuser); assert(result == 0); } } storage_unlock_master(storage, basedir); // cleanup the storage storage_free(storage); storage = NULL; } else { // network version. stash = stash_init(NULL); assert(stash); // add our username and password to the authority... in future // versions, private and public keys may be used instead. assert(username); assert(password); stash_authority(stash, username, password); // add our known host to the server list. assert(host); stash_addserver(stash, host, 10); // connect to the database... check error code. // although it is not necessary to connect now, because if we dont, // the first operation we do will attempt to connect if we are not // already connected. However, it is useful right now to attempt to // connect so that we can report the error back to the user. Easier // to do it here and it doesn't cost anything. res = stash_connect(stash); if (res != 0) { fprintf(stderr, "Unable to connect: %04X:%s\n", res, stash_err_text(res)); } else { res = stash_set_password(stash, 0, newuser, newpass); if (res != STASH_ERR_OK) { switch(res) { case STASH_ERR_OK: if (verbose) { printf("Password set for user '%s'.\n", newuser); } break; case STASH_ERR_USERNOTEXIST: fprintf(stderr, "Username '%s' does not exist.\n", newuser); break; case STASH_ERR_INSUFFICIENTRIGHTS: fprintf(stderr, "Insufficient rights to change passwords.\n"); break; default: fprintf(stderr, "Unexpected error: %04X:%s\n", res, stash_err_text(res)); break; } result = 1; } } // cleanup the storage stash_free(stash); stash = NULL; } assert(stash == NULL); assert(storage == NULL); return(result); }
int main(int argc, char** argv) { if(argc != 2) { printf("You should use the following format for running this program: %s <Number of Iterations>\n", argv[0]); exit(1); } int N = atoi(argv[1]); int rng = 42; srand(rng); array_number_t vec1 = vector_fill(DIM, 0.0); array_number_t vec2 = vector_fill(DIM, 0.0); array_number_t vec3 = vector_fill(DIM, 0.0); for(int i=0; i<DIM; i++) { vec1->arr[i] = dist(rng); vec2->arr[i] = dist(rng); vec3->arr[i] = dist(rng); } #ifdef HOIST storage_t s = storage_alloc(VECTOR_ALL_BYTES(DIM)); #endif timer_t t = tic(); double total = 0; for (int count = 0; count < N; ++count) { vec1->arr[0] += 1.0 / (2.0 + vec1->arr[0]); vec2->arr[10] += 1.0 / (2.0 + vec2->arr[10]); #ifdef DPS #ifndef HOIST storage_t s = storage_alloc(VECTOR_ALL_BYTES(DIM)); #endif #endif #ifdef ADD3 #ifdef DPS total += vectorSum(TOP_LEVEL_linalg_vectorAdd3_dps(s, vec1, vec2, vec3, DIM, DIM, DIM)); #else total += vectorSum(TOP_LEVEL_linalg_vectorAdd3(vec1, vec2, vec3)); #endif #elif DOT #ifdef DPS total += TOP_LEVEL_linalg_dot_prod_dps(s, vec1, vec2, DIM, DIM); #else total += TOP_LEVEL_linalg_dot_prod(vec1, vec2); #endif #elif CROSS #ifdef DPS total += vectorSum(TOP_LEVEL_linalg_cross_dps(s, vec1, vec2, DIM, DIM)); #else total += vectorSum(TOP_LEVEL_linalg_cross(vec1, vec2)); #endif #endif #ifdef DPS #ifndef HOIST storage_free(s, VECTOR_ALL_BYTES(DIM)); #endif #endif } float elapsed = toc2(t); printf("total =%f, time per call = %f ms\n", total, elapsed / (double)(N)); return 0; }
static int storage_msghandler (int m, int c, struct msgbuf *buf, int bufcnt) { if (m != MSG_BUF) return -1; if (c == STORAGE_MSG_NEW) { struct storage_msg_new *arg; struct storage_extend *extend; char *arg_extend; int extend_count, tmp, i; if (bufcnt != 1 && bufcnt != 2) return -1; if (buf[0].len != sizeof *arg) return -1; arg = buf[0].base; if (arg->guidp) arg->guidp = &arg->guidd; if (bufcnt == 2) { arg_extend = buf[1].base; for (extend_count = 0, tmp = 0; tmp < buf[1].len; extend_count++) { tmp += strlen (&arg_extend[tmp]) + 1; tmp += strlen (&arg_extend[tmp]) + 1; } extend = alloc (sizeof *extend * (extend_count + 1)); for (i = 0, tmp = 0; tmp < buf[1].len; i++) { extend[i].name = &arg_extend[tmp]; tmp += strlen (&arg_extend[tmp]) + 1; extend[i].value = &arg_extend[tmp]; tmp += strlen (&arg_extend[tmp]) + 1; } extend[i].name = NULL; extend[i].value = NULL; } else { extend = NULL; } arg->retval = storage_new (arg->type, arg->host_id, arg->device_id, arg->guidp, extend); if (extend) free (extend); return 0; } else if (c == STORAGE_MSG_FREE) { struct storage_msg_free *arg; if (bufcnt != 1) return -1; if (buf[0].len != sizeof *arg) return -1; arg = buf[0].base; storage_free (arg->storage); return 0; } else if (c == STORAGE_MSG_HANDLE_SECTORS) { struct storage_msg_handle_sectors *arg; if (bufcnt != 3) return -1; if (buf[0].len != sizeof *arg) return -1; arg = buf[0].base; arg->retval = storage_handle_sectors (arg->storage, &arg->access, buf[1].base, buf[2].base); return 0; } else { return -1; } }
void createStorage() { storage_t* s = storage_new(); CU_ASSERT_PTR_NOT_NULL_FATAL(s); storage_free(s); }
//----------------------------------------------------------------------------- // Main... process command line parameters, and if we have enough information, then create an empty stash. int main(int argc, char **argv) { int c; master_t master; storage_t *storage; const char *filename = NULL; assert(argc >= 0); assert(argv); // initialise the master structure that we will be passing through the risp process. master.risp_top = NULL; master.risp_op = NULL; master.risp_payload = NULL; master.risp_data = NULL; // process arguments /// Need to check the options in here, there're possibly ones that we dont need. while ((c = getopt(argc, argv, "hvf:")) != -1) { switch (c) { case 'h': usage(); exit(EXIT_SUCCESS); case 'v': verbose++; break; case 'f': filename = optarg; break; default: fprintf(stderr, "Illegal argument \"%c\"\n", c); exit(1); } } // check that our required params are there: if (filename == NULL) { fprintf(stderr, "requires: -f <filename>\n"); exit(1); } // create the top-level risp interface. master.risp_top = risp_init(NULL); assert(master.risp_top != NULL); risp_add_command(master.risp_top, STASH_CMD_CLEAR, &cmdClear); risp_add_command(master.risp_top, STASH_CMD_FILE_SEQ, &cmdFileSeq); risp_add_command(master.risp_top, STASH_CMD_OPERATION, &cmdOperation); risp_add_command(master.risp_top, STASH_CMD_NEXT_VOLUME, &cmdNextVolume); master.risp_op = risp_init(NULL); assert(master.risp_op); master.risp_payload = risp_init(NULL); assert(master.risp_payload); risp_add_command(master.risp_payload, STASH_CMD_CREATE_USER, &cmdCreateUser); risp_add_command(master.risp_payload, STASH_CMD_CREATE_NAMESPACE, &cmdCreateNamespace); risp_add_command(master.risp_payload, STASH_CMD_SET_PASSWORD, &cmdSetPassword); risp_add_command(master.risp_payload, STASH_CMD_GRANT, &cmdGrant); risp_add_command(master.risp_payload, STASH_CMD_CREATE_TABLE, &cmdCreateTable); risp_add_command(master.risp_payload, STASH_CMD_CREATE_KEY, &cmdCreateKey); risp_add_command(master.risp_payload, STASH_CMD_CREATE_NAME, &cmdCreateName); risp_add_command(master.risp_payload, STASH_CMD_CREATE_ROW, &cmdCreateRow); risp_add_command(master.risp_payload, STASH_CMD_SET, &cmdSet); risp_add_command(master.risp_payload, STASH_CMD_DELETE, &cmdDelete); // risp_add_command(master.risp_payload, STASH_CMD_DROP_USER, &cmdDropUser); master.risp_data = risp_init(NULL); assert(master.risp_data); storage = storage_init(NULL); assert(storage); if (storage_lock_file(storage, filename) == 0) { fprintf(stderr, "Unable to open file, it appears to be locked.\n"); exit(1); } else { // we were able to lock the file, so we can continue. From this point on, we cannot exit without unlocking the file. // TODO: We should intercept the signals at this point to ensure that the lock gets released. // process the main meta file; storage_process_file(storage, filename, master.risp_top, &master); storage_unlock_file(storage, filename); } // cleanup the risp interface. assert(master.risp_top); risp_shutdown(master.risp_top); master.risp_top = NULL; assert(master.risp_op); risp_shutdown(master.risp_op); master.risp_op = NULL; assert(master.risp_payload); risp_shutdown(master.risp_payload); master.risp_payload = NULL; assert(master.risp_data); risp_shutdown(master.risp_data); master.risp_data = NULL; assert(storage); storage_free(storage); storage = NULL; assert(master.risp_top == NULL); return 0; }
void rfcm_written(io_handle_t *handle, io_buf_t *buf, int status) { if(status > 0) { storage_free(&storage, buf->base); puts("bluetooth sent to tcp1."); } else perror("rfcm_written"); }
void __pthread_thread_halt (struct __pthread *thread, int need_dealloc) { /* We may deallocate THREAD. First save any data we need. */ addr_t exception_area[EXCEPTION_AREA_SIZE / PAGESIZE]; memcpy (exception_area, thread->exception_area, sizeof (thread->exception_area)); memset (thread->exception_area, 0, sizeof (thread->exception_area)); void *va = thread->exception_area_va; addr_t object = thread->object; l4_thread_id_t tid = thread->threadid; if (need_dealloc) __pthread_dealloc (thread); /* The THREAD data structure is no longer valid. */ thread = NULL; /* Deallocate any saved object. */ ss_mutex_lock (&saved_object_lock); if (! ADDR_IS_VOID (saved_object)) { storage_free (saved_object, false); saved_object = ADDR_VOID; } ss_mutex_unlock (&saved_object_lock); /* Free the exception area. */ /* Clean up the exception page. */ exception_page_cleanup (ADDR_TO_PTR (addr_extend (exception_area[EXCEPTION_PAGE], 0, PAGESIZE_LOG2))); /* Free the storage. */ int i; for (i = 0; i < EXCEPTION_AREA_SIZE / PAGESIZE; i ++) { assert (! ADDR_IS_VOID (exception_area[i])); storage_free (exception_area[i], false); } /* And the address space. */ as_free (addr_chop (PTR_TO_ADDR (va), EXCEPTION_AREA_SIZE_LOG2), false); if (tid == l4_myself ()) /* If we try to storage_free (storage.addr), we will freeze in the middle. That's no good. We set SAVED_OBJECT to our thread object and the next thread in will free us. */ { ss_mutex_lock (&saved_object_lock); saved_object = object; ss_mutex_unlock (&saved_object_lock); } else storage_free (object, false); if (tid == l4_myself ()) { l4_send_timeout (l4_myself (), L4_NEVER); panic ("Failed to stop thread %x.%x!", l4_thread_no (l4_myself ()), l4_version (l4_myself ())); } else thread_stop (object); }
void do_profiling(const int *sizes, const size_t count) { const int repetitions = 50; const int size_field_width = 5; const int result_field_width = 15; const plan_constructor_t plan_constructors[] = { interpolate_plan_3d_naive_interleaved, interpolate_plan_3d_padding_aware_interleaved, interpolate_plan_3d_phase_shift_interleaved, }; const papi_event_t counters[] = { PAPI_TOT_CYC, PAPI_L3_TCM, PAPI_DP_OPS }; const size_t num_plan_constructors = sizeof(plan_constructors)/sizeof(plan_constructors[0]); const size_t num_counters = sizeof(counters)/sizeof(counters[0]); printf("%*s", size_field_width, ""); for(size_t constructor_index = 0; constructor_index < num_plan_constructors; ++constructor_index) { interpolate_plan plan = plan_constructors[constructor_index](1, 1, 1, 0); assert(plan != NULL); printf("%*s", (int) (result_field_width * num_counters), interpolate_get_name(plan)); interpolate_destroy_plan(plan); } printf("\n"); printf("%*s", size_field_width, ""); for(size_t constructor_index = 0; constructor_index < num_plan_constructors; ++constructor_index) { char name[PAPI_MAX_STR_LEN]; for(size_t i=0; i < num_counters; ++i) { PAPI_CHECK(PAPI_event_code_to_name(counters[i], name)); printf("%*s", result_field_width, name); } } printf("\n"); for(size_t size_index = 0; size_index < count; ++size_index) { const int layout = INTERLEAVED; const size_t size = sizes[size_index]; const size_t block_size = size * size * size; storage_t coarse, fine; storage_allocate(&coarse, layout, block_size); storage_allocate(&fine, layout, 8 * block_size); printf("%5zd", size); for(size_t constructor_index = 0; constructor_index < num_plan_constructors; ++constructor_index) { interpolate_plan plan = plan_constructors[constructor_index](size, size, size, 0); assert(plan != NULL); papi_multiplex_t multiplex; PAPI_CHECK(pm_init(&multiplex)); for(size_t i=0; i < num_counters; ++i) PAPI_CHECK(pm_add_event(&multiplex, counters[i])); for(int repetition = 0; repetition < repetitions; ++repetition) { PAPI_CHECK(pm_start(&multiplex)); execute_interpolate(plan, &coarse, &fine); PAPI_CHECK(pm_stop(&multiplex)); } for(size_t i=0; i < num_counters; ++i) { long long value; PAPI_CHECK(pm_count(&multiplex, counters[i], &value)); printf("%15lld", value); } PAPI_CHECK(pm_destroy(&multiplex)); interpolate_destroy_plan(plan); } printf("\n"); storage_free(&coarse); storage_free(&fine); } }