Mac OSX Launcher:

* Fixed issue with >> and compilers in C++ in subprocess.hpp
  * Added queue for logger
  * Misc
This commit is contained in:
meeh
2018-09-30 09:32:49 +00:00
parent e8d371ed9b
commit b40b987c0f
4 changed files with 86 additions and 6 deletions

View File

@@ -8,7 +8,7 @@
using callbackType = void (CFFileDescriptorRef, CFOptionFlags, void *);
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;
int fd = CFFileDescriptorGetNativeDescriptor(fdref);
kevent(fd, NULL, 0, &kev, 1, NULL);

View 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__

View File

@@ -10,6 +10,8 @@
#include <locale>
#include "optional.h"
#import <Foundation/NSString.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreFoundation/CFArray.h>
#include <CoreFoundation/CFString.h>
@@ -98,6 +100,15 @@ static inline std::string trim_copy(std::string 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

View File

@@ -34,6 +34,8 @@ Documentation for C++ subprocessing libraray.
#ifndef SUBPROCESS_HPP
#define SUBPROCESS_HPP
#ifdef __cplusplus
#include <map>
#include <algorithm>
#include <iostream>
@@ -1627,4 +1629,6 @@ OutBuffer pipeline(Args&&... args)
};
#endif // __cplusplus
#endif // SUBPROCESS_HPP