Beispiel #1
0
/*
 * returns: -1 on error:
 *          timeout on timeout
 *          index into _signals array of signal that was generated on success
 */
int
Mono_Unix_UnixSignal_WaitAny (void** _signals, int count, int timeout /* milliseconds */, Mono_Posix_RuntimeIsShuttingDown shutting_down)
{
	int r;
	int currfd = 0;
	struct pollfd fd_structs[NUM_SIGNALS];

	signal_info** signals = (signal_info**) _signals;

	if (count > NUM_SIGNALS)
		return -1;

	if (acquire_mutex (&signals_mutex) == -1)
		return -1;

	r = setup_pipes (signals, count, &fd_structs[0], &currfd);

	release_mutex (&signals_mutex);

	if (r == 0) {
		r = wait_for_any (signals, count, &currfd, &fd_structs[0], timeout, shutting_down);
	}

	if (acquire_mutex (&signals_mutex) == -1)
		return -1;

	teardown_pipes (signals, count);

	release_mutex (&signals_mutex);

	return r;
}
void EDGAR_FilingFile::FindEDGAR_Tables(RunMode run_mode)
{
    // always start fresh

    EDGAR_filing_tables_.clear();

    CDocument the_filing;
    the_filing.parse(EDGAR_filing_content_.c_str());
    CSelection c = the_filing.find("table");

    // ConvertMarkupToText is a time consuming function -- it actually calls out to
    // an external process right now -- so let's do some async'ing !!

    // keep track of our async processes here.

    std::vector<std::future<std::string>> tasks;

    for (int indx = 0 ; indx < c.nodeNum(); ++indx)
    {
        CNode pNode = c.nodeAt(indx);

        // use the 'Outer' functions to include the table tags in the extracted content.

        std::string content = EDGAR_filing_content_.substr(pNode.startPosOuter(), pNode.endPosOuter() - pNode.startPosOuter());
		if (TableHasMarkup(content))
		{
            if (run_mode == RunMode::do_sync)
            {
    			std::string plain_table = ConvertMarkupToText(content);
                EDGAR_filing_tables_.push_back(plain_table);
            }
            else
                tasks.push_back(std::async(&EDGAR_FilingFile::ConvertMarkupToText, this, content));
		}
        else
            EDGAR_filing_tables_.push_back(content);
    }

    // now, let's go look for our output...

    for (int count = tasks.size(); count; --count)
    {
        int i = wait_for_any(tasks, std::chrono::microseconds{100});
        std::string converted_text;
        try
        {
            converted_text = tasks[i].get();
        }
        catch (...)
        {
            // any problems, let's just ignore them.
            poco_error(the_logger_, "Some problem with an async process");
            continue;
        }
        if (! converted_text.empty())
            EDGAR_filing_tables_.push_back(converted_text);
    }
}        // -----  end of method EDGAR_FilingFile::FindEDGAR_Tables  -----
/*
 * Repeatedly call wait_for_any() until it returns -ECHILD
 */
