<commit_before>#include <sys/statvfs.h>

#include <unordered_map>
#include <sstream>

#include "pin.H"

#include "boost_interprocess.h"

#include "feeder.h"
#include "multiprocess_shared.h"
#include "ipc_queues.h"
#include "BufferManagerProducer.h"


namespace xiosim
{
namespace buffer_management
{

static void copyProducerToFile(pid_t tid, bool checkSpace);
static void copyProducerToFileReal(pid_t tid, bool checkSpace);
static void copyProducerToFileFake(pid_t tid);
static void writeHandshake(pid_t tid, int fd, handshake_container_t* handshake);
static int getKBFreeSpace(boost::interprocess::string path);
static void reserveHandshake(pid_t tid);
static shm_string genFileName(boost::interprocess::string path);

static std::unordered_map<pid_t, Buffer*> produceBuffer_;
static std::unordered_map<pid_t, int> writeBufferSize_;
static std::unordered_map<pid_t, void*> writeBuffer_;
static std::vector<boost::interprocess::string> bridgeDirs_;
static boost::interprocess::string gpid_;

void InitBufferManagerProducer(pid_t harness_pid, int num_cores)
{
    InitBufferManager(harness_pid, num_cores);

    produceBuffer_.reserve(MAX_CORES);
    writeBufferSize_.reserve(MAX_CORES);
    writeBuffer_.reserve(MAX_CORES);

    bridgeDirs_.push_back("/dev/shm/");
    bridgeDirs_.push_back("/tmp/");
    bridgeDirs_.push_back("./");

    int pid = getpgrp();
    ostringstream iss;
    iss << pid;
    gpid_ = iss.str().c_str();
    assert(gpid_.length() > 0);
    cerr << " Creating temp files with prefix "  << gpid_ << "_*" << endl;
}

void DeinitBufferManagerProducer()
{
    DeinitBufferManager();

    for(int i = 0; i < (int)bridgeDirs_.size(); i++) {
        boost::interprocess::string cmd = "/bin/rm -rf " + bridgeDirs_[i] + gpid_ + "_* &";
        int retVal = system(cmd.c_str());
        (void)retVal;
        assert(retVal == 0);
    }
}

void AllocateThreadProducer(pid_t tid)
{
    int bufferCapacity = AllocateThread(tid);<commit_msg>Don't fall back on "." for the buffers.<commit_after>#include <sys/statvfs.h>

#include <unordered_map>
#include <sstream>

#include "pin.H"

#include "boost_interprocess.h"

#include "feeder.h"
#include "multiprocess_shared.h"
#include "ipc_queues.h"
#include "BufferManagerProducer.h"


namespace xiosim
{
namespace buffer_management
{

static void copyProducerToFile(pid_t tid, bool checkSpace);
static void copyProducerToFileReal(pid_t tid, bool checkSpace);
static void copyProducerToFileFake(pid_t tid);
static void writeHandshake(pid_t tid, int fd, handshake_container_t* handshake);
static int getKBFreeSpace(boost::interprocess::string path);
static void reserveHandshake(pid_t tid);
static shm_string genFileName(boost::interprocess::string path);

static std::unordered_map<pid_t, Buffer*> produceBuffer_;
static std::unordered_map<pid_t, int> writeBufferSize_;
static std::unordered_map<pid_t, void*> writeBuffer_;
static std::vector<boost::interprocess::string> bridgeDirs_;
static boost::interprocess::string gpid_;

void InitBufferManagerProducer(pid_t harness_pid, int num_cores)
{
    InitBufferManager(harness_pid, num_cores);

    produceBuffer_.reserve(MAX_CORES);
    writeBufferSize_.reserve(MAX_CORES);
    writeBuffer_.reserve(MAX_CORES);

    bridgeDirs_.push_back("/dev/shm/");
    bridgeDirs_.push_back("/tmp/");

    int pid = getpgrp();
    ostringstream iss;
    iss << pid;
    gpid_ = iss.str().c_str();
    assert(gpid_.length() > 0);
    cerr << " Creating temp files with prefix "  << gpid_ << "_*" << endl;
}

void DeinitBufferManagerProducer()
{
    DeinitBufferManager();

    for(int i = 0; i < (int)bridgeDirs_.size(); i++) {
        boost::interprocess::string cmd = "/bin/rm -rf " + bridgeDirs_[i] + gpid_ + "_* &";
        int retVal = system(cmd.c_str());
        (void)retVal;
        assert(retVal == 0);
    }
}

void AllocateThreadProducer(pid_t tid)
{
    int bufferCapacity = AllocateThread(tid);
{'fraction_non_alphanumeric': 0.130033341882534, 'fraction_numerical': 0.001538856116953065, 'mean_word_length': 5.25, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4990873', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1312, 'n_words': 274}