Ejemplo n.º 1
0
int
main(int argc, char **argv)
{
    server_args_t server_args;
    pthread_t server_thread;

    seed_random();

    burp_track = track_new(BURP_WAV);
    if (! burp_track) {
	perror(BURP_WAV);
	exit(1);
    }

    p = piface_new();

    pthread_mutex_init(&event_lock, NULL);
    server_args.port = 5555;
    server_args.command = remote_event;
    server_args.state = NULL;

    pthread_create(&server_thread, NULL, server_thread_main, &server_args);

    while(true) {
	wait_for_trigger();
	take_action();
	wait_for_trigger_release();
	if (n_consecutive_spits) {
	    wait_for_recharge();
	}
    }

    return 0;
}
Ejemplo n.º 2
0
//
//the routine for deleting keys in pool
//
void* NVM_KV_Pool_Del_Manager::start_thread()
{
    pthread_mutex_t *glb_mtx = get_store()->get_pool_mgr()->get_glb_mutex();
    NVM_KV_Store* kv_store = get_store();
    NVM_KV_Pool_Mgr* pool_mgr = kv_store->get_pool_mgr();
    bool delete_all_pools = false;
    int ret_code = NVM_SUCCESS;

    set_cancel_state();
    //register function that needs to be called on thread cancellation
    pthread_cleanup_push(&NVM_KV_Scanner::scanner_cancel_routine, get_mutex());
    pthread_cleanup_push(&NVM_KV_Scanner::scanner_cancel_routine, glb_mtx);
    while (true)
    {

        //cancellation point
        pthread_testcancel();
        //check if the pool deletion map is empty, if not
        //return from the wait else start waiting for
        //external trigger
        pthread_mutex_lock(get_mutex());
        while (!pool_mgr->has_pools_to_delete())
        {
            wait_for_trigger();
        }
        //copy out the pool deletion bitmap to m_pools_to_delete bitmap for
        //processing. This operation is protected by pool bitmap mutex.
        pool_mgr->get_pool_deletion_bitmap(m_pools_to_delete, delete_all_pools);
        pthread_mutex_unlock(get_mutex());

        //to yield to pool deletion manager, pool deletion status is set right
        //away
        pool_mgr->set_pool_del_status(true);

        //acquire global lock to synchronize with expiry manager
        pthread_mutex_lock(glb_mtx);
        if ((ret_code = start_pool_delete(delete_all_pools)) != NVM_SUCCESS)
        {
            fprintf(stderr, "Pool deletion encounter error: %d\n", ret_code);
        }

        pool_mgr->set_pool_del_status(false);

        //trigger expiry thread
        if (get_store()->expiry_status())
        {
            get_store()->get_expiry_thread()->restart_scanner_if_asleep();
        }
        pthread_mutex_unlock(glb_mtx);
    }
    pthread_cleanup_pop(0);
    pthread_cleanup_pop(0);
    return NULL;
}