static void wait_for_all() {
    while (wait_for_any() != -ECHILD) ;
}
Beispiel #4
0
/* The core testproc code */
void *testproc(int arg1, void *arg2) {
    proc_thread_t pt;
    pid_t pid = -1;
    int rv = 0;
    int i = 0;

#if CS402TESTS > 0
    dbg_print("waitpid any test");
    start_proc(&pt, "waitpid any test", waitpid_test, 23);
    wait_for_any();

    dbg_print("waitpid test");
    start_proc(&pt, "waitpid test", waitpid_test, 32);
    pid = do_waitpid(2323, 0, &rv);
    if ( pid != -ECHILD ) dbg_print("Allowed wait on non-existent pid\n");
    wait_for_proc(pt.p);
/*
    dbg_print("kthread exit test");
    start_proc(&pt, "kthread exit test", kthread_exit_test, 0);
    wait_for_proc(pt.p);
*/
/*
    dbg_print("many test");
    for (i = 0; i < 10; i++) 
	start_proc(NULL, "many test", waitpid_test, i);
    wait_for_all();a
*/
#endif

#if CS402TESTS > 1
    dbg_print("Context switch test");
    start_proc(&pt, "Context switch", racer_test, 0);
    wait_for_proc(pt.p);
#endif

#if CS402TESTS > 2
    sched_queue_init(&wake_me_q);

    dbg_print("wake me test");
    wake_me_len = 0;
    start_proc(&pt, "wake me test", wakeme_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("broadcast me test");
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "broadcast me test", wakeme_test, 0);
    stop_until_queued(10, &wake_me_len);
    /* Make sure the processes have blocked */
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 3
    dbg_print("wake me uncancellable test");
    start_proc(&pt, "wake me uncancellable test", 
	    wakeme_uncancellable_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("broadcast me uncancellable test");
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "broadcast me uncancellable test", 
		wakeme_uncancellable_test, 0);
    /* Make sure the processes have blocked */
    stop_until_queued(10, &wake_me_len);
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 4
    dbg_print("cancel me test");
    start_proc(&pt, "cancel me test", cancelme_test, 0);
    /* Make sure p has blocked */
    stop_until_queued(1, &wake_me_len);
    sched_cancel(pt.t);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("prior cancel me test");
    start_proc(&pt, "prior cancel me test", cancelme_test, 0);
    /*  Cancel before sleep */
    sched_cancel(pt.t);
    wait_for_proc(pt.p);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");

    dbg_print("cancel me head test");
    start_proc(&pt, "cancel me head test", cancelme_test, 0);
    start_proc(NULL, "cancel me head test", wakeme_test, 0);
    stop_until_queued(2, &wake_me_len);
    sched_cancel(pt.t);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
    
    dbg_print("cancel me tail test");
    start_proc(NULL, "cancel me tail test", wakeme_test, 0);
    start_proc(&pt, "cancel me tail test", cancelme_test, 0);
    stop_until_queued(2, &wake_me_len);
    sched_cancel(pt.t);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 5
    dbg_print("Reparenting test");
    start_proc(NULL, "Reparenting test", reparent_test, 1);
    stop_until_queued(1, &wake_me_len);
    sched_wakeup_on(&wake_me_q);
    wait_for_all();
    stop_until_zero(&wake_me_len);
    dbg_print("Reparenting stress test");
    start_proc(NULL, "Reparenting stress test", reparent_test, 10);
    stop_until_queued(10, &wake_me_len);
    sched_broadcast_on(&wake_me_q);
    wait_for_all();
    stop_until_zero(&wake_me_len);
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 6
    kmutex_init(&mutex);

    dbg_print("show race test");
    race = 0;
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "show race test", racer_test, 0);
    wait_for_all();

    dbg_print("fix race test");
    race = 0;
    for (i = 0; i < 10; i++ ) 
	start_proc(NULL, "fix race test", mutex_uncancellable_test, 0);
    wait_for_all();

    dbg_print("fix race test w/cancel");
    race = 0;
    for (i = 0; i < 10; i++ ) {
	if ( i % 2 == 0) { 
	    start_proc(NULL, "fix race test w/cancel", mutex_test, 0);
	} else {
	    start_proc(&pt, "fix race test w/cancel", mutex_test_cancelme, 0);
	    sched_cancel(pt.t);
	}
    }
    wait_for_all();
#endif

#if CS402TESTS > 7
    dbg_print("kill all test");
    for ( i=0 ; i < 10; i++ )
	start_proc(NULL, "kill all test", cancelme_test, 0);
    stop_until_queued(10, &wake_me_len);
    proc_kill_all();
    wait_for_all();
    KASSERT(wake_me_len == 0 && "Error on wakeme bookkeeping");
#endif

#if CS402TESTS > 8
    student_tests(arg1, arg2);
#endif

    dbg_print("All tests completed\n\n");
    return NULL;
}