Add hardware_threads() function (#111)
* Add hardware_threads() function
This commit is contained in:
parent
d189d67349
commit
c5d94ec465
@ -37,6 +37,7 @@ Requires C++14 compiler compliance. Tested with GCC 4.9+, clang 3.8 and Visual S
|
|||||||
* [effil.thread_id()](#id--effilthread_id)
|
* [effil.thread_id()](#id--effilthread_id)
|
||||||
* [effil.yield()](#effilyield)
|
* [effil.yield()](#effilyield)
|
||||||
* [effil.sleep()](#effilsleeptime-metric)
|
* [effil.sleep()](#effilsleeptime-metric)
|
||||||
|
* [effil.hardware_threads()](#id--effilhardware_threads)
|
||||||
* [Table](#table)
|
* [Table](#table)
|
||||||
* [effil.table()](#table--effiltabletbl)
|
* [effil.table()](#table--effiltabletbl)
|
||||||
* [__newindex: table[key] = value](#tablekey--value)
|
* [__newindex: table[key] = value](#tablekey--value)
|
||||||
@ -306,6 +307,11 @@ Suspend current thread.
|
|||||||
|
|
||||||
**input**: [time metrics](#time-metrics) arguments.
|
**input**: [time metrics](#time-metrics) arguments.
|
||||||
|
|
||||||
|
### `effil.hardware_threads()`
|
||||||
|
Returns the number of concurrent threads supported by implementation.
|
||||||
|
Basically forwards value from [std::thread::hardware_concurrency](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency).
|
||||||
|
**output**: number of concurrent hardware threads.
|
||||||
|
|
||||||
## Table
|
## Table
|
||||||
`effil.table` is a way to exchange data between effil threads. It behaves almost like standard lua tables.
|
`effil.table` is a way to exchange data between effil threads. It behaves almost like standard lua tables.
|
||||||
All operations with shared table are thread safe. **Shared table stores** primitive types (number, boolean, string), function, table, light userdata and effil based userdata. **Shared table doesn't store** lua threads (coroutines) or arbitrary userdata. See examples of shared table usage [here](#examples)
|
All operations with shared table are thread safe. **Shared table stores** primitive types (number, boolean, string), function, table, light userdata and effil based userdata. **Shared table doesn't store** lua threads (coroutines) or arbitrary userdata. See examples of shared table usage [here](#examples)
|
||||||
|
|||||||
@ -108,6 +108,7 @@ int luaopen_effil(lua_State* L) {
|
|||||||
"ipairs", SharedTable::globalLuaIPairs,
|
"ipairs", SharedTable::globalLuaIPairs,
|
||||||
"size", luaSize,
|
"size", luaSize,
|
||||||
"allow_table_upvalues", luaAllowTableUpvalues,
|
"allow_table_upvalues", luaAllowTableUpvalues,
|
||||||
|
"hardware_threads", std::thread::hardware_concurrency,
|
||||||
sol::meta_function::index, luaIndex
|
sol::meta_function::index, luaIndex
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,10 @@ local effil = effil
|
|||||||
|
|
||||||
test.thread.tear_down = default_tear_down
|
test.thread.tear_down = default_tear_down
|
||||||
|
|
||||||
|
test.thread.hardware_threads = function()
|
||||||
|
test.is_true(effil.hardware_threads() >= 0)
|
||||||
|
end
|
||||||
|
|
||||||
test.thread.wait = function ()
|
test.thread.wait = function ()
|
||||||
local thread = effil.thread(function()
|
local thread = effil.thread(function()
|
||||||
print 'Effil is not that tower'
|
print 'Effil is not that tower'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user