forked from I2P_Developers/i2p.i2p
Mac OSX Launcher:
* Fixed issue with >> and compilers in C++ in subprocess.hpp * Added queue for logger * Misc
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
using callbackType = void (CFFileDescriptorRef, CFOptionFlags, void *);
|
using callbackType = void (CFFileDescriptorRef, CFOptionFlags, void *);
|
||||||
using HandleFunction = std::function<void(int)>;
|
using HandleFunction = std::function<void(int)>;
|
||||||
|
|
||||||
static void noteProcDeath(CFFileDescriptorRef fdref, CFOptionFlags callBackTypes, void *info) {
|
static inline void noteProcDeath(CFFileDescriptorRef fdref, CFOptionFlags callBackTypes, void *info) {
|
||||||
struct kevent kev;
|
struct kevent kev;
|
||||||
int fd = CFFileDescriptorGetNativeDescriptor(fdref);
|
int fd = CFFileDescriptorGetNativeDescriptor(fdref);
|
||||||
kevent(fd, NULL, 0, &kev, 1, NULL);
|
kevent(fd, NULL, 0, &kev, 1, NULL);
|
||||||
|
65
launchers/macosx/include/sharedqueue.h
Normal file
65
launchers/macosx/include/sharedqueue.h
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#ifndef SHAREDQUEUE_H__
|
||||||
|
#define SHAREDQUEUE_H__
|
||||||
|
|
||||||
|
#include <queue>
|
||||||
|
#include <mutex>
|
||||||
|
#include <exception>
|
||||||
|
#include <condition_variable>
|
||||||
|
|
||||||
|
/** Multiple producer, multiple consumer thread safe queue
|
||||||
|
* Since 'return by reference' is used this queue won't throw */
|
||||||
|
template<typename T>
|
||||||
|
class shared_queue
|
||||||
|
{
|
||||||
|
std::queue<T> queue_;
|
||||||
|
mutable std::mutex m_;
|
||||||
|
std::condition_variable data_cond_;
|
||||||
|
|
||||||
|
shared_queue& operator=(const shared_queue&);
|
||||||
|
shared_queue(const shared_queue& other);
|
||||||
|
|
||||||
|
public:
|
||||||
|
shared_queue(){}
|
||||||
|
|
||||||
|
void push(T item){
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(m_);
|
||||||
|
queue_.push(item);
|
||||||
|
}
|
||||||
|
data_cond_.notify_one();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// \return immediately, with true if successful retrieval
|
||||||
|
bool try_and_pop(T& popped_item){
|
||||||
|
std::lock_guard<std::mutex> lock(m_);
|
||||||
|
if(queue_.empty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
popped_item=std::move(queue_.front());
|
||||||
|
queue_.pop();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Try to retrieve, if no items, wait till an item is available and try again
|
||||||
|
void wait_and_pop(T& popped_item){
|
||||||
|
std::unique_lock<std::mutex> lock(m_); // note: unique_lock is needed for std::condition_variable::wait
|
||||||
|
while(queue_.empty())
|
||||||
|
{ // The 'while' loop below is equal to
|
||||||
|
data_cond_.wait(lock); //data_cond_.wait(lock, [](bool result){return !queue_.empty();});
|
||||||
|
}
|
||||||
|
popped_item=std::move(queue_.front());
|
||||||
|
queue_.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool empty() const{
|
||||||
|
std::lock_guard<std::mutex> lock(m_);
|
||||||
|
return queue_.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned size() const{
|
||||||
|
std::lock_guard<std::mutex> lock(m_);
|
||||||
|
return queue_.size();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // SHAREDQUEUE_H__
|
@@ -10,6 +10,8 @@
|
|||||||
#include <locale>
|
#include <locale>
|
||||||
#include "optional.h"
|
#include "optional.h"
|
||||||
|
|
||||||
|
#import <Foundation/NSString.h>
|
||||||
|
|
||||||
#include <CoreFoundation/CoreFoundation.h>
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
#include <CoreFoundation/CFArray.h>
|
#include <CoreFoundation/CFArray.h>
|
||||||
#include <CoreFoundation/CFString.h>
|
#include <CoreFoundation/CFString.h>
|
||||||
@@ -98,6 +100,15 @@ static inline std::string trim_copy(std::string s) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSString* stdStringToNSString(std::string &stdstr) {
|
||||||
|
return [NSString stringWithUTF8String:stdstr.c_str()];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string nsStringToStd(NSString* nsStr) {
|
||||||
|
const char *charlist = [nsStr UTF8String];
|
||||||
|
return std::string(charlist);
|
||||||
|
}
|
||||||
|
|
||||||
#if __cplusplus > 201402L
|
#if __cplusplus > 201402L
|
||||||
|
|
||||||
|
|
||||||
|
@@ -34,6 +34,8 @@ Documentation for C++ subprocessing libraray.
|
|||||||
#ifndef SUBPROCESS_HPP
|
#ifndef SUBPROCESS_HPP
|
||||||
#define SUBPROCESS_HPP
|
#define SUBPROCESS_HPP
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -697,19 +699,19 @@ template <typename... T> struct param_pack{};
|
|||||||
template <typename F, typename T> struct has_type;
|
template <typename F, typename T> struct has_type;
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
struct has_type<F, param_pack<>> {
|
struct has_type<F, param_pack<> > {
|
||||||
static constexpr bool value = false;
|
static constexpr bool value = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename F, typename... T>
|
template <typename F, typename... T>
|
||||||
struct has_type<F, param_pack<F, T...>> {
|
struct has_type<F, param_pack<F, T...> > {
|
||||||
static constexpr bool value = true;
|
static constexpr bool value = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename F, typename H, typename... T>
|
template <typename F, typename H, typename... T>
|
||||||
struct has_type<F, param_pack<H,T...>> {
|
struct has_type<F, param_pack<H,T...> > {
|
||||||
static constexpr bool value =
|
static constexpr bool value =
|
||||||
std::is_same<F, typename std::decay<H>::type>::value ? true : has_type<F, param_pack<T...>>::value;
|
std::is_same<F, typename std::decay<H>::type>::value ? true : has_type<F, param_pack<T...> >::value;
|
||||||
};
|
};
|
||||||
|
|
||||||
//----
|
//----
|
||||||
@@ -1528,7 +1530,7 @@ namespace detail
|
|||||||
template<typename F, typename... Args>
|
template<typename F, typename... Args>
|
||||||
OutBuffer check_output_impl(F& farg, Args&&... args)
|
OutBuffer check_output_impl(F& farg, Args&&... args)
|
||||||
{
|
{
|
||||||
static_assert(!detail::has_type<output, detail::param_pack<Args...>>::value, "output not allowed in args");
|
static_assert(!detail::has_type<output, detail::param_pack<Args...> >::value, "output not allowed in args");
|
||||||
auto p = Popen(std::forward<F>(farg), std::forward<Args>(args)..., output{PIPE});
|
auto p = Popen(std::forward<F>(farg), std::forward<Args>(args)..., output{PIPE});
|
||||||
auto res = p.communicate();
|
auto res = p.communicate();
|
||||||
auto retcode = p.poll();
|
auto retcode = p.poll();
|
||||||
@@ -1627,4 +1629,6 @@ OutBuffer pipeline(Args&&... args)
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // __cplusplus
|
||||||
|
|
||||||
#endif // SUBPROCESS_HPP
|
#endif // SUBPROCESS_HPP
|
||||||
|
Reference in New Issue
Block a user