void deposit(string rec) {
		while (count == lenght - 1) {
			not_full.wait();
		}
		
		buffer[rear] = rec;
		if (rear < lenght)
			rear++;
		if (rear == lenght)
			rear = 0;
		count++;
		not_empty.post();
	}	
	string fetch() {
		while (count == 0) {
			not_empty.wait();
		}
		string result = buffer[front];

		if (front < lenght)
			front = (front + 1) % lenght;
		if (front == lenght)
			front = 0;
		count--;
		not_full.post();
		//buffer[front] = "";
		return result;
	}
Пример #3
0
NMBLSEXPORT void handleUnLoadLibrary(void)
{
    done = true;
    sign.post();

    // Currently throwing: what():  boost: mutex lock failed in pthread_mutex_lock: Invalid argument
    // But given we are using an atomic done flag - is this needed?
    // worker_thread.join_all();

    for ( auto it = dbhandles.begin(); it != dbhandles.end(); it++)
    {
        sqlite3_close_v2(it->second);
    }

    std::cout << "Oppertunity to clean up..." << std::endl;
}
Пример #4
0
NMBLSEXPORT bool handleWebRequest(std::string method, websockcon ref, std::string webfilename, ValuePair &queryparams, ValuePair &httpheaders, boost::function<void(std::string, std::string, std::string)> postResponceCallback)
{
    // Only supported method (at the moment?)
    if ( "GET" != method )
    {
        return false;
    }
    // First check if we have a statement to process for this request.
    std::string filename;
    // This should be long enough
    filename.reserve(512);

    filename += docroot;
    filename += boost::filesystem::path::preferred_separator;

    // To get here we must have got the host header
    std::string host = httpheaders["host"];
    filename += host;
    filename += boost::filesystem::path::preferred_separator;

    filename += "sqlite";
    filename += boost::filesystem::path::preferred_separator;
    std::string hostroot = filename;

    filename += "files";
    filename += boost::filesystem::path::preferred_separator;
    filename += webfilename;

    if (is_running_as_debug) std::cout << "Checking for sqlite file " << filename << std::endl;

    try{
        if ( !boost::filesystem::is_regular_file(filename) )
        {
            if ( !boost::filesystem::is_directory(filename) )
            {
                return false;
            }
            else
            {
                filename += boost::filesystem::path::preferred_separator;
                filename += "index";

                if ( !boost::filesystem::is_regular_file(filename) )
                {
                    // nothing to see here!
                    return false;
                }
            }
        }
    }
    catch (boost::filesystem::filesystem_error)
    {
        return false;
    }

    // Second check we have not created too much of a backlog
    if ( backlog >= WORKERBACKLOGSIZE )
    {
        // Post a 500 error of some form...
        return true;
    }

    // Now post it to the workers.
    int currentindex = nextavailable % WORKERBACKLOGSIZE ;
    nextavailable++;
    backlog++;

    auto it = requests.begin() + currentindex;
    it->ref = ref;
    it->filename = filename;
    it->host = host;
    it->hostroot = hostroot;
    it->postResponceCallback = postResponceCallback;
    it->http_headers = httpheaders;
    it->params = queryparams;

    workqueue.push(currentindex);
    sign.post();

    return true;
}