Ejemplo n.º 1
0
void ValueLatch<T>::set(T&& value)
{
    std::unique_lock<std::mutex> lock(mMutex);
    if (mValue) {
        throw UtilsException("Cannot set value multiple times");
    }
    mValue.reset(new T(std::move(value)));
    mCondition.notify_one();
}
Ejemplo n.º 2
0
std::string get_home_directory() throw (UtilsException) {
#ifdef __unix__
    struct passwd *pw;
    pw = getpwuid(geteuid());
    if (!pw) {
        throw UtilsException("Function getpwuid() failed.");
    }

    return std::string(pw->pw_dir);
#elif _WIN32
    char path[MAX_PATH];
    if (!(SHGetFolderPathA(NULL, CSIDL_PROFILE, NULL, 0, path) == S_OK)) {
        throw UtilsException("Function SHGetFolderPathA() failed.");
    }

    return std::string(path);
#endif
}
Ejemplo n.º 3
0
T ValueLatch<T>::get(const unsigned int timeoutMs)
{
    std::unique_lock<std::mutex> lock(mMutex);
    if (mCondition.wait_for(lock, std::chrono::milliseconds(timeoutMs), [this]() {
                                return (bool)mValue;
                            }) ) {
        std::unique_ptr<T> retValue(std::move(mValue));
        return T(std::move(*retValue));
    } else {
        throw UtilsException("Timeout occured");
    }
}
Ejemplo n.º 4
0
void create_directory(const std::string& directory, const std::string& in) throw (UtilsException) {
    std::string dir;

    dir = in + dir_separator + directory;
#ifdef __unix__
    int rv = mkdir(dir.c_str(), S_IRWXU);
    if (rv && errno != EEXIST) {
        throw UtilsException(strerror(errno));
    }
#elif _WIN32
    CreateDirectoryA(dir.c_str(), 0);
#endif
}