/* allocate memory and do data initialization, threads initialization, also call reset write/read pointers */ int bsreader_open(void) { int ret = 0; u32 max_entry_num; lock_all(); if (G_ready) { printf("already opened\n"); return -1; } //init iav and test iav state, it's expected iav should not be in encoding, before open bsreader if (init_iav() < 0) { ret = -3; goto error_catch; } max_entry_num = G_bsreader_init_data.max_buffered_frame_num; myFIFO[0] = fifo_create(G_bsreader_init_data.ring_buf_size[0], sizeof(bs_info_t), max_entry_num); myFIFO[1] = fifo_create(G_bsreader_init_data.ring_buf_size[1], sizeof(bs_info_t), max_entry_num); myFIFO[2] = fifo_create(G_bsreader_init_data.ring_buf_size[2], sizeof(bs_info_t), max_entry_num); myFIFO[3] = fifo_create(G_bsreader_init_data.ring_buf_size[3], sizeof(bs_info_t), max_entry_num); //init cavlc if (G_bsreader_init_data.cavlc_possible) { if (init_cavlc() < 0) { printf("init cavlc in bsreader error \n"); ret = -2; goto error_catch; } } //create thread after all other initialization is done if (create_working_thread() < 0) { printf("create working thread error \n"); ret = -1; goto error_catch; } G_ready = 1; unlock_all(); return 0; error_catch: cancel_working_thread(); if (G_bsreader_init_data.cavlc_possible) { destroy_cavlc(); } unlock_all(); printf("bsreader opened.\n"); return ret; }
void keydb_release (KEYDB_HANDLE hd) { int i; if (!hd) return; assert (active_handles > 0); active_handles--; unlock_all (hd); for (i=0; i < hd->used; i++) { switch (hd->active[i].type) { case KEYDB_RESOURCE_TYPE_NONE: break; case KEYDB_RESOURCE_TYPE_KEYRING: keyring_release (hd->active[i].u.kr); break; case KEYDB_RESOURCE_TYPE_KEYBOX: keybox_release (hd->active[i].u.kb); break; } } xfree (hd); }
/* * The current keyblock or cert will be deleted. */ int keydb_delete (KEYDB_HANDLE hd, int unlock) { int rc = -1; if (!hd) return gpg_error (GPG_ERR_INV_VALUE); if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ if( opt.dry_run ) return 0; if (!hd->locked) return gpg_error (GPG_ERR_NOT_LOCKED); switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = gpg_error (GPG_ERR_GENERAL); break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_delete (hd->active[hd->found].u.kr); break; } if (unlock) unlock_all (hd); return rc; }
/* Update the current keyblock with KB. */ int keydb_update_cert (KEYDB_HANDLE hd, ksba_cert_t cert) { int rc = 0; unsigned char digest[20]; if (!hd) return gpg_error (GPG_ERR_INV_VALUE); if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ if (opt.dry_run) return 0; rc = lock_all (hd); if (rc) return rc; gpgsm_get_fingerprint (cert, GCRY_MD_SHA1, digest, NULL); /* kludge*/ switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = gpg_error (GPG_ERR_GENERAL); /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_update_cert (hd->active[hd->found].u.kr, cert, digest); break; } unlock_all (hd); return rc; }
/* * Insert a new KB into one of the resources. */ int keydb_insert_keyblock (KEYDB_HANDLE hd, KBNODE kb) { int rc = -1; int idx; if (!hd) return G10ERR_INV_ARG; if( opt.dry_run ) return 0; if ( hd->found >= 0 && hd->found < hd->used) idx = hd->found; else if ( hd->current >= 0 && hd->current < hd->used) idx = hd->current; else return G10ERR_GENERAL; rc = lock_all (hd); if (rc) return rc; switch (hd->active[idx].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = G10ERR_GENERAL; /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYRING: rc = keyring_insert_keyblock (hd->active[idx].u.kr, kb); break; } unlock_all (hd); return rc; }
/* free all resources, close all threads */ int bsreader_close(void) { int ret = 0; lock_all(); //TODO, possible release if (!G_ready) { printf("has not opened, cannot close\n"); return -1; } if (cancel_working_thread() < 0) { perror("pthread_cancel bsreader main"); return -1; } else { DEBUG_PRINT("main working thread canceled \n"); } fifo_close(myFIFO[0]); fifo_close(myFIFO[1]); fifo_close(myFIFO[2]); fifo_close(myFIFO[3]); if (G_bsreader_init_data.cavlc_possible) { destroy_cavlc(); } G_ready = 0; unlock_all(); pthread_mutex_destroy(&G_all_mutex); return ret; }
/* * update the current keyblock with KB */ int keydb_update_keyblock (KEYDB_HANDLE hd, KBNODE kb) { int rc = 0; if (!hd) return G10ERR_INV_ARG; if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ if( opt.dry_run ) return 0; if (!hd->locked) return gpg_error (GPG_ERR_NOT_LOCKED); switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = G10ERR_GENERAL; /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_update_keyblock (hd->active[hd->found].u.kr, kb); break; } unlock_all (hd); return rc; }
/* * The current keyblock will be deleted. */ int keydb_delete_keyblock (KEYDB_HANDLE hd) { int rc = -1; if (!hd) return G10ERR_INV_ARG; if ( hd->found < 0 || hd->found >= hd->used) return -1; /* nothing found */ if( opt.dry_run ) return 0; rc = lock_all (hd); if (rc) return rc; switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = G10ERR_GENERAL; /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYRING: rc = keyring_delete_keyblock (hd->active[hd->found].u.kr); break; } unlock_all (hd); return rc; }
/* * Insert a new KB into one of the resources. */ gpg_error_t keydb_insert_keyblock (KEYDB_HANDLE hd, kbnode_t kb) { gpg_error_t err; int idx; if (!hd) return gpg_error (GPG_ERR_INV_ARG); keyblock_cache_clear (); if (opt.dry_run) return 0; if (hd->found >= 0 && hd->found < hd->used) idx = hd->found; else if (hd->current >= 0 && hd->current < hd->used) idx = hd->current; else return gpg_error (GPG_ERR_GENERAL); err = lock_all (hd); if (err) return err; switch (hd->active[idx].type) { case KEYDB_RESOURCE_TYPE_NONE: err = gpg_error (GPG_ERR_GENERAL); /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYRING: err = keyring_insert_keyblock (hd->active[idx].u.kr, kb); break; case KEYDB_RESOURCE_TYPE_KEYBOX: { /* We need to turn our kbnode_t list of packets into a proper keyblock first. This is required by the OpenPGP key parser included in the keybox code. Eventually we can change this kludge to have the caller pass the image. */ iobuf_t iobuf; u32 *sigstatus; err = build_keyblock_image (kb, &iobuf, &sigstatus); if (!err) { err = keybox_insert_keyblock (hd->active[idx].u.kb, iobuf_get_temp_buffer (iobuf), iobuf_get_temp_length (iobuf), sigstatus); xfree (sigstatus); iobuf_close (iobuf); } } break; } unlock_all (hd); return err; }
int Sequencer::reset() { wrlock_all(run_locks_); for (auto& sorted_run: runs_) { ready_.push_back(move(sorted_run)); } unlock_all(run_locks_); runs_resize_lock_.lock(); runs_.clear(); runs_resize_lock_.unlock(); sequence_number_.store(1); return 1; }
aku_Status Sequencer::close(PageHeader* target) { wrlock_all(run_locks_); for (auto& sorted_run: runs_) { ready_.push_back(move(sorted_run)); } unlock_all(run_locks_); runs_resize_lock_.lock(); runs_.clear(); runs_resize_lock_.unlock(); sequence_number_.store(1); return merge_and_compress(target, true); }
static void dstress(int num) { unsigned int n, skips, lock_ops, unlock_ops, unlockf_ops, cancel_ops; int i; struct lk *lk; n = skips = lock_ops = unlock_ops = unlockf_ops = cancel_ops = 0; sts_eunlock = sts_ecancel = sts_etimedout = sts_edeadlk = sts_eagain = sts_other = sts_zero = 0; bast_unlock = bast_skip = 0; noqueue = 0; ignore_bast = 1; quiet = 0; while (!stress_stop && n < num) { sleep(1); process_libdlm(); if (n && !(n % 60)) unlock_all(); n++; i = rand_int(0, maxn-1); lk = get_lock(i); if (!lk) continue; if (lk->wait_ast || lk->grmode > -1) { printf("%8x: lock %3d\t%x: skip gr %d wait_ast %d\n", n, i, lk->lksb.sb_lkid, lk->grmode, lk->wait_ast); continue; } lock(i, rand_int(0, 5)); lock_ops++; printf("%8x: lock %3d\t%x\n", n, i, lk->lksb.sb_lkid); } printf("ops: skip %d lock %d unlock %d unlockf %d cancel %d\n", skips, lock_ops, unlock_ops, unlockf_ops, cancel_ops); printf("bast: unlock %u skip %u\n", bast_unlock, bast_skip); printf("ast status: eunlock %d ecancel %d etimedout %d edeadlk %d eagain %d\n", sts_eunlock, sts_ecancel, sts_etimedout, sts_edeadlk, sts_eagain); printf("ast status: zero %d other %d\n", sts_zero, sts_other); }
/* * Update the current keyblock with the keyblock KB */ gpg_error_t keydb_update_keyblock (KEYDB_HANDLE hd, kbnode_t kb) { gpg_error_t rc; if (!hd) return gpg_error (GPG_ERR_INV_ARG); keyblock_cache_clear (); if (hd->found < 0 || hd->found >= hd->used) return gpg_error (GPG_ERR_VALUE_NOT_FOUND); if (opt.dry_run) return 0; rc = lock_all (hd); if (rc) return rc; switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = gpg_error (GPG_ERR_GENERAL); /* oops */ break; case KEYDB_RESOURCE_TYPE_KEYRING: rc = keyring_update_keyblock (hd->active[hd->found].u.kr, kb); break; /* case KEYDB_RESOURCE_TYPE_KEYRING: */ /* rc = build_keyblock (kb, &image, &imagelen); */ /* if (!rc) */ /* rc = keybox_update_keyblock (hd->active[hd->found].u.kb, */ /* image, imagelen); */ /* break; */ } unlock_all (hd); return rc; }
/* * Insert a new Certificate into one of the resources. */ int keydb_insert_cert (KEYDB_HANDLE hd, ksba_cert_t cert) { int rc = -1; int idx; unsigned char digest[20]; if (!hd) return gpg_error (GPG_ERR_INV_VALUE); if (opt.dry_run) return 0; if ( hd->found >= 0 && hd->found < hd->used) idx = hd->found; else if ( hd->current >= 0 && hd->current < hd->used) idx = hd->current; else return gpg_error (GPG_ERR_GENERAL); if (!hd->locked) return gpg_error (GPG_ERR_NOT_LOCKED); gpgsm_get_fingerprint (cert, GCRY_MD_SHA1, digest, NULL); /* kludge*/ switch (hd->active[idx].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = gpg_error (GPG_ERR_GENERAL); break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_insert_cert (hd->active[idx].u.kr, cert, digest); break; } unlock_all (hd); return rc; }
/* * Delete the current keyblock. */ gpg_error_t keydb_delete_keyblock (KEYDB_HANDLE hd) { gpg_error_t rc; if (!hd) return gpg_error (GPG_ERR_INV_ARG); keyblock_cache_clear (); if (hd->found < 0 || hd->found >= hd->used) return gpg_error (GPG_ERR_VALUE_NOT_FOUND); if (opt.dry_run) return 0; rc = lock_all (hd); if (rc) return rc; switch (hd->active[hd->found].type) { case KEYDB_RESOURCE_TYPE_NONE: rc = gpg_error (GPG_ERR_GENERAL); break; case KEYDB_RESOURCE_TYPE_KEYRING: rc = keyring_delete_keyblock (hd->active[hd->found].u.kr); break; case KEYDB_RESOURCE_TYPE_KEYBOX: rc = keybox_delete (hd->active[hd->found].u.kb); break; } unlock_all (hd); return rc; }
void test_tablockman_simple() { /* simple */ lock_ok_a(1, 1, S); lock_ok_i(2, 2, IS); lock_ok_i(1, 2, IX); /* lock escalation */ lock_ok_a(1, 1, X); lock_ok_i(2, 2, IX); /* failures */ lock_conflict(2, 1, X); unlock_all(2); lock_ok_a(1, 2, S); lock_ok_a(1, 2, IS); lock_ok_a(1, 2, LS); lock_ok_i(1, 3, IX); lock_ok_a(2, 3, LS); lock_ok_i(1, 3, IX); lock_ok_l(2, 3, IS); unlock_all(1); unlock_all(2); lock_ok_i(1, 1, IX); lock_conflict(2, 1, S); lock_ok_a(1, 1, LS); unlock_all(1); unlock_all(2); lock_ok_i(1, 1, IX); lock_ok_a(2, 1, LS); lock_ok_a(1, 1, LS); lock_ok_i(1, 1, IX); lock_ok_i(3, 1, IS); unlock_all(1); unlock_all(2); unlock_all(3); lock_ok_i(1, 4, IS); lock_ok_i(2, 4, IS); lock_ok_i(3, 4, IS); lock_ok_a(3, 4, LS); lock_ok_i(4, 4, IS); lock_conflict(4, 4, IX); lock_conflict(2, 4, IX); lock_ok_a(1, 4, LS); unlock_all(1); unlock_all(2); unlock_all(3); unlock_all(4); lock_ok_i(1, 1, IX); lock_ok_i(2, 1, IX); lock_conflict(1, 1, S); lock_conflict(2, 1, X); unlock_all(1); unlock_all(2); lock_ok_i(1, 1, IS); lock_conflict(2, 1, X); lock_conflict(3, 1, IS); unlock_all(1); unlock_all(2); unlock_all(3); lock_ok_a(1, 1, S); lock_conflict(2, 1, IX); lock_conflict(3, 1, IS); unlock_all(1); unlock_all(2); unlock_all(3); }
static void process_command(int *quit) { char inbuf[132]; int x = 0, y = 0; if (!opt_cmd) { fgets(inbuf, sizeof(inbuf), stdin); sscanf(inbuf, "%s %d %d", cmd, &x, &y); } if (!strncmp(cmd, "EXIT", 4)) { *quit = 1; unlock_all(); return; } if (!strncmp(cmd, "CLOSE", 5)) { *quit = 1; openclose_ls = 1; unlock_all(); return; } if (!strncmp(cmd, "kill", 4)) { printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "lock", 4) && strlen(cmd) == 4) { lock(x, y); return; } if (!strncmp(cmd, "unlock", 6) && strlen(cmd) == 6) { unlock(x); return; } if (!strncmp(cmd, "unlockf", 7) && strlen(cmd) == 7) { unlockf(x); return; } if (!strncmp(cmd, "cancel", 6) && strlen(cmd) == 6) { cancel(x); return; } if (!strncmp(cmd, "canceld", 7) && strlen(cmd) == 7) { canceld(x, y); return; } if (!strncmp(cmd, "lock_sync", 9) && strlen(cmd) == 9) { lock_sync(x, y); return; } if (!strncmp(cmd, "unlock_sync", 11) && strlen(cmd) == 11) { unlock_sync(x); return; } if (!strncmp(cmd, "lock-kill", 9) && strlen(cmd) == 9) { lock(x, y); printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "unlock-kill", 11) && strlen(cmd) == 11) { unlock(x); printf("process exiting\n"); exit(0); } if (!strncmp(cmd, "lock-cancel", 11) && strlen(cmd) == 11) { lock(x, y); /* usleep(1000 * z); */ cancel(x); return; } if (!strncmp(cmd, "lock-unlockf", 12) && strlen(cmd) == 12) { lock(x, y); /* usleep(1000 * z); */ unlockf(x); return; } if (!strncmp(cmd, "ex", 2)) { lock(x, LKM_EXMODE); return; } if (!strncmp(cmd, "pr", 2)) { lock(x, LKM_PRMODE); return; } if (!strncmp(cmd, "hold", 4) && strlen(cmd) == 4) { lock_all(LKM_PRMODE); return; } if (!strncmp(cmd, "hold-kill", 9) && strlen(cmd) == 9) { lock_all(LKM_PRMODE); exit(0); } if (!strncmp(cmd, "release", 7) && strlen(cmd) == 7) { unlock_all(); return; } if (!strncmp(cmd, "release-kill", 12) && strlen(cmd) == 12) { unlock_all(); exit(0); } if (!strncmp(cmd, "dump", 4) && strlen(cmd) == 4) { dump(); return; } if (!strncmp(cmd, "stress", 6) && strlen(cmd) == 6) { if (iterations && !x) x = iterations; stress(x); return; } if (!strncmp(cmd, "tstress", 7) && strlen(cmd) == 7) { tstress(x); return; } if (!strncmp(cmd, "dstress", 7) && strlen(cmd) == 7) { dstress(x); return; } if (!strncmp(cmd, "stress_delay", 12) && strlen(cmd) == 12) { stress_delay = x; return; } if (!strncmp(cmd, "stress_lock_only", 16) && strlen(cmd) == 16) { stress_lock_only = !stress_lock_only; printf("stress_lock_only is %s\n", stress_lock_only ? "on" : "off"); return; } if (!strncmp(cmd, "stress_stop", 11) && strlen(cmd) == 11) { stress_stop = !stress_stop; printf("stress_stop is %d\n", stress_stop); return; } if (!strncmp(cmd, "ignore_bast", 11) && strlen(cmd) == 11) { ignore_bast = !ignore_bast; printf("ignore_bast is %s\n", ignore_bast ? "on" : "off"); return; } if (!strncmp(cmd, "our_xid", 7) && strlen(cmd) == 7) { our_xid = x; printf("our_xid is %llx\n", (unsigned long long)our_xid); return; } if (!strncmp(cmd, "purge", 5) && strlen(cmd) == 5) { purge(x, y); return; } if (!strncmp(cmd, "purgetest", 9) && strlen(cmd) == 9) { purgetest(x, y); return; } if (!strncmp(cmd, "noqueue", 7)) { noqueue = !noqueue; printf("noqueue is %s\n", noqueue ? "on" : "off"); return; } if (!strncmp(cmd, "persistent", 10)) { persistent = !persistent; printf("persistent is %s\n", persistent ? "on" : "off"); return; } if (!strncmp(cmd, "minhold", 7)) { minhold = x; return; } if (!strncmp(cmd, "timeout", 7)) { timeout = (uint64_t) 100 * x; /* dlm takes it in centiseconds */ printf("timeout is %d\n", x); return; } if (!strncmp(cmd, "quiet", 5)) { quiet = !quiet; printf("quiet is %d\n", quiet); return; } if (!strncmp(cmd, "verbose", 7)) { verbose = !verbose; printf("verbose is %d\n", verbose); return; } if (!strncmp(cmd, "help", 4)) { print_commands(); return; } if (!strncmp(cmd, "settings", 8)) { print_settings(); return; } printf("unknown command %s\n", cmd); }