<commit_before>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium team:
http://bohrium.bitbucket.org

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BOHRIUM_BRIDGE_CPP_RUNTIME
#define __BOHRIUM_BRIDGE_CPP_RUNTIME
#include <iostream>
#include <sstream>

namespace bxx {

// Runtime : Definition
inline Runtime& Runtime::instance()
{
    static Runtime instance;
    return instance;
}

inline Runtime::Runtime() : global_random_seed_(0), global_random_state_(0), extension_count(BH_MAX_OPCODE_ID+1), queue_size(0)
{
    bh_error err;
    char err_msg[1000];

    if((err = bh_component_init(&bridge, NULL)) != BH_SUCCESS)
        exit(-1);
    if(bridge.nchildren != 1)
    {
        sprintf(err_msg, "Error in the runtime configuration: the bridge must "
                         "have exactly one child of type VEM or FILTER.\n");
        throw std::runtime_error(err_msg);
    }
    runtime = &bridge.children[0];
    if((err = runtime->init(runtime->name)) != BH_SUCCESS)
    {
        sprintf(err_msg, "Error in the initialization of the VEM.\n");
        throw std::runtime_error(err_msg);
    }
}

inline Runtime::~Runtime()
{
    if (ref_count.size()) {
        std::cout << "There are " << ref_count.size() << " dangling refs." << std::endl;
        for (std::map<bh_base*, size_t>::iterator it=ref_count.begin();
            it!=ref_count.end();
            ++it) {
            std::cout << it->first << " => " << it->second << '\n';
        }
    }
 
    flush();
    runtime->shutdown();
    bh_component_destroy(&bridge);
}

inline size_t Runtime::get_queue_size()
{<commit_msg>bxx: Moved assignment out of conditional.<commit_after>/*
This file is part of Bohrium and copyright (c) 2012 the Bohrium team:
http://bohrium.bitbucket.org

Bohrium is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.

Bohrium is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the
GNU Lesser General Public License along with Bohrium.

If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BOHRIUM_BRIDGE_CPP_RUNTIME
#define __BOHRIUM_BRIDGE_CPP_RUNTIME
#include <iostream>
#include <sstream>

namespace bxx {

// Runtime : Definition
inline Runtime& Runtime::instance()
{
    static Runtime instance;
    return instance;
}

inline Runtime::Runtime() : global_random_seed_(0), global_random_state_(0), extension_count(BH_MAX_OPCODE_ID+1), queue_size(0)
{
    char err_msg[1000];

    bh_error err = bh_component_init(&bridge, NULL);
    if (BH_SUCCESS != err) {
        exit(-1);
    }
    if (bridge.nchildren != 1) {
        sprintf(err_msg, "Error in the runtime configuration: the bridge must "
                         "have exactly one child of type VEM or FILTER.\n");
        throw std::runtime_error(err_msg);
    }
    runtime = &bridge.children[0];

    err = runtime->init(runtime->name);
    if (BH_SUCCESS != err) {
        sprintf(err_msg, "Error in the initialization of the VEM.\n");
        throw std::runtime_error(err_msg);
    }
}

inline Runtime::~Runtime()
{
    if (ref_count.size()) {
        std::cout << "There are " << ref_count.size() << " dangling refs." << std::endl;
        for (std::map<bh_base*, size_t>::iterator it=ref_count.begin();
            it!=ref_count.end();
            ++it) {
            std::cout << it->first << " => " << it->second << '\n';
        }
    }
 
    flush();
    runtime->shutdown();
    bh_component_destroy(&bridge);
}

inline size_t Runtime::get_queue_size()
{
{'fraction_non_alphanumeric': 0.11514876220758574, 'fraction_numerical': 0.0072677719736543266, 'mean_word_length': 3.3864541832669324, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2102234', 'n_tokens_mistral': 1363, 'n_tokens_neox': 1320, 'n_words': 433}