diff --git a/.clang-format b/.clang-format deleted file mode 100644 index 23f0d05..0000000 --- a/.clang-format +++ /dev/null @@ -1,89 +0,0 @@ ---- -Language: Cpp -# BasedOnStyle: LLVM -AccessModifierOffset: -4 -AlignAfterOpenBracket: Align -AlignConsecutiveAssignments: false -AlignConsecutiveDeclarations: false -AlignEscapedNewlinesLeft: false -AlignOperands: false -AlignTrailingComments: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: false -AllowShortCaseLabelsOnASingleLine: false -AllowShortFunctionsOnASingleLine: All -AllowShortIfStatementsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -AlwaysBreakAfterDefinitionReturnType: None -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: false -AlwaysBreakTemplateDeclarations: true -BinPackArguments: true -BinPackParameters: true -BraceWrapping: - AfterClass: false - AfterControlStatement: false - AfterEnum: false - AfterFunction: false - AfterNamespace: false - AfterObjCDeclaration: false - AfterStruct: false - AfterUnion: false - BeforeCatch: false - BeforeElse: false - IndentBraces: false -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Attach -BreakBeforeTernaryOperators: true -BreakConstructorInitializersBeforeComma: true -ColumnLimit: 120 -ConstructorInitializerAllOnOneLineOrOnePerLine: false -ConstructorInitializerIndentWidth: 8 -ContinuationIndentWidth: 4 -Cpp11BracedListStyle: true -DerivePointerAlignment: false -DisableFormat: false -ExperimentalAutoDetectBinPacking: false -ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: - - Regex: '^"(llvm|llvm-c|clang|clang-c)/' - Priority: 2 - - Regex: '^(<|"(gtest|isl|json)/)' - Priority: 3 - - Regex: '.*' - Priority: 1 -IndentCaseLabels: true -IndentWidth: 4 -IndentWrappedFunctionNames: false -KeepEmptyLinesAtTheStartOfBlocks: true -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 1 -NamespaceIndentation: None -ObjCBlockIndentWidth: 2 -ObjCSpaceAfterProperty: false -ObjCSpaceBeforeProtocolList: true -PenaltyBreakBeforeFirstCallParameter: 19 -PenaltyBreakComment: 300 -PenaltyBreakFirstLessLess: 120 -PenaltyBreakString: 1000 -PenaltyExcessCharacter: 1000000 -PenaltyReturnTypeOnItsOwnLine: 60 -PointerAlignment: Left -ReflowComments: true -SortIncludes: false -SpaceAfterCStyleCast: false -SpaceBeforeAssignmentOperators: true -SpaceBeforeParens: ControlStatements -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 1 -SpacesInAngles: false -SpacesInContainerLiterals: true -SpacesInCStyleCastParentheses: false -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Cpp11 -TabWidth: 4 -UseTab: Never -... - diff --git a/.gitignore b/.gitignore index 02d83f2..ed4da74 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea .work_dir build -*.user \ No newline at end of file +*.user +cmake-* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 7296607..2ff9da6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,9 +4,6 @@ [submodule "libs/gtest"] path = libs/gtest url = https://github.com/google/googletest.git -[submodule "libs/luaunit"] - path = libs/luaunit - url = https://github.com/bluebird75/luaunit [submodule "libs/u-test"] path = libs/u-test url = https://github.com/IUdalov/u-test.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ec937e..191d5a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,9 +13,6 @@ FILE(GLOB LUA_SOURCES src/lua/*.lua) if(APPLE) # Supress warning CMP0042 set(CMAKE_MACOSX_RPATH 1) - set(LIBRARY_EXT dylib) -else() - set(LIBRARY_EXT so) endif() add_library(effil SHARED ${SOURCES}) @@ -38,13 +35,6 @@ include_directories(${GTEST_DIR}/include ${GTEST_DIR}) add_executable(tests ${TEST_SOURCES} ${GTEST_DIR}/src/gtest-all.cc) target_link_libraries(tests effil ${LUA_LIBRARY}) -#---------- -# FORMAT - -#---------- -add_custom_target( format - COMMAND clang-format -i ${TEST_SOURCES} ${SOURCES} -) - #---------- # INSTALL - #---------- diff --git a/README.md b/README.md index 8f4028e..1272fa6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,5 @@ # Effil [![Build Status](https://travis-ci.org/loud-hound/effil.svg?branch=master)](https://travis-ci.org/loud-hound/effil) -[![Build Status Windows](https://ci.appveyor.com/api/projects/status/us6uh4e5q597jj54?svg=true)](https://ci.appveyor.com/project/loud-hound/effil/branch/master) -[![Documentation Status](https://readthedocs.org/projects/effil/badge/?version=latest)](http://effil.readthedocs.io/en/latest/?badge=latest) Effil is a lua module for multithreading support. It allows to spawn native threads and safe data exchange. diff --git a/ci/test_all.bat b/ci/test_all.bat deleted file mode 100644 index e69de29..0000000 diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index 109cf6b..0000000 --- a/docs/index.md +++ /dev/null @@ -1,2 +0,0 @@ -# Effil -Threading library for Lua. Written in C++ with great help of [sol2](https://github.com/ThePhD/sol2). diff --git a/libs/luaunit b/libs/luaunit deleted file mode 160000 index d2f1ffa..0000000 --- a/libs/luaunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit d2f1ffa86582d51b77dc29b1f7216e75fe2bc6d0 diff --git a/src/cpp/channel.cpp b/src/cpp/channel.cpp index 0302619..19334a6 100644 --- a/src/cpp/channel.cpp +++ b/src/cpp/channel.cpp @@ -7,7 +7,8 @@ namespace effil { void Channel::getUserType(sol::state_view& lua) { sol::usertype type("new", sol::no_constructor, "push", &Channel::push, - "pop", &Channel::pop + "pop", &Channel::pop, + "size", &Channel::size ); sol::stack::push(lua, type); sol::stack::pop(lua); @@ -65,4 +66,9 @@ StoredArray Channel::pop(const sol::optional& duration, return ret; } +size_t Channel::size() { + std::lock_guard lock(data_->lock_); + return data_->channel_.size(); +} + } // namespace effil diff --git a/src/cpp/channel.h b/src/cpp/channel.h index cfa3a67..4ac7c3d 100644 --- a/src/cpp/channel.h +++ b/src/cpp/channel.h @@ -16,6 +16,7 @@ public: StoredArray pop(const sol::optional& duration, const sol::optional& period); + size_t size(); protected: struct SharedData { std::mutex lock_; diff --git a/src/cpp/lua-module.cpp b/src/cpp/lua-module.cpp index 754905a..9e5f5b1 100644 --- a/src/cpp/lua-module.cpp +++ b/src/cpp/lua-module.cpp @@ -62,11 +62,10 @@ extern "C" int luaopen_libeffil(lua_State* L) { "table", createTable, "rawset", SharedTable::luaRawSet, "rawget", SharedTable::luaRawGet, - "size", SharedTable::luaSize, + "table_size", SharedTable::luaSize, "setmetatable", SharedTable::luaSetMetatable, "getmetatable", SharedTable::luaGetMetatable, "G", sol::make_object(lua, globalTable), - "getmetatable", SharedTable::luaGetMetatable, "gc", GC::getLuaApi(lua), "channel", createChannel, "userdata_type", userdataType diff --git a/src/lua/effil.lua b/src/lua/effil.lua index 6135301..583a499 100644 --- a/src/lua/effil.lua +++ b/src/lua/effil.lua @@ -17,7 +17,6 @@ local api = { thread_id = capi.thread_id, sleep = capi.sleep, yield = capi.yield, - size = capi.size, rawget = capi.rawget, rawset = capi.rawset, setmetatable = capi.setmetatable, @@ -36,6 +35,17 @@ api.type = function (something) end end +api.size = function (something) + local t = api.type(something) + if t == "effil.table" then + return capi.table_size(something) + elseif t == "effil.channel" then + return something:size() + else + error("Unsupported type " .. t .. " for effil.size()") + end +end + local function run_thread(config, f, ...) return capi.thread(config.path, config.cpath, config.step, f, ...) end diff --git a/tests/lua/channel.lua b/tests/lua/channel.lua index 431b2ad..96b6981 100644 --- a/tests/lua/channel.lua +++ b/tests/lua/channel.lua @@ -7,11 +7,14 @@ test.channel.capacity_usage = function() test.is_true(chan:push(14)) test.is_true(chan:push(88)) + test.equal(chan:size(), 2) + test.is_false(chan:push(1488)) test.equal(chan:pop(), 14) test.equal(chan:pop(), 88) test.is_nil(chan:pop(0)) + test.equal(chan:size(), 0) test.is_true(chan:push(14, 88), true) local ret1, ret2 = chan:pop() diff --git a/tests/lua/size.lua b/tests/lua/size.lua new file mode 100644 index 0000000..107dd8f --- /dev/null +++ b/tests/lua/size.lua @@ -0,0 +1,14 @@ +require "bootstrap-tests" + +test.size = function() + local st = effil.table() + st[0] = 1 + st[1] = 0 + + local chan = effil.channel() + chan:push(0) + chan:push(2) + + test.equal(effil.size(st), 2) + test.equal(effil.size(chan), 2) +end