
15 changed files with 186 additions and 48 deletions
@ -1,49 +1,72 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
|
|
||||
import sys |
# This file is under GNU Affero General Public License 3.0 |
||||
import os |
# see LICENSE.txt |
||||
from distutils.core import setup, Extension |
|
||||
|
|
||||
|
from setuptools import setup, Extension |
||||
from glob import glob |
from glob import glob |
||||
from distutils.errors import DistutilsOptionError |
from os import environ, uname |
||||
|
from os.path import dirname, exists, join |
||||
def option_value(name): |
from sys import argv |
||||
for index, option in enumerate(sys.argv): |
|
||||
if option == '--' + name: |
|
||||
if index+1 >= len(sys.argv): |
compile_args = ['-O0', '-g', '-UNDEBUG', '-std=c++14'] \ |
||||
raise DistutilsOptionError( |
if '--debug' in argv or '-g' in argv else ['-std=c++14'] |
||||
'The option %s requires a value' % option) |
|
||||
value = sys.argv[index+1] |
|
||||
sys.argv[index:index+2] = [] |
def find(file, pathlist): |
||||
return value |
for path in pathlist: |
||||
if option.startswith('--' + name + '='): |
_file = join(path, file) |
||||
value = option[len(name)+3:] |
if exists(_file): |
||||
sys.argv[index:index+1] = [] |
return dirname(_file) |
||||
return value |
raise FileNotFoundError(file) |
||||
env_val = os.getenv(name.upper().replace('-', '_')) |
|
||||
return env_val |
|
||||
|
includes = [ |
||||
OPTION_PREFIX = option_value("prefix") |
join(environ['HOME'], 'include'), |
||||
OPTION_BOOST = option_value("boost") |
'/usr/include', |
||||
|
'/usr/local/include', |
||||
if OPTION_PREFIX is None : |
'/opt/local/include', |
||||
OPTION_PREFIX = os.environ["HOME"] |
join(environ['HOME'], 'share'), |
||||
|
'/usr/share', |
||||
if OPTION_BOOST is None : |
'/usr/local/share', |
||||
OPTION_BOOST = '/opt/local' |
'/opt/local/share', |
||||
|
] |
||||
|
|
||||
|
|
||||
|
libraries = [ |
||||
|
join(environ['HOME'], 'lib'), |
||||
|
'/usr/lib', |
||||
|
'/usr/local/lib', |
||||
|
'/opt/local/lib', |
||||
|
] |
||||
|
|
||||
|
|
||||
|
libext = '.dylib' if uname().sysname == 'Darwin' else '.so' |
||||
|
|
||||
|
|
||||
|
search_for_includes = 'pEp', 'boost', 'asn1c/asn_system.h' |
||||
|
search_for_libraries = 'libpEpengine' + libext, 'libboost_python3-mt' + libext |
||||
|
|
||||
|
|
||||
module_pEp = Extension('pEp', |
module_pEp = Extension('pEp', |
||||
sources = glob('src/*.cc'), |
sources = glob('src/*.cc'), |
||||
include_dirs = [OPTION_PREFIX+'/include', OPTION_BOOST+'/include',], |
|
||||
library_dirs = [OPTION_PREFIX+'/lib', OPTION_BOOST+'/lib',], |
|
||||
libraries = ['pEpEngine', 'boost_python3-mt', 'boost_locale-mt',], |
libraries = ['pEpEngine', 'boost_python3-mt', 'boost_locale-mt',], |
||||
extra_compile_args = ['-O0', '-UNDEBUG', '-std=c++14',], |
extra_compile_args = compile_args, |
||||
|
include_dirs = set( [ find(file, includes) for file in |
||||
|
search_for_includes ] ), |
||||
|
library_dirs = set( [ find(file, libraries) for file in |
||||
|
search_for_libraries ] ), |
||||
) |
) |
||||
|
|
||||
|
|
||||
setup( |
setup( |
||||
name='p≡p Python adapter', |
name='p≡p Python adapter', |
||||
version='1.0', |
version='2.0', |
||||
description='Provides a Python module giving access to p≡p engine', |
description='Provides a Python module giving access to p≡p engine', |
||||
author="Volker Birk", |
author="Volker Birk", |
||||
author_email="vb@pep-project.org", |
author_email="vb@pep-project.org", |
||||
ext_modules=[module_pEp] |
ext_modules=[module_pEp,], |
||||
) |
) |
||||
|
|
||||
|
@ -0,0 +1,61 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include <list> |
||||
|
#include <mutex> |
||||
|
|
||||
|
namespace utility |
||||
|
{ |
||||
|
using namespace std; |
||||
|
|
||||
|
template<class T> class locked_queue |
||||
|
{ |
||||
|
mutex _mtx; |
||||
|
list<T> _q; |
||||
|
|
||||
|
public: |
||||
|
T& back() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
return _q.back(); |
||||
|
} |
||||
|
T& front() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
return _q.front(); |
||||
|
} |
||||
|
T pop_back() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
T r = _q.back(); |
||||
|
_q.pop_back(); |
||||
|
return r; |
||||
|
} |
||||
|
T pop_front() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
T r = _q.front(); |
||||
|
_q.pop_front(); |
||||
|
return r; |
||||
|
} |
||||
|
void push_back(const T& data) |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
_q.push_back(data); |
||||
|
} |
||||
|
void push_front(const T& data) |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
_q.push_front(data); |
||||
|
} |
||||
|
size_t size() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
return _q.size(); |
||||
|
} |
||||
|
bool empty() |
||||
|
{ |
||||
|
lock_guard<mutex> lg(_mtx); |
||||
|
return _q.empty(); |
||||
|
} |
||||
|
}; |
||||
|
}; |
Loading…
Reference in new issue