CoolFace
Modelpublic

Felipe97/llama-cpp-compiled

sourceHugging Faceupdated 3d agoView on Hugging Face
0likes1.1kdownloads
subproc.h60 linesDownload Raw Back to common
1#pragma once2 3#include <atomic>4#include <cstdio>5#include <string>6#include <vector>7 8#ifdef LLAMA_SUBPROCESS9#include <sheredom/subprocess.h>10#else11// dummy values to allow compilation when subprocess is disabled12struct subprocess_s {};13static constexpr int subprocess_option_no_window = 0;14static constexpr int subprocess_option_combined_stdout_stderr = 0;15static constexpr int subprocess_option_inherit_environment = 0;16static constexpr int subprocess_option_search_user_path = 0;17#endif18 19// RAII-style wrapper around https://github.com/sheredom/subprocess.h,20// exposing method calls instead of free functions operating on subprocess_s.21struct common_subproc {22    common_subproc() = default;23    ~common_subproc();24 25    common_subproc(const common_subproc &) = delete;26    common_subproc & operator=(const common_subproc &) = delete;27 28    // spawn a child process; if env is non-empty it replaces the child's environment29    // (do not combine with subprocess_option_inherit_environment)30    bool create(31            const std::vector<std::string> & args,32            int options,33            const std::vector<std::string> & env = {},34            const char * cwd = nullptr);35 36    bool alive();37 38    // true if LLAMA_SUBPROCESS was enabled at build time; when false, create() always fails39    static bool is_supported();40 41    FILE * stdin_file();42    FILE * stdout_file();43    FILE * stderr_file();44 45    // close stdin and detach it from the process, so a later join()/destroy() won't double-close it;46    // use this after writing all input to signal EOF to the child while it's still running47    void close_stdin();48 49    void terminate();50 51    // wait for the process to exit, release the underlying handle and return its exit code52    int join();53 54private:55    subprocess_s proc {};56    std::atomic<bool> is_created{false};57 58    bool has_handle() const;59};60