Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CMakeLists.txt
# This file is part of the EScript programming language (https://github.com/EScript)
#
# Copyright (C) 2011-2014 Claudius J�hn <ClaudiusJ@live.de>
# Copyright (C) 2011-2013 Benjamin Eikel <benjamin@eikel.org>
# Copyright (C) 2011-2014 Claudius Jähn <ClaudiusJ@live.de>
# Copyright (C) 2011-2016 Benjamin Eikel <benjamin@eikel.org>
#
# Licensed under the MIT License. See LICENSE file for details.
# ---------------------------------------------------------------------------------
Expand Down Expand Up @@ -69,11 +69,24 @@ set(ESCRIPT_SOURCES
E_Libs/MathLib.cpp
E_Libs/StdLib.cpp
)
option(BUILD_ESCRIPT_THREADING "Defines if EScript is built with threading support.")
if(BUILD_ESCRIPT_THREADING)
list(APPEND ESCRIPT_SOURCES E_Libs/ThreadingLib.cpp)
endif()
if(WIN32)
list(APPEND ESCRIPT_SOURCES E_Libs/Win32Lib.cpp)
endif()
add_library(EScript SHARED ${ESCRIPT_SOURCES})

if(BUILD_ESCRIPT_THREADING)
target_compile_definitions(EScript PRIVATE ES_THREADING)

# Dependency on pthread
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(EScript PRIVATE Threads::Threads)
endif()

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
Expand Down
4 changes: 4 additions & 0 deletions EScript/Basics.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This file is part of the EScript programming language (https://github.com/EScript)
//
// Copyright (C) 2013 Claudius Jähn <ClaudiusJ@live.de>
// Copyright (C) 2016 Benjamin Eikel <benjamin@eikel.org>
//
// Licensed under the MIT License. See LICENSE file for details.
// ---------------------------------------------------------------------------------
Expand All @@ -17,5 +18,8 @@
#include "Utils/Macros.h"
#include "Utils/StdConversions.h"
#include "Utils/StdFactories.h"
#ifdef ES_THREADING
#include "Utils/SyncTools.h"
#endif

#endif // ESCRIPT_BASICS_H
9 changes: 8 additions & 1 deletion EScript/Objects/Values/Bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ Bool * Bool::create(bool value){
#ifdef ES_DEBUG_MEMORY
return new Bool(value);
#endif
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
if(pool.empty()){
Expand All @@ -101,9 +102,11 @@ Bool * Bool::create(bool value){
return o;
}
}else{
#endif /* ES_THREADING */
return new Bool(false);
#ifdef ES_THREADING
}

#endif /* ES_THREADING */
}
void Bool::release(Bool * o){
#ifdef ES_DEBUG_MEMORY
Expand All @@ -114,12 +117,16 @@ void Bool::release(Bool * o){
delete o;
std::cout << "Found diff BoolType\n";
}else{
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
pool.push(o);
}else{
#endif /* ES_THREADING */
delete o;
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
}

Expand Down
8 changes: 8 additions & 0 deletions EScript/Objects/Values/Number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ Number * Number::create(double value){
#ifdef ES_DEBUG_MEMORY
return new Number(value);
#endif
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
if(pool.empty()){
Expand All @@ -301,8 +302,11 @@ Number * Number::create(double value){
return n;
}
}else{
#endif /* ES_THREADING */
return new Number(value);
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}

//! (static)
Expand All @@ -315,12 +319,16 @@ void Number::release(Number * n){
delete n;
std::cout << "Found diff NumberType\n";
}else{
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
pool.push(n);
}else{
#endif /* ES_THREADING */
delete n;
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
}
//----------------------------------------------------------
Expand Down
9 changes: 8 additions & 1 deletion EScript/Objects/Values/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ String * String::create(const StringData & sData){
#ifdef ES_DEBUG_MEMORY
return new String(sData);
#endif
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
if(pool.empty()){
Expand All @@ -285,8 +285,11 @@ String * String::create(const StringData & sData){
return o;
}
}else{
#endif /* ES_THREADING */
return new String(sData);
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
void String::release(String * o){
#ifdef ES_DEBUG_MEMORY
Expand All @@ -297,12 +300,16 @@ void String::release(String * o){
delete o;
std::cout << "(internal) String::release: Invalid StringType\n";
}else{
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
pool.push(o);
}else{
#endif /* ES_THREADING */
delete o;
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
}
//---
Expand Down
8 changes: 8 additions & 0 deletions EScript/Runtime/FunctionCallContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static SyncTools::FastLock poolMutex;
FunctionCallContext * FunctionCallContext::create(ERef<UserFunction> userFunction,ObjRef _caller){
FunctionCallContext * fcc = nullptr;
{
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
if(pool.empty()){
Expand All @@ -39,8 +40,11 @@ FunctionCallContext * FunctionCallContext::create(ERef<UserFunction> userFunctio
pool.pop();
}
}else{
#endif /* ES_THREADING */
fcc = new FunctionCallContext;
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
// fcc = new FunctionCallContext;
// assert(userFunction); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Expand All @@ -52,12 +56,16 @@ FunctionCallContext * FunctionCallContext::create(ERef<UserFunction> userFunctio
void FunctionCallContext::release(FunctionCallContext *fcc){
fcc->reset();
{
#ifdef ES_THREADING
auto lock = SyncTools::tryLock(poolMutex);
if(lock.owns_lock()){
pool.push(fcc);
}else{
#endif /* ES_THREADING */
delete fcc;
#ifdef ES_THREADING
}
#endif /* ES_THREADING */
}
}

Expand Down