Compare commits

..

No commits in common. "main" and "0.1.0" have entirely different histories.
main ... 0.1.0

34 changed files with 348 additions and 2243 deletions

29
.gitignore vendored
View File

@ -1 +1,28 @@
*.pyc # Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app

574
LICENSE
View File

@ -1,373 +1,201 @@
Mozilla Public License Version 2.0 Apache License
================================== Version 2.0, January 2004
http://www.apache.org/licenses/
1. Definitions
-------------- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1.1. "Contributor" 1. Definitions.
means each individual or legal entity that creates, contributes to
the creation of, or owns Covered Software. "License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
1.2. "Contributor Version"
means the combination of the Contributions of others (if any) used "Licensor" shall mean the copyright owner or entity authorized by
by a Contributor and that particular Contributor's Contribution. the copyright owner that is granting the License.
1.3. "Contribution" "Legal Entity" shall mean the union of the acting entity and all
means Covered Software of a particular Contributor. other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
1.4. "Covered Software" "control" means (i) the power, direct or indirect, to cause the
means Source Code Form to which the initial Contributor has attached direction or management of such entity, whether by contract or
the notice in Exhibit A, the Executable Form of such Source Code otherwise, or (ii) ownership of fifty percent (50%) or more of the
Form, and Modifications of such Source Code Form, in each case outstanding shares, or (iii) beneficial ownership of such entity.
including portions thereof.
"You" (or "Your") shall mean an individual or Legal Entity
1.5. "Incompatible With Secondary Licenses" exercising permissions granted by this License.
means
"Source" form shall mean the preferred form for making modifications,
(a) that the initial Contributor has attached the notice described including but not limited to software source code, documentation
in Exhibit B to the Covered Software; or source, and configuration files.
(b) that the Covered Software was made available under the terms of "Object" form shall mean any form resulting from mechanical
version 1.1 or earlier of the License, but not also under the transformation or translation of a Source form, including but
terms of a Secondary License. not limited to compiled object code, generated documentation,
and conversions to other media types.
1.6. "Executable Form"
means any form of the work other than Source Code Form. "Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
1.7. "Larger Work" copyright notice that is included in or attached to the work
means a work that combines Covered Software with other material, in (an example is provided in the Appendix below).
a separate file or files, that is not Covered Software.
"Derivative Works" shall mean any work, whether in Source or Object
1.8. "License" form, that is based on (or derived from) the Work and for which the
means this document. editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
1.9. "Licensable" of this License, Derivative Works shall not include works that remain
means having the right to grant, to the maximum extent possible, separable from, or merely link (or bind by name) to the interfaces of,
whether at the time of the initial grant or subsequently, any and the Work and Derivative Works thereof.
all of the rights conveyed by this License.
"Contribution" shall mean any work of authorship, including
1.10. "Modifications" the original version of the Work and any modifications or additions
means any of the following: to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
(a) any file in Source Code Form that results from an addition to, or by an individual or Legal Entity authorized to submit on behalf of
deletion from, or modification of the contents of Covered the copyright owner. For the purposes of this definition, "submitted"
Software; or means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
(b) any new file in Source Code Form that contains any Covered communication on electronic mailing lists, source code control systems,
Software. and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
1.11. "Patent Claims" of a Contributor excluding communication that is conspicuously marked or otherwise
means any patent claim(s), including without limitation, method, designated in writing by the copyright owner as "Not a Contribution."
process, and apparatus claims, in any patent Licensable by such
Contributor that would be infringed, but for the grant of the "Contributor" shall mean Licensor and any individual or Legal Entity
License, by the making, using, selling, offering for sale, having on behalf of whom a Contribution has been received by Licensor and
made, import, or transfer of either its Contributions or its subsequently incorporated within the Work.
Contributor Version.
2. Grant of Copyright License. Subject to the terms and conditions of
1.12. "Secondary License" this License, each Contributor hereby grants to You a perpetual,
means either the GNU General Public License, Version 2.0, the GNU worldwide, non-exclusive, no-charge, royalty-free, irrevocable
Lesser General Public License, Version 2.1, the GNU Affero General copyright license to reproduce, prepare Derivative Works of,
Public License, Version 3.0, or any later versions of those publicly display, publicly perform, sublicense, and distribute the
licenses. Work and such Derivative Works in Source or Object form.
1.13. "Source Code Form" 3. Grant of Patent License. Subject to the terms and conditions of
means the form of the work preferred for making modifications. this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
1.14. "You" (or "Your") (except as stated in this section) patent license to make, have made,
means an individual or a legal entity exercising rights under this use, offer to sell, sell, import, and otherwise transfer the Work,
License. For legal entities, "You" includes any entity that where such license applies only to those patent claims licensable
controls, is controlled by, or is under common control with You. For by such Contributor that are necessarily infringed by their
purposes of this definition, "control" means (a) the power, direct Contribution(s) alone or by combination of their Contribution(s)
or indirect, to cause the direction or management of such entity, with the Work to which such Contribution(s) was submitted. If You
whether by contract or otherwise, or (b) ownership of more than institute patent litigation against any entity (including a
fifty percent (50%) of the outstanding shares or beneficial cross-claim or counterclaim in a lawsuit) alleging that the Work
ownership of such entity. or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
2. License Grants and Conditions granted to You under this License for that Work shall terminate
-------------------------------- as of the date such litigation is filed.
2.1. Grants 4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
Each Contributor hereby grants You a world-wide, royalty-free, modifications, and in Source or Object form, provided that You
non-exclusive license: meet the following conditions:
(a) under intellectual property rights (other than patent or trademark) (a) You must give any other recipients of the Work or
Licensable by such Contributor to use, reproduce, make available, Derivative Works a copy of this License; and
modify, display, perform, distribute, and otherwise exploit its
Contributions, either on an unmodified basis, with Modifications, or (b) You must cause any modified files to carry prominent notices
as part of a Larger Work; and stating that You changed the files; and
(b) under Patent Claims of such Contributor to make, use, sell, offer (c) You must retain, in the Source form of any Derivative Works
for sale, have made, import, and otherwise transfer either its that You distribute, all copyright, patent, trademark, and
Contributions or its Contributor Version. attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
2.2. Effective Date the Derivative Works; and
The licenses granted in Section 2.1 with respect to any Contribution (d) If the Work includes a "NOTICE" text file as part of its
become effective for each Contribution on the date the Contributor first distribution, then any Derivative Works that You distribute must
distributes such Contribution. include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
2.3. Limitations on Grant Scope pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
The licenses granted in this Section 2 are the only rights granted under as part of the Derivative Works; within the Source form or
this License. No additional rights or licenses will be implied from the documentation, if provided along with the Derivative Works; or,
distribution or licensing of Covered Software under this License. within a display generated by the Derivative Works, if and
Notwithstanding Section 2.1(b) above, no patent license is granted by a wherever such third-party notices normally appear. The contents
Contributor: of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
(a) for any code that a Contributor has removed from Covered Software; notices within Derivative Works that You distribute, alongside
or or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
(b) for infringements caused by: (i) Your and any other third party's as modifying the License.
modifications of Covered Software, or (ii) the combination of its
Contributions with other software (except as part of its Contributor You may add Your own copyright statement to Your modifications and
Version); or may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
(c) under Patent Claims infringed by Covered Software in the absence of for any such Derivative Works as a whole, provided Your use,
its Contributions. reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
This License does not grant any rights in the trademarks, service marks,
or logos of any Contributor (except as may be necessary to comply with 5. Submission of Contributions. Unless You explicitly state otherwise,
the notice requirements in Section 3.4). any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
2.4. Subsequent Licenses this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
No Contributor makes additional grants as a result of Your choice to the terms of any separate license agreement you may have executed
distribute the Covered Software under a subsequent version of this with Licensor regarding such Contributions.
License (see Section 10.2) or under the terms of a Secondary License (if
permitted under the terms of Section 3.3). 6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
2.5. Representation except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
Each Contributor represents that the Contributor believes its
Contributions are its original creation(s) or it has sufficient rights 7. Disclaimer of Warranty. Unless required by applicable law or
to grant the rights to its Contributions conveyed by this License. agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
2.6. Fair Use WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
This License is not intended to limit any rights You have under of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
applicable copyright doctrines of fair use, fair dealing, or other PARTICULAR PURPOSE. You are solely responsible for determining the
equivalents. appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
2.7. Conditions
8. Limitation of Liability. In no event and under no legal theory,
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted whether in tort (including negligence), contract, or otherwise,
in Section 2.1. unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
3. Responsibilities liable to You for damages, including any direct, indirect, special,
------------------- incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
3.1. Distribution of Source Form Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
All distribution of Covered Software in Source Code Form, including any other commercial damages or losses), even if such Contributor
Modifications that You create or to which You contribute, must be under has been advised of the possibility of such damages.
the terms of this License. You must inform recipients that the Source
Code Form of the Covered Software is governed by the terms of this 9. Accepting Warranty or Additional Liability. While redistributing
License, and how they can obtain a copy of this License. You may not the Work or Derivative Works thereof, You may choose to offer,
attempt to alter or restrict the recipients' rights in the Source Code and charge a fee for, acceptance of support, warranty, indemnity,
Form. or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
3.2. Distribution of Executable Form on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
If You distribute Covered Software in Executable Form then: defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
(a) such Covered Software must also be made available in Source Code of your accepting any such warranty or additional liability.
Form, as described in Section 3.1, and You must inform recipients of
the Executable Form how they can obtain a copy of such Source Code END OF TERMS AND CONDITIONS
Form by reasonable means in a timely manner, at a charge no more
than the cost of distribution to the recipient; and APPENDIX: How to apply the Apache License to your work.
(b) You may distribute such Executable Form under the terms of this To apply the Apache License to your work, attach the following
License, or sublicense it under different terms, provided that the boilerplate notice, with the fields enclosed by brackets "{}"
license for the Executable Form does not attempt to limit or alter replaced with your own identifying information. (Don't include
the recipients' rights in the Source Code Form under this License. the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
3.3. Distribution of a Larger Work file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
You may create and distribute a Larger Work under terms of Your choice, identification within third-party archives.
provided that You also comply with the requirements of this License for
the Covered Software. If the Larger Work is a combination of Covered Copyright {yyyy} {name of copyright owner}
Software with a work governed by one or more Secondary Licenses, and the
Covered Software is not Incompatible With Secondary Licenses, this Licensed under the Apache License, Version 2.0 (the "License");
License permits You to additionally distribute such Covered Software you may not use this file except in compliance with the License.
under the terms of such Secondary License(s), so that the recipient of You may obtain a copy of the License at
the Larger Work may, at their option, further distribute the Covered
Software under the terms of either this License or such Secondary http://www.apache.org/licenses/LICENSE-2.0
License(s).
Unless required by applicable law or agreed to in writing, software
3.4. Notices distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
You may not remove or alter the substance of any license notices See the License for the specific language governing permissions and
(including copyright notices, patent notices, disclaimers of warranty, limitations under the License.
or limitations of liability) contained within the Source Code Form of
the Covered Software, except that You may alter any license notices to
the extent required to remedy known factual inaccuracies.
3.5. Application of Additional Terms
You may choose to offer, and to charge a fee for, warranty, support,
indemnity or liability obligations to one or more recipients of Covered
Software. However, You may do so only on Your own behalf, and not on
behalf of any Contributor. You must make it absolutely clear that any
such warranty, support, indemnity, or liability obligation is offered by
You alone, and You hereby agree to indemnify every Contributor for any
liability incurred by such Contributor as a result of warranty, support,
indemnity or liability terms You offer. You may include additional
disclaimers of warranty and limitations of liability specific to any
jurisdiction.
4. Inability to Comply Due to Statute or Regulation
---------------------------------------------------
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Software due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description must
be placed in a text file included with all distributions of the Covered
Software under this License. Except to the extent prohibited by statute
or regulation, such description must be sufficiently detailed for a
recipient of ordinary skill to be able to understand it.
5. Termination
--------------
5.1. The rights granted under this License will terminate automatically
if You fail to comply with any of its terms. However, if You become
compliant, then the rights granted under this License from a particular
Contributor are reinstated (a) provisionally, unless and until such
Contributor explicitly and finally terminates Your grants, and (b) on an
ongoing basis, if such Contributor fails to notify You of the
non-compliance by some reasonable means prior to 60 days after You have
come back into compliance. Moreover, Your grants from a particular
Contributor are reinstated on an ongoing basis if such Contributor
notifies You of the non-compliance by some reasonable means, this is the
first time You have received notice of non-compliance with this License
from such Contributor, and You become compliant prior to 30 days after
Your receipt of the notice.
5.2. If You initiate litigation against any entity by asserting a patent
infringement claim (excluding declaratory judgment actions,
counter-claims, and cross-claims) alleging that a Contributor Version
directly or indirectly infringes any patent, then the rights granted to
You by any and all Contributors for the Covered Software under Section
2.1 of this License shall terminate.
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
end user license agreements (excluding distributors and resellers) which
have been validly granted by You or Your distributors under this License
prior to termination shall survive termination.
************************************************************************
* *
* 6. Disclaimer of Warranty *
* ------------------------- *
* *
* Covered Software is provided under this License on an "as is" *
* basis, without warranty of any kind, either expressed, implied, or *
* statutory, including, without limitation, warranties that the *
* Covered Software is free of defects, merchantable, fit for a *
* particular purpose or non-infringing. The entire risk as to the *
* quality and performance of the Covered Software is with You. *
* Should any Covered Software prove defective in any respect, You *
* (not any Contributor) assume the cost of any necessary servicing, *
* repair, or correction. This disclaimer of warranty constitutes an *
* essential part of this License. No use of any Covered Software is *
* authorized under this License except under this disclaimer. *
* *
************************************************************************
************************************************************************
* *
* 7. Limitation of Liability *
* -------------------------- *
* *
* Under no circumstances and under no legal theory, whether tort *
* (including negligence), contract, or otherwise, shall any *
* Contributor, or anyone who distributes Covered Software as *
* permitted above, be liable to You for any direct, indirect, *
* special, incidental, or consequential damages of any character *
* including, without limitation, damages for lost profits, loss of *
* goodwill, work stoppage, computer failure or malfunction, or any *
* and all other commercial damages or losses, even if such party *
* shall have been informed of the possibility of such damages. This *
* limitation of liability shall not apply to liability for death or *
* personal injury resulting from such party's negligence to the *
* extent applicable law prohibits such limitation. Some *
* jurisdictions do not allow the exclusion or limitation of *
* incidental or consequential damages, so this exclusion and *
* limitation may not apply to You. *
* *
************************************************************************
8. Litigation
-------------
Any litigation relating to this License may be brought only in the
courts of a jurisdiction where the defendant maintains its principal
place of business and such litigation shall be governed by laws of that
jurisdiction, without reference to its conflict-of-law provisions.
Nothing in this Section shall prevent a party's ability to bring
cross-claims or counter-claims.
9. Miscellaneous
----------------
This License represents the complete agreement concerning the subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. Any law or regulation which provides
that the language of a contract shall be construed against the drafter
shall not be used to construe this License against a Contributor.
10. Versions of the License
---------------------------
10.1. New Versions
Mozilla Foundation is the license steward. Except as provided in Section
10.3, no one other than the license steward has the right to modify or
publish new versions of this License. Each version will be given a
distinguishing version number.
10.2. Effect of New Versions
You may distribute the Covered Software under the terms of the version
of the License under which You originally received the Covered Software,
or under the terms of any subsequent version published by the license
steward.
10.3. Modified Versions
If you create software not governed by this License, and you want to
create a new license for such software, you may create and use a
modified version of this License if you rename the license and remove
any references to the name of the license steward (except to note that
such modified license differs from this License).
10.4. Distributing Source Code Form that is Incompatible With Secondary
Licenses
If You choose to distribute Source Code Form that is Incompatible With
Secondary Licenses under the terms of this version of the License, the
notice described in Exhibit B of this License must be attached.
Exhibit A - Source Code Form License Notice
-------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
If it is not possible or desirable to put the notice in a particular
file, then You may include the notice in a location (such as a LICENSE
file in a relevant directory) where a recipient would be likely to look
for such a notice.
You may add additional accurate notices of copyright ownership.
Exhibit B - "Incompatible With Secondary Licenses" Notice
---------------------------------------------------------
This Source Code Form is "Incompatible With Secondary Licenses", as
defined by the Mozilla Public License, v. 2.0.

View File

@ -1 +0,0 @@
MR Edouard DUPIN <yui.heero@gmail.com>

View File

@ -1,38 +0,0 @@
Build lib & build sample {#ethread_build}
========================
@tableofcontents
Download: {#ethread_build_download}
=========
ethread use some tools to manage source and build it:
lutin (build-system): {#ethread_build_download_lutin}
---------------------
```{.sh}
pip install lutin --user
# optionnal dependency of lutin (manage image changing size for application release)
pip install pillow --user
```
sources: {#ethread_build_download_sources}
--------
```{.sh}
cd framework
git clone https://github.com/atria-soft/ethread.git
cd ..
```
Build: {#ethread_build_build}
======
library: {#ethread_build_build_library}
--------
```{.sh}
lutin -mdebug ethread
```

View File

@ -1,58 +0,0 @@
ETHREAD library {#mainpage}
===============
@tableofcontents
What is ETHREAD: {#ethread_mainpage_what}
================
ETHREAD, or Ewol thread tools (specific platform). this permit to abstaract the platform for somme tools associated with the theead like set priority or naming.
What it does: {#ethread_mainpage_what_it_does}
-------------
- Set the thread name (usefull for elog) and in the system if possible
- set the thread priority if supported by the system
What it doesn't do: {#ethread_mainpage_what_it_not_does}
-------------------
- thread management
- thread abstraction (we have std::thread for this ...)
What languages are supported? {#ethread_mainpage_language}
=============================
ETHREAD is written in C++.
Are there any licensing restrictions? {#ethread_mainpage_license_restriction}
=====================================
ETHREAD is **FREE software** and _all sub-library are FREE and staticly linkable !!!_
License (MPL v2.0) {#ethread_mainpage_license}
==================
Copyright ETHREAD Edouard DUPIN
Licensed under the Mozilla Public License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
<https://www.mozilla.org/MPL/2.0>
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Other pages {#ethread_mainpage_sub_page}
===========
- @ref ethread_build
- [**ewol coding style**](http://atria-soft.github.io/ewol/ewol_coding_style.html)

View File

@ -1,32 +0,0 @@
#!/usr/bin/python
import os
import doxy.module as module
import doxy.debug as debug
import doxy.tools as tools
def create(target, module_name):
my_module = module.Module(__file__, module_name)
my_module.set_version("version.txt")
my_module.set_title("ethread: Ewol thread platform tools")
my_module.set_website("http://atria-soft.github.io/" + module_name)
my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
my_module.add_path([
module_name,
"doc"
])
my_module.add_file_patterns([
'tools.hpp',
'*.md',
])
my_module.add_exclude_symbols([
'*operator<<*',
])
my_module.add_exclude_file([
'debug.hpp',
])
my_module.add_file_patterns([
'*.hpp',
'*.md',
])
return my_module

View File

@ -1,33 +0,0 @@
#!/usr/bin/python
import os
import doxy.module as module
import doxy.debug as debug
import doxy.tools as tools
def create(target, module_name):
my_module = module.Module(__file__, module_name)
my_module.set_version("version.txt")
my_module.set_title("ethread: Ewol thread platform tools")
my_module.set_website("http://atria-soft.github.io/" + module_name)
my_module.set_website_sources("http://github.com/atria-soft/" + module_name)
my_module.add_path([
module_name,
"doc"
])
my_module.add_file_patterns([
'*.hpp',
'*.md',
])
my_module.add_exclude_symbols([
'*operator<<*',
])
my_module.add_exclude_file([
'debug.hpp',
'tools.hpp',
])
my_module.add_file_patterns([
'*.hpp',
'*.md',
])
return my_module

View File

@ -1,40 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include "debug.hpp"
#include <ethread/Future.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Future);
ethread::Future::Future(ememory::SharedPtr<ethread::Promise> _promise):
m_promise(_promise) {
}
bool ethread::Future::isFinished() {
if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist...");
return true;
}
return m_promise->isFinished();
}
bool ethread::Future::wait(echrono::Duration _delay) {
if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist...");
return false;
}
return m_promise->wait(_delay);
}
void ethread::Future::andThen(etk::Function<void()> _action) {
if (m_promise == null) {
ETHREAD_ERROR("Promise does not exist...");
return;
}
m_promise->andThen(_action);
}

View File

@ -1,43 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ethread/Mutex.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Promise.hpp>
#include <ememory/memory.hpp>
namespace ethread {
/**
* @brief Simple future to process
*/
class Future {
private:
ememory::SharedPtr<ethread::Promise> m_promise; //!< the assiciated promise that we are waiting and of action
public:
/**
* @brief Simple Future contructor
* @param[in] _promise Associated promise to wait
*/
Future(ememory::SharedPtr<ethread::Promise> _promise=null);
/**
* @brief Check if the action is finished
* @return true, the action is done, false otherwise
*/
bool isFinished();
/**
* @brief Wait some time that the action finished
* @param[in] _delay Delay to wait the action is finished
* @return true, the action is finished, false, the time-out apear.
*/
bool wait(echrono::Duration _delay=echrono::seconds(2));
/**
* @brief Action to do when the action is finished
* @param[in] _action New action to do.
*/
void andThen(etk::Function<void()> _action);
};
}

View File

@ -1,33 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ethread/Mutex.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Mutex);
ETK_DECLARE_TYPE(ethread::UniqueLock);
ethread::Mutex::Mutex() {
InitializeCriticalSection(&m_mutex);
}
ethread::Mutex::~Mutex() {
DeleteCriticalSection(&m_mutex);
}
void ethread::Mutex::lock() {
EnterCriticalSection(&m_mutex);
}
bool ethread::Mutex::tryLock() {
return TryEnterCriticalSection(&m_mutex) != 0;
}
void ethread::Mutex::unLock() {
LeaveCriticalSection(&m_mutex);
}

View File

@ -1,94 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#ifdef __TARGET_OS__Windows
#include <windows.h>
#else
#include <pthread.h>
#endif
namespace ethread {
/**
* @brief Generic mutex interface (OS independent)
*/
class Mutex {
private:
#ifdef __TARGET_OS__Windows
CRITICAL_SECTION m_mutex;
#else
pthread_mutex_t m_mutex;
#endif
public:
/**
* @brief Create a new mutex
*/
Mutex();
/**
* @brief Destroy the mutex.
*/
~Mutex();
/**
* @brief Lock the mutex (Wait while the mutex is not lock)
*/
void lock();
/**
* @brief Try to lock the mutex (exit if mutex is already locked)
* @return true The mutex is locked
* @return false The mutex is already locked.
*/
bool tryLock();
/**
* @brief Unloc the mutex
*/
void unLock();
};
/**
* @brief AutoLock and un-lock when exit fuction.
*/
class UniqueLock {
private:
// Keep a reference on the mutex
ethread::Mutex &m_protect;
bool m_lock;
public:
/**
* @brief constructor that automaticly lock the mutex.
* @param[in] _protect Mutex to Lock.
* @param[in] _notLock Must be lock after by a tryLock.
*/
UniqueLock(ethread::Mutex& _protect, bool _notLock = false) :
m_protect(_protect),
m_lock(false) {
if (_notLock == false) {
m_protect.lock();
m_lock = true;
}
}
/**
* @brief Try to lock the mutex (exit if mutex is already locked)
* @return true The mutex is locked
* @return false The mutex is already locked.
*/
bool tryLock() {
if (m_protect.tryLock() == true) {
m_lock = true;
}
return m_lock;
}
/**
* @brief Destructor that Auto Unlock mutex when remove.
*/
virtual ~UniqueLock(){
if (m_lock == true) {
m_protect.unLock();
m_lock = false;
}
}
};
}

View File

@ -1,78 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <ethread/Mutex.hpp>
#include <ethread/tools.hpp>
extern "C" {
#include <errno.h>
}
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Mutex);
ETK_DECLARE_TYPE(ethread::UniqueLock);
//#include <ethread/debug.hpp>
ethread::Mutex::Mutex() {
// create interface mutex :
int ret = pthread_mutex_init(&m_mutex, null);
//ETHREAD_ASSERT(ret == 0, "Error creating Mutex ...");
}
ethread::Mutex::~Mutex() {
// Remove mutex
int ret = pthread_mutex_destroy(&m_mutex);
//ETHREAD_ASSERT(ret == 0, "Error destroying Mutex ...");
}
void ethread::Mutex::lock() {
pthread_mutex_lock(&m_mutex);
}
bool ethread::Mutex::tryLock() {
int ret = pthread_mutex_trylock(&m_mutex);
if (ret == 0) {
return true;
}
if (ret == EINVAL) {
printf("trylock error: EINVAL\n");
// The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's
// priority is higher than the mutex's current priority ceiling.
// The pthread_mutex_trylock() function shall fail if:
}
if (ret == EBUSY) {
printf("trylock error: EBUSY\n");
// The mutex could not be acquired because it was already locked.
// The pthread_mutex_lock(), pthread_mutex_trylock(), and pthread_mutex_unlock() functions may fail if:
}
if (ret == EINVAL) {
printf("trylock error: EINVAL\n");
// The value specified by mutex does not refer to an initialized mutex object.
}
if (ret == EAGAIN) {
printf("trylock error: EAGAIN\n");
// The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded.
// The pthread_mutex_lock() function may fail if:
}
if (ret == EDEADLK) {
printf("trylock error: EDEADLK\n");
// The current thread already owns the mutex.
// The pthread_mutex_unlock() function may fail if:
}
if (ret == EPERM) {
printf("trylock error: EPERM\n");
//The current thread does not own the mutex.
}
return false;
}
void ethread::Mutex::unLock() {
pthread_mutex_unlock(&m_mutex);
}

View File

@ -1,99 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#ifdef __TARGET_OS__Windows
#include <windows.h>
#else
#include <pthread.h>
#endif
namespace ethread {
/**
* @brief Generic mutex interface (OS independent)
*/
// TODO: Create a single class parametrable for all mutex ...
class MutexRecursive {
private:
#ifdef __TARGET_OS__Windows
CRITICAL_SECTION m_mutex;
#else
pthread_mutex_t m_mutex;
pthread_mutexattr_t m_attribute;
#endif
#ifdef DEBUG
uint32_t m_threadThatHaveLock;
#endif
public:
/**
* @brief Create a new mutex recursive
*/
MutexRecursive();
/**
* @brief Destroy the mutex.
*/
~MutexRecursive();
/**
* @brief Lock the mutex (Wait while the mutex is not lock)
*/
void lock();
/**
* @brief Try to lock the mutex (exit if mutex is already locked)
* @return true The mutex is locked
* @return false The mutex is already locked.
*/
bool tryLock();
/**
* @brief Unloc the mutex
*/
void unLock();
};
/**
* @brief AutoLock and un-lock when exit fuction.
*/
class RecursiveLock {
private:
// Keep a reference on the mutex
ethread::MutexRecursive &m_protect;
bool m_lock;
public:
/**
* @brief constructor that automaticly lock the mutex.
* @param[in] _protect Mutex to Lock.
* @param[in] _notLock Must be lock after by a tryLock.
*/
RecursiveLock(ethread::MutexRecursive& _protect, bool _notLock = false) :
m_protect(_protect),
m_lock(false) {
if (_notLock == false) {
m_protect.lock();
m_lock = true;
}
}
/**
* @brief Try to lock the mutex (exit if mutex is already locked)
* @return true The mutex is locked
* @return false The mutex is already locked.
*/
bool tryLock() {
if (m_protect.tryLock() == true) {
m_lock = true;
}
return m_lock;
}
/**
* @brief Destructor that Auto Unlock mutex when remove.
*/
virtual ~RecursiveLock(){
if (m_lock == true) {
m_protect.unLock();
m_lock = false;
}
}
};
}

View File

@ -1,89 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <ethread/MutexRecursive.hpp>
#include <ethread/tools.hpp>
extern "C" {
#include <errno.h>
}
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::MutexRecursive);
ETK_DECLARE_TYPE(ethread::RecursiveLock);
//#include <ethread/debug.hpp>
ethread::MutexRecursive::MutexRecursive() {
#ifdef DEBUG
m_threadThatHaveLock = 0xFFFFFFFF;
#endif
// create interface mutex :
pthread_mutexattr_init(&m_attribute);
pthread_mutexattr_settype(&m_attribute, PTHREAD_MUTEX_RECURSIVE);
int ret = pthread_mutex_init(&m_mutex, &m_attribute);
//ETHREAD_ASSERT(ret == 0, "Error creating Mutex ...");
}
ethread::MutexRecursive::~MutexRecursive() {
// Remove mutex
int ret = pthread_mutex_destroy(&m_mutex);
//ETHREAD_ASSERT(ret == 0, "Error destroying Mutex ...");
}
void ethread::MutexRecursive::lock() {
pthread_mutex_lock(&m_mutex);
#ifdef DEBUG
m_threadThatHaveLock = ethread::getId();
#endif
}
bool ethread::MutexRecursive::tryLock() {
int ret = pthread_mutex_trylock(&m_mutex);
if (ret == 0) {
return true;
}
if (ret == EINVAL) {
printf("trylock error: EINVAL\n");
// The mutex was created with the protocol attribute having the value PTHREAD_PRIO_PROTECT and the calling thread's
// priority is higher than the mutex's current priority ceiling.
// The pthread_mutex_trylock() function shall fail if:
}
if (ret == EBUSY) {
printf("trylock error: EBUSY\n");
// The mutex could not be acquired because it was already locked.
// The pthread_mutex_lock(), pthread_mutex_trylock(), and pthread_mutex_unlock() functions may fail if:
}
if (ret == EINVAL) {
printf("trylock error: EINVAL\n");
// The value specified by mutex does not refer to an initialized mutex object.
}
if (ret == EAGAIN) {
printf("trylock error: EAGAIN\n");
// The mutex could not be acquired because the maximum number of recursive locks for mutex has been exceeded.
// The pthread_mutex_lock() function may fail if:
}
if (ret == EDEADLK) {
printf("trylock error: EDEADLK\n");
// The current thread already owns the mutex.
// The pthread_mutex_unlock() function may fail if:
}
if (ret == EPERM) {
printf("trylock error: EPERM\n");
//The current thread does not own the mutex.
}
return false;
}
void ethread::MutexRecursive::unLock() {
pthread_mutex_unlock(&m_mutex);
#ifdef DEBUG
m_threadThatHaveLock = 0xFFFFFFFF;
#endif
}

View File

@ -1,132 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ethread/Pool.hpp>
#include <ethread/PoolExecutor.hpp>
#include "debug.hpp"
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Pool);
ethread::Pool::Pool(uint16_t _numberOfThread):
m_lastTrandId(1) {
ethread::UniqueLock lock(m_mutex);
for (uint32_t iii=0; iii<_numberOfThread; ++iii) {
ememory::SharedPtr<ethread::PoolExecutor> tmp = ememory::makeShared<ethread::PoolExecutor>(*this);
if (tmp != null) {
tmp->start();
m_listThread.pushBack(tmp);
}
}
}
ethread::Pool::~Pool() {
stop();
join();
}
uint32_t ethread::Pool::createGroupId() {
ethread::UniqueLock lock(m_mutex);
return m_lastTrandId++;
}
ethread::Future ethread::Pool::async(etk::Function<void()> _call, uint64_t _executionInGroupId) {
ethread::UniqueLock lock(m_mutex);
if (_call == null) {
ETHREAD_ERROR("Can not add an action with no function to call...");
return ethread::Future();
}
ememory::SharedPtr<ethread::Promise> promise = ememory::makeShared<ethread::Promise>();
ememory::SharedPtr<ethread::PoolAction> action = ememory::makeShared<ethread::PoolAction>(_executionInGroupId, promise, _call);
m_listActions.pushBack(action);
for(auto &it : m_listThread) {
if (it == null) {
continue;
}
if (it->touch() == true) {
// Find one to force action now ...
break;
}
}
return ethread::Future(promise);
}
void ethread::Pool::releaseId(uint64_t _id) {
if (_id == 0) {
return;
}
ethread::UniqueLock lock(m_mutex);
auto it = m_listIdPool.begin();
while (it != m_listIdPool.end()) {
if (*it == _id) {
it = m_listIdPool.erase(it);
continue;
}
++it;
}
}
// get an action to execute ...
ememory::SharedPtr<ethread::PoolAction> ethread::Pool::getAction() {
ethread::UniqueLock lock(m_mutex);
auto it = m_listActions.begin();
while (it != m_listActions.end()) {
if (*it == null) {
it = m_listActions.erase(it);
continue;
}
// Check if this element is associated at a specific pool...
uint64_t uniquId = (*it)->getPoolId();
bool alreadyUsed = false;
if (uniquId != 0) {
for (auto &itId : m_listIdPool) {
if (itId == uniquId) {
alreadyUsed = true;
break;
}
}
}
if (alreadyUsed == false) {
ememory::SharedPtr<ethread::PoolAction> out = (*it);
if (uniquId != 0) {
m_listIdPool.pushBack(uniquId);
}
it = m_listActions.erase(it);
return out;
}
++it;
}
return null;
}
void ethread::Pool::stop() {
ethread::UniqueLock lock(m_mutex);
auto it = m_listThread.begin();
while (it != m_listThread.end()) {
if (*it == null) {
it = m_listThread.erase(it);
continue;
}
(*it)->stop();
++it;
}
}
void ethread::Pool::join() {
ethread::UniqueLock lock(m_mutex);
ETHREAD_DEBUG("start join all the threads in pool " << m_listThread.size());
for (size_t iii=0; iii<m_listThread.size(); ++iii) {
ETHREAD_DEBUG(" join " << iii);
if (m_listThread[iii] == null) {
continue;
}
m_listThread[iii]->join();
}
ETHREAD_DEBUG(" ==> all joined");
m_listThread.clear();
ETHREAD_DEBUG(" ==> all reset");
}

View File

@ -1,69 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolAction.hpp>
namespace ethread {
class PoolExecutor;
/**
* @brief A pool is an association of a list of active thread that excecute some actions
*/
class Pool {
private:
ethread::Mutex m_mutex; //!< global add and release some thread
etk::Vector<ememory::SharedPtr<ethread::PoolExecutor>> m_listThread; //!< Thread pool
etk::Vector<ememory::SharedPtr<ethread::PoolAction>> m_listActions; //!< Thread pool
etk::Vector<uint64_t> m_listIdPool; //!< Thread pool
uint32_t m_lastTrandId; //!< to group the action in a single thread
public:
/**
* @brief Contructor of the threadPool
* @param[in] _numberOfThread Basic number of thread
*/
Pool(uint16_t _numberOfThread);
/**
* @brief DEstructor (virtualized)
*/
virtual ~Pool();
/**
* @brief Create a new group ID to manage a single ID
* @return A simple incremented group ID (number 0 to 10 are reserved)
*/
uint32_t createGroupId();
/**
* @brief Ad a async action to process later
* @param[in] _func Function to execure to process action
* @param[in] _executionInGroupId Group in which the process must be run
* @return A future on the action done
*/
// Execte in a group != of 0 request ordering the action in a single thread (same as a trand ...)
ethread::Future async(etk::Function<void()> _func, uint64_t _executionInGroupId=0); //!< execute an action in the thread pool...
// internal:
/**
* @brief Gan an Action to process
* @return A single action to process in a thread
*/
ememory::SharedPtr<ethread::PoolAction> getAction();
/**
* @brief Release an action id in the pool of action in progress
* @param[in] _id Id to release
*/
void releaseId(uint64_t _id);
/**
* @brief Stop all the thread and current actions
*/
void stop();
/**
* @brief Join all thread to destroy the pool
*/
void join();
};
}

View File

@ -1,34 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ethread/PoolAction.hpp>
#include "debug.hpp"
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::PoolAction);
ethread::PoolAction::PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, etk::Function<void()> _call) :
m_currentPoolId(_currentPoolId),
m_promise(_promise),
m_call(etk::move(_call)) {
}
uint64_t ethread::PoolAction::getPoolId() const {
return m_currentPoolId;
}
void ethread::PoolAction::call() {
if (m_call == null) {
return;
}
if (m_call != null) {
m_call();
}
if (m_promise != null) {
m_promise->finish();
}
}

View File

@ -1,41 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ememory/memory.hpp>
namespace ethread {
/**
* @brief A pool Action is a link between an action to do (the call) and a group of excecution (poolId) and the result store in a promise.
*/
class PoolAction {
private:
uint64_t m_currentPoolId; //!< execution group Id requested
ememory::SharedPtr<ethread::Promise> m_promise; //!< Return promise of the action
etk::Function<void()> m_call; //!< Action to do ...
public:
/**
* @brief Contuctor of a simple action
* @param[in] _currentPoolId Id Of the action might be process inside
* @param[in] _promise Promise to call when action is done
* @param[in] _call Action to do (callable object)
*/
PoolAction(uint64_t _currentPoolId, ememory::SharedPtr<ethread::Promise> _promise, etk::Function<void()> _call);
/**
* @brief Get the Pool id of the Action
* @return The pool id of this action (0 for no request)
*/
uint64_t getPoolId() const;
/**
* @brief Call the action to do (real action will be done)
*/
void call();
};
}

View File

@ -1,102 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolExecutor.hpp>
#include <ethread/tools.hpp>
#include "debug.hpp"
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::PoolExecutor);
ethread::PoolExecutor::PoolExecutor(ethread::Pool& _pool):
m_needProcess(false),
m_isWaiting(false),
m_pool(_pool),
m_running(false) {
}
void ethread::PoolExecutor::threadCallback() {
ETHREAD_DEBUG("RUN: thread in Pool [START]");
ethread::setName("pool " + etk::toString(ethread::getId()));
// get datas:
while (m_running == true) {
// get an action:
m_action = m_pool.getAction();
if (m_action == null) {
// If no action availlable and not requested to check, just sleep ...
if (m_needProcess == false) {
m_isWaiting = true;
ETHREAD_VERBOSE("RUN: Jump in sleep");
if (m_semaphore.wait(60000000) == false) {
ETHREAD_VERBOSE("RUN: time-out");
continue;
}
ETHREAD_VERBOSE("RUN: WakeUp");
m_isWaiting = false;
m_needProcess = false;
}
continue;
}
m_action->call();
m_pool.releaseId(m_action->getPoolId());
m_action.reset();
}
m_running = false;
ETHREAD_DEBUG("RUN: thread in Pool [STOP]");
}
void ethread::PoolExecutor::start() {
ETHREAD_DEBUG("START: thread in Pool [START]");
m_running = true;
m_semaphore.post();
m_thread = ememory::makeShared<ethread::Thread>([&](){ threadCallback();});
if (m_thread == null) {
m_running = false;
ETHREAD_ERROR("START: thread in Pool [STOP] can not intanciate THREAD!");
return;
}
//ethread::setPriority(*m_receiveThread, -6);
ETHREAD_DEBUG("START: thread in Pool [STOP]");
}
void ethread::PoolExecutor::stop() {
ETHREAD_DEBUG("STOP: thread in Pool [START]");
m_semaphore.post();
m_running = false;
ETHREAD_DEBUG("STOP: thread in Pool [STOP]");
}
void ethread::PoolExecutor::join() {
ETHREAD_DEBUG("JOIN: thread in Pool [START]");
m_semaphore.post();
if (m_thread != null) {
ETHREAD_DEBUG("JOIN: waiting ...");
m_thread->join();
m_thread.reset();
}
ETHREAD_DEBUG("JOIN: thread in Pool [STOP]");
}
bool ethread::PoolExecutor::touch() {
bool ret = false;
if ( m_needProcess == false
&& m_isWaiting == true) {
ETHREAD_VERBOSE("Touch ...");
m_needProcess = true;
ret = true;
m_semaphore.post();
}
return ret;
}

View File

@ -1,61 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ethread/Mutex.hpp>
#include <etk/Vector.hpp>
#include <ethread/Thread.hpp>
#include <ethread/Future.hpp>
#include <ethread/PoolAction.hpp>
#include <ethread/Pool.hpp>
#include <ethread/Mutex.hpp>
#include <ethread/Semaphore.hpp>
namespace ethread {
/**
* @brief A pool Executor is a class that execute some PoolAction. it is contituated wit a simple thread that execute some code).
*/
class PoolExecutor {
private: //section to permit to optimize CPU:
ethread::Semaphore m_semaphore; //!< protection of the internal data.
bool m_needProcess; //!< Need to do action (no need to wait condition).
bool m_isWaiting; //!< The executor is waiting to some action to do.
private:
ethread::Pool& m_pool; //!< Local reference on the Thread pool that store action to do.
ememory::SharedPtr<ethread::Thread> m_thread; //!< Local thread to process action.
bool m_running; //!< Thread is running (not stop).
ememory::SharedPtr<ethread::PoolAction> m_action; //!< Curent action that is processing.
public:
/**
* @brief Create a thread executor for the specific pool.
* @param[in] _pool Reference on the thread pool.
*/
PoolExecutor(ethread::Pool& _pool);
protected:
/**
* @brief Internal thread callback (for ethread::Thread).
*/
void threadCallback();
public:
/**
* @brief Start the current thread.
*/
void start();
/**
* @brief Stop the current thread.
*/
void stop();
/**
* @brief Join the current thread.
*/
void join();
/**
* @brief Touche the execurot to process some other data.
* @return true if the executor is waiting to process something. false otherwise.
*/
bool touch();
};
}

View File

@ -1,70 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include "debug.hpp"
#include <ethread/Future.hpp>
#include <ethread/Promise.hpp>
#include <ethread/tools.hpp>
#include <echrono/Steady.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Promise);
ethread::Promise::Promise():
m_isFinished(false) {
}
bool ethread::Promise::isFinished() {
return m_isFinished;
}
void ethread::Promise::finish() {
etk::Function<void()> callback;
{
ethread::UniqueLock lock(m_mutex);
if (m_isFinished == true) {
ETHREAD_ERROR("Request 2 time finishing a Promise ...");
return;
}
m_isFinished = true;
if (m_callback != null) {
// call callbacks ...
callback = etk::move(m_callback);
}
}
if (callback != null) {
callback();
}
}
bool ethread::Promise::wait(echrono::Duration _delay) {
echrono::Steady time = echrono::Steady::now();
while (_delay >= 0) {
{
ethread::UniqueLock lock(m_mutex);
if (m_isFinished == true) {
return true;
}
}
echrono::Steady time2 = echrono::Steady::now();
_delay -= (time2-time);
time = time2;
if (_delay >= 0) {
// TODO : This is really bad ==> fast to code and debug but not optimum at all ... use condition instead ...
ethread::sleepMilliSeconds((10));
}
}
return false;
}
void ethread::Promise::andThen(etk::Function<void()> _action) {
ethread::UniqueLock lock(m_mutex);
m_callback = etk::move(_action);
if (m_isFinished == true) {
m_callback();
}
}

View File

@ -1,48 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <ethread/Mutex.hpp>
#include <ethread/Thread.hpp>
#include <etk/Function.hpp>
#include <echrono/Duration.hpp>
namespace ethread {
/**
* @brief A promise of the specific ation to do in the thread pool
*/
class Promise {
private:
ethread::Mutex m_mutex; //!< Simple lock of the interface
etk::Function<void()> m_callback; //!< callback to call when processing is ended
bool m_isFinished; //!< The process of the action has been done
public:
/**
* @brief Simple empty contructor
*/
Promise();
/**
* @brief Call this when the action has been done
*/
void finish();
/**
* @brief Check if the action is finished
* @return true, the action is done, false otherwise
*/
bool isFinished();
/**
* @brief Wait some time that the action finished
* @param[in] _delay Delay to wait the action is finished
* @return true, the action is finished, false, the time-out apear.
*/
bool wait(echrono::Duration _delay=echrono::seconds(2));
/**
* @brief Action to do when the action is finished
* @param[in] _action New action to do.
*/
void andThen(etk::Function<void()> _action);
};
}

View File

@ -1,48 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <etk/os/Semaphore.hpp>
#include <etk/debug.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Semaphore);
etk::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
// create interface mutex :
m_semaphore = CreateSemaphore(null, _nbBasicElement, _nbMessageMax, null);
TK_ASSERT(m_semaphore != 0, "Error creating SEMAPHORE ...");
}
etk::Semaphore::~Semaphore() {
CloseHandle(m_semaphore);
}
uint32_t etk::Semaphore::getCount() {
LONG tmpData = 0;
ReleaseSemaphore(m_semaphore, 0, &tmpData);
return tmpData;
}
void etk::Semaphore::post() {
ReleaseSemaphore(m_semaphore, 1, null);
}
void etk::Semaphore::wait() {
WaitForSingleObject(m_semaphore, INFINITE);
}
bool etk::Semaphore::wait(uint64_t _timeOutInUs) {
DWORD result = WaitForSingleObject(m_semaphore, _timeOutInUs);
if (result == WAIT_FAILED) {
TK_ERROR("Failed to wait for semaphore ");
return false;
} else {
return result == WAIT_OBJECT_0;
}
}

View File

@ -1,63 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#ifdef __TARGET_OS__Windows
#include <windows.h>
#else
#include <pthread.h>
#endif
namespace ethread {
/**
* @brief Generic semaphore wrapper ( it is os independent)
*/
class Semaphore {
private:
#ifdef __TARGET_OS__Windows
HANDLE m_semaphore;
#else
pthread_mutex_t m_mutex;
pthread_cond_t m_condition;
uint32_t m_data;
uint32_t m_maximum;
#endif
public:
/**
* @brief Contruct the inithialized semaphore.
* @param[in] _nbBasicElement Number of element basicly set in the semaphore list
* @param[in] _nbMessageMax Nunber of maximun message that can be set.
*/
Semaphore(uint32_t _nbBasicElement=0, uint32_t _nbMessageMax=1);
/**
* @brief Generic destructor.
*/
~Semaphore();
/**
* @brief Get the number of element in the semaphore.
* @return Number of stored elements.
*/
uint32_t getCount();
/**
* @brief Post a new semaphore
*/
void post();
/**
* @brief Wait for a new semaphore post by an other thread.
*/
void wait();
/**
* @brief Wait for a new semaphore post by an other thread,
* with a timeout in micro-second.
* @param[in] _timeOutInUs Number of micro-second to wait a semaphore.
* @return true The function get a semaphore.
* @return false The time-out appear or an error occured.
*/
bool wait(uint64_t _timeOutInUs);
};
}

View File

@ -1,89 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <etk/types.hpp>
#include <ethread/Semaphore.hpp>
//#include <ethread/debug.hpp>
#include <sys/time.h>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Semaphore);
ethread::Semaphore::Semaphore(uint32_t _nbBasicElement, uint32_t _nbMessageMax) {
// create interface mutex :
int ret = pthread_mutex_init(&m_mutex, null);
//TK_ASSERT(ret == 0, "Error creating Mutex ...");
// create contition :
ret = pthread_cond_init(&m_condition, null);
//TK_ASSERT(ret == 0, "Error creating Condition ...");
if (ret != 0) {
ret = pthread_mutex_destroy(&m_mutex);
//TK_ASSERT(ret == 0, "Error destroying Mutex ...");
}
m_maximum = _nbMessageMax;
m_data = _nbBasicElement;
}
ethread::Semaphore::~Semaphore() {
// Remove condition
int ret = pthread_cond_destroy(&m_condition);
//TK_ASSERT(ret == 0, "Error destroying Condition ...");
// Remove Mutex
ret = pthread_mutex_destroy(&m_mutex);
//TK_ASSERT(ret == 0, "Error destroying Mutex ...");
}
uint32_t ethread::Semaphore::getCount() {
int32_t tmpData = 0;
pthread_mutex_lock(&m_mutex);
tmpData = m_data;
pthread_mutex_unlock(&m_mutex);
return tmpData;
}
void ethread::Semaphore::post() {
pthread_mutex_lock(&m_mutex);
if (m_data>=m_maximum) {
m_data = m_maximum;
} else {
m_data++;
}
// send message
pthread_cond_broadcast(&m_condition);
pthread_mutex_unlock(&m_mutex);
}
void ethread::Semaphore::wait() {
pthread_mutex_lock(&m_mutex);
while(m_data == 0) {
pthread_cond_wait(&m_condition, &m_mutex);
}
m_data--;
pthread_mutex_unlock(&m_mutex);
}
bool ethread::Semaphore::wait(uint64_t _timeOutInUs) {
pthread_mutex_lock(&m_mutex);
if(m_data == 0) {
struct timeval tp;
struct timespec ts;
gettimeofday(&tp, null);
uint64_t totalTimeUS = tp.tv_sec * 1000000 + tp.tv_usec;
totalTimeUS += _timeOutInUs;
ts.tv_sec = totalTimeUS / 1000000;
ts.tv_nsec = (totalTimeUS%1000000) * 1000;
int ret = pthread_cond_timedwait(&m_condition, &m_mutex, &ts);
if (ret !=0) { //== ETIMEOUT) {
pthread_mutex_unlock(&m_mutex);
return false;
}
}
m_data--;
pthread_mutex_unlock(&m_mutex);
return true;
}

View File

@ -1,52 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <etk/types.hpp>
#include <etk/Function.hpp>
#include <etk/String.hpp>
#ifdef __TARGET_OS__Windows
#error TODO ...
#else
extern "C" {
#include <pthread.h>
}
#endif
namespace ethread {
/**
* @brief Generic Thread interface (OS independent)
*/
class Thread {
private:
#ifdef __TARGET_OS__Windows
#else
pthread_t m_thread;
static void* threadCallback(void* _userData);
#endif
uint64_t m_uid; //!< unique id of the thread
etk::String m_name; //!< Name of the thread (do not get it on the system ==> more portable)
etk::Function<void()> m_function; //!< Function to call every cycle of the thead running
public:
Thread(etk::Function<void()>&& _call, const etk::String& _name = "");
~Thread();
void join();
bool detach();
void threadCall();
void setName(const etk::String& _name);
const etk::String& getName() const;
uint64_t getId() const;
#ifdef __TARGET_OS__Windows
#else
pthread_t getNativeHandle() {
return m_thread;
}
#endif
};
}

View File

@ -1,71 +0,0 @@
/**
* @author Edouard DUPIN
* @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include <ethread/Thread.hpp>
#include <ethread/tools.hpp>
#include <etk/typeInfo.hpp>
ETK_DECLARE_TYPE(ethread::Thread);
namespace ethread {
uint32_t getThreadHumanId(uint64_t _id);
etk::String getThreadName(uint64_t _id);
void setThreadName(ethread::Thread* _thread, const etk::String& _name);
}
void* ethread::Thread::threadCallback(void* _userData) {
ethread::Thread* threadHandle = static_cast<ethread::Thread*>(_userData);
if (threadHandle != null) {
threadHandle->threadCall();
}
return null;
}
ethread::Thread::Thread(etk::Function<void()>&& _call, const etk::String& _name):
m_thread(0),
m_uid(-1),
m_name(_name),
m_function(etk::move(_call)) {
uint32_t iii = ethread::getId();
pthread_create(&m_thread, null, &ethread::Thread::threadCallback, this);
m_uid = ethread::getThreadHumanId(uint64_t(m_thread));
printf("New thread: %ld from %d\n", m_uid, iii);
}
ethread::Thread::~Thread() {
}
void ethread::Thread::join() {
void* ret = null;
int val = pthread_join(m_thread, &ret);
}
bool ethread::Thread::detach() {
return true;
}
void ethread::Thread::setName(const etk::String& _name) {
m_name = _name;
ethread::setThreadName(this, m_name);
}
const etk::String& ethread::Thread::getName() const {
return m_name;
}
void ethread::Thread::threadCall() {
if (m_function != null) {
m_function();
}
}
uint64_t ethread::Thread::getId() const {
return m_uid;
}

View File

@ -1,12 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#include "debug.hpp"
int32_t ethread::getLogId() {
static int32_t g_val = elog::registerInstance("ethread");
return g_val;
}

View File

@ -1,40 +0,0 @@
/** @file
* @author Edouard DUPIN
* @copyright 2014, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file)
*/
#pragma once
#include <elog/log.hpp>
namespace ethread {
int32_t getLogId();
};
#define ETHREAD_BASE(info,data) ELOG_BASE(ethread::getLogId(),info,data)
#define ETHREAD_PRINT(data) ETHREAD_BASE(-1, data)
#define ETHREAD_CRITICAL(data) ETHREAD_BASE(1, data)
#define ETHREAD_ERROR(data) ETHREAD_BASE(2, data)
#define ETHREAD_WARNING(data) ETHREAD_BASE(3, data)
#ifdef DEBUG
#define ETHREAD_INFO(data) ETHREAD_BASE(4, data)
#define ETHREAD_DEBUG(data) ETHREAD_BASE(5, data)
#define ETHREAD_VERBOSE(data) ETHREAD_BASE(6, data)
#define ETHREAD_TODO(data) ETHREAD_BASE(4, "TODO : " << data)
#else
#define ETHREAD_INFO(data) do { } while(false)
#define ETHREAD_DEBUG(data) do { } while(false)
#define ETHREAD_VERBOSE(data) do { } while(false)
#define ETHREAD_TODO(data) do { } while(false)
#endif
#define ETHREAD_ASSERT(cond,data) \
do { \
if (!(cond)) { \
ETHREAD_CRITICAL(data); \
assert(!#cond); \
} \
} while (0)

View File

@ -1,123 +1,110 @@
/** /**
* @author Edouard DUPIN * @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved * @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) *
* @license APACHE v2.0 (see license file)
*/ */
#include <ethread/tools.hpp> #include <ethread/tools.h>
#include <etk/Pair.hpp> #include <mutex>
#include <ethread/Mutex.hpp> #include <map>
// TODO: set mutex back ...
#include <etk/Map.hpp> static std::mutex g_lock;
extern "C" { static std::map<uint32_t, std::string>& getThreadList() {
#include <unistd.h> static std::map<uint32_t, std::string> g_val;
}
#ifdef __TARGET_OS__Windows
#error TODO ...
#else
extern "C" {
#include <pthread.h>
}
#endif
static ethread::Mutex g_lock;
static etk::Map<uint64_t, etk::String>& getThreadList() {
static etk::Map<uint64_t, etk::String> g_val;
return g_val; return g_val;
} }
namespace ethread {
// Note: Declared in Thread.cpp
uint32_t getThreadHumanId(uint64_t _id) {
uint32_t out = 0;
g_lock.lock();
static etk::Map<uint64_t, uint32_t> g_list;
auto it = g_list.find(_id);
if (it == g_list.end()) {
// attribute new ID :
static uint32_t tmpId = 0;
g_list.set(_id, tmpId);
out = tmpId;
tmpId++;
} else {
out = it.getValue();
}
g_lock.unLock();
return out;
}
etk::String getThreadName(uint64_t _id) { static uint32_t getThreadHumanId(std::thread::id _id) {
etk::Map<uint64_t,etk::String>& list = getThreadList(); uint32_t out = 0;
uint32_t threadID = getThreadHumanId(_id); uint64_t iddd = std::hash<std::thread::id>()(_id);
etk::String out; g_lock.lock();
g_lock.lock(); static std::map<uint64_t, uint32_t> g_list;
auto it = list.find(threadID); std::map<uint64_t, uint32_t>::iterator it = g_list.find(iddd);
if (it != list.end()) { if (it == g_list.end()) {
out = it.getValue(); // attribute new ID :
} static uint32_t tmpId = 0;
g_lock.unLock(); g_list.insert(std::pair<uint64_t, uint32_t>(iddd,tmpId));
return out; out = tmpId;
tmpId++;
} else {
out = it->second;
} }
g_lock.unlock();
return out;
void setThreadName(ethread::Thread* _thread, const etk::String& _name) {
etk::Map<uint64_t,etk::String>& list = getThreadList();
uint32_t threadID = ethread::getId();
g_lock.lock();
list.set(threadID, _name);
g_lock.unLock();
// try now to set the thread name with Pthread
#if ( defined(__TARGET_OS__Linux) \
|| defined(__TARGET_OS__Android) \
) \
&& !defined(__TARGET_OS__Web)
pthread_t pthreadID;
if (_thread == null) {
pthreadID = pthread_self();
} else {
pthreadID = _thread->getNativeHandle();
}
etk::String name = _name;
if (name.size() > 15) {
name.resize(15);
}
if (pthread_setname_np(pthreadID, name.c_str()) < 0) {
//TODO: TK_ERROR("Error when setting the Name in the OS thread naming");
}
#else
//TODO: TK_INFO("Can not set the thread name in this OS (local set)");
#endif
}
} }
static std::string getThreadName(std::thread::id _id) {
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = getThreadHumanId(_id);
std::string out;
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it != list.end()) {
out = it->second;
}
g_lock.unlock();
return out;
}
static void setThreadName(std::thread* _thread, const std::string& _name) {
std::map<uint32_t,std::string>& list = getThreadList();
uint32_t threadID = ethread::getId();
g_lock.lock();
std::map<uint32_t,std::string>::iterator it = list.find(threadID);
if (it == list.end()) {
list.insert(std::pair<uint32_t, std::string>(threadID, _name));
} else {
it->second = _name;
}
g_lock.unlock();
// try now to set the thread name with Pthread
#if defined(__TARGET_OS__Linux)
pthread_t pthreadID;
if (_thread == nullptr) {
pthreadID = pthread_self();
} else {
pthreadID = (pthread_t) _thread->native_handle();
}
std::string name = _name;
if (name.size() > 15) {
name.resize(15);
}
if (pthread_setname_np(pthreadID, name.c_str()) < 0) {
//TODO: TK_ERROR("Error when setting the Name in the OS thread naming");
}
#else
//TODO: TK_INFO("Can not set the thread name in this OS (local set)");
#endif
}
uint32_t ethread::getId() { uint32_t ethread::getId() {
pthread_t self; return getThreadHumanId(std::this_thread::get_id());
self = pthread_self();
return ethread::getThreadHumanId(uint64_t(self));
} }
uint32_t ethread::getId(ethread::Thread& _thread) { uint32_t ethread::getId(std::thread& _thread) {
return ethread::getThreadHumanId(_thread.getId()); return getThreadHumanId(_thread.get_id());
} }
void ethread::setName(const etk::String& _name) { void ethread::setName(const std::string& _name) {
setThreadName(null, _name); setThreadName(nullptr, _name);
} }
void ethread::setName(ethread::Thread& _thread, const etk::String& _name) { void ethread::setName(std::thread& _thread, const std::string& _name) {
_thread.setName(_name); setThreadName(&_thread, _name);
} }
etk::String ethread::getName() { std::string ethread::getName() {
pthread_t self; return getThreadName(std::this_thread::get_id());
self = pthread_self();
return getThreadName(uint64_t(self));
} }
etk::String ethread::getName(ethread::Thread& _thread) { std::string ethread::getName(std::thread& _thread) {
return _thread.getName(); return getThreadName(_thread.get_id());
} }
#if defined(__TARGET_OS__Linux) \ #if defined(__TARGET_OS__Linux)
&& !defined(__TARGET_OS__Web)
static void setThreadPriority(pthread_t _threadID, int32_t _priority) { static void setThreadPriority(pthread_t _threadID, int32_t _priority) {
int retcode; int retcode;
int policy; int policy;
@ -156,30 +143,26 @@ etk::String ethread::getName(ethread::Thread& _thread) {
return -param.sched_priority; return -param.sched_priority;
} }
return param.sched_priority; return param.sched_priority;
return 0;
} }
#endif #endif
void ethread::setPriority(int32_t _priority) { void ethread::setPriority(int32_t _priority) {
#if defined(__TARGET_OS__Linux) \ #if defined(__TARGET_OS__Linux)
&& !defined(__TARGET_OS__Web)
pthread_t threadID = pthread_self(); pthread_t threadID = pthread_self();
setThreadPriority(threadID, _priority); setThreadPriority(threadID, _priority);
#endif #endif
} }
void ethread::setPriority(ethread::Thread& _thread, int32_t _priority) { void ethread::setPriority(std::thread& _thread, int32_t _priority) {
#if defined(__TARGET_OS__Linux) \ #if defined(__TARGET_OS__Linux)
&& !defined(__TARGET_OS__Web) pthread_t threadID = (pthread_t) _thread.native_handle();
pthread_t threadID = _thread.getNativeHandle();
setThreadPriority(threadID, _priority); setThreadPriority(threadID, _priority);
#endif #endif
} }
int32_t ethread::getPriority() { int32_t ethread::getPriority() {
#if defined(__TARGET_OS__Linux) \ #if defined(__TARGET_OS__Linux)
&& !defined(__TARGET_OS__Web)
pthread_t threadID = pthread_self(); pthread_t threadID = pthread_self();
return getThreadPriority(threadID); return getThreadPriority(threadID);
#else #else
@ -187,66 +170,11 @@ int32_t ethread::getPriority() {
#endif #endif
} }
int32_t ethread::getPriority(ethread::Thread& _thread) { int32_t ethread::getPriority(std::thread& _thread) {
#if defined(__TARGET_OS__Linux) \ #if defined(__TARGET_OS__Linux)
&& !defined(__TARGET_OS__Web) pthread_t threadID = static_cast<pthread_t>(_thread.native_handle());
pthread_t threadID = _thread.getNativeHandle();
return getThreadPriority(threadID); return getThreadPriority(threadID);
#else #else
return 20; return 20;
#endif #endif
} }
//static ethread::Mutex g_localMutex;
static etk::Map<uint32_t, etk::Map<etk::String, uint64_t>> g_listMetaData;
void ethread::metadataSet(const etk::String& _key, uint64_t _value) {
/*
uint32_t currentThreadId = ethread::getId();
// TODO: ethread::UniqueLock lock(g_localMutex);
auto it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
it.getValue().set(_key, _value);
} else {
etk::Map<etk::String, uint64_t> tmp;
tmp.set(_key, _value);
g_listMetaData.set(currentThreadId, tmp);
}
*/
}
void ethread::metadataRemove(const etk::String& _key) {
/*
uint32_t currentThreadId = ethread::getId();
// TODO: ethread::UniqueLock lock(g_localMutex);
etk::Map<uint32_t, etk::Map<etk::String, uint64_t>>::Iterator it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
auto it2 = it.getValue().find(_key);
if (it2 != it.getValue().end()) {
it.getValue().erase(it2);
}
}
*/
}
uint64_t ethread::metadataGetU64(const etk::String& _key) {
/*
uint32_t currentThreadId = ethread::getId();
// TODO: ethread::UniqueLock lock(g_localMutex);
auto it = g_listMetaData.find(currentThreadId);
if (it != g_listMetaData.end()) {
auto it2 = it.getValue().find(_key);
if (it2 != it.getValue().end()) {
return it2.getValue();
}
}
*/
return 0;
}
void ethread::sleepMilliSeconds(uint32_t _timeInMilliSeconds) {
usleep(_timeInMilliSeconds*1000);
}

View File

@ -1,50 +1,48 @@
/** /**
* @author Edouard DUPIN * @author Edouard DUPIN
*
* @copyright 2011, Edouard DUPIN, all right reserved * @copyright 2011, Edouard DUPIN, all right reserved
* @license MPL v2.0 (see license file) *
* @license APACHE v2.0 (see license file)
*/ */
#pragma once #pragma once
#include <ethread/Thread.hpp> #include <thread>
#include <etk/String.hpp>
/**
* @brief ethread main namespace
*/
namespace ethread { namespace ethread {
/** /**
* @brief get human readable thread ID. (not the ethread::Thread::getId()) * @brief get human readable thread ID. (not the std::thread::get_id())
* @return the ID of the thread. * @return the ID of the thread.
*/ */
uint32_t getId(); uint32_t getId();
/** /**
* @brief get human readable thread ID. (not the ethread::Thread::getId()) * @brief get human readable thread ID. (not the std::thread::get_id())
* @param[in] _thread Thread handle * @param[in] _thread Thread handle
* @return the ID of the thread. * @return the ID of the thread.
*/ */
uint32_t getId(ethread::Thread& _thread); uint32_t getId(std::thread& _thread);
/** /**
* @brief Set the Current thread name * @brief Set the Current thread name
* @param[in] _name New name of the thread * @param[in] _name New name of the thread
*/ */
void setName(const etk::String& _name); void setName(const std::string& _name);
/** /**
* @brief Set an other thread name * @brief Set an other thread name
* @param[in] _thread Thread handle * @param[in] _thread Thread handle
* @param[in] _name New name of the thread * @param[in] _name New name of the thread
*/ */
void setName(ethread::Thread& _thread, const etk::String& _name); void setName(std::thread& _thread, const std::string& _name);
/** /**
* @brief Set the Current thread name * @brief Set the Current thread name
* @return The current name of the thread * @return The current name of the thread
*/ */
etk::String getName(); std::string getName();
/** /**
* @brief Get an other thread name * @brief Get an other thread name
* @param[in] _thread Thread handle * @praram[in] _thread Thread handle
* @return The external thread name of the thread * @return The external thread name of the thread
*/ */
etk::String getName(ethread::Thread& _thread); std::string getName(std::thread& _thread);
/** /**
* @brief Set the Current thread priority [-20..0] for RT and ]0..50] for normal priority * @brief Set the Current thread priority [-20..0] for RT and ]0..50] for normal priority
* @param[in] _priority New priority of the thread * @param[in] _priority New priority of the thread
@ -57,7 +55,7 @@ namespace ethread {
* @param[in] _priority New priority of the thread * @param[in] _priority New priority of the thread
* @note If your process have not the right to change thread name, it does not work * @note If your process have not the right to change thread name, it does not work
*/ */
void setPriority(ethread::Thread& _thread, int32_t _priority); void setPriority(std::thread& _thread, int32_t _priority);
/** /**
* @brief get the Current thread priority [-20..0] for RT and ]0..50] for normal priority * @brief get the Current thread priority [-20..0] for RT and ]0..50] for normal priority
* @return current priority of the thread * @return current priority of the thread
@ -68,24 +66,5 @@ namespace ethread {
* @param[in] _thread Thread handle * @param[in] _thread Thread handle
* @return current priority of the thread * @return current priority of the thread
*/ */
int32_t getPriority(ethread::Thread& _thread); int32_t getPriority(std::thread& _thread);
/**
* @brief Set an information with a key on the current thread
* @param[in] _key key to store the value
* @param[in] _value Value to store
*/
void metadataSet(const etk::String& _key, uint64_t _value);
/**
* @brief Remove the information with a key on the current thread
* @param[in] _key key to remove
*/
void metadataRemove(const etk::String& _key);
/**
* @brief get the information with a key on the current thread
* @param[in] _key key to store the value
* @return the uint 64 value to stored
*/
uint64_t metadataGetU64(const etk::String& _key);
void sleepMilliSeconds(uint32_t _timeInMilliSeconds);
} }

View File

@ -1,74 +0,0 @@
#!/usr/bin/python
import realog.debug as debug
import lutin.tools as tools
def get_type():
return "LIBRARY"
def get_desc():
return "Ewol thread tools"
def get_licence():
return "MPL-2"
def get_compagny_type():
return "com"
def get_compagny_name():
return "atria-soft"
def get_maintainer():
return "authors.txt"
def get_version():
return "version.txt"
def configure(target, my_module):
my_module.add_extra_flags()
# add the file to compile:
my_module.add_src_file([
'ethread/tools.cpp',
])
my_module.add_header_file([
'ethread/tools.hpp',
'ethread/Thread.hpp',
'ethread/Mutex.hpp',
'ethread/MutexRecursive.hpp',
'ethread/Semaphore.hpp',
])
if "Windows" in target.get_type():
my_module.add_src_file([
'ethread/Mutex.Windows.cpp',
'ethread/MutexRecursive.Windows.cpp',
'ethread/Thread.Windows.cpp',
'ethread/Semaphore.Windows.cpp',
])
else:
my_module.add_src_file([
'ethread/Mutex.pthread.cpp',
'ethread/MutexRecursive.pthread.cpp',
'ethread/Thread.pthread.cpp',
'ethread/Semaphore.pthread.cpp',
])
my_module.add_depend([
'pthread',
])
# build in C++ mode
my_module.compile_version("c++", 2011)
# add dependency of the generic C++ library:
my_module.add_depend([
'etk-core',
])
#pthread is not availlable on Windows
if "Linux" in target.get_type() \
or "Android" in target.get_type():
my_module.add_depend([
'pthread'
])
return True

View File

@ -1,5 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import realog.debug as debug import lutin.module as module
import lutin.tools as tools import lutin.tools as tools
@ -7,10 +7,10 @@ def get_type():
return "LIBRARY" return "LIBRARY"
def get_desc(): def get_desc():
return "Ewol thread" return "Ewol thread tools"
def get_licence(): def get_licence():
return "MPL-2" return "APACHE-2"
def get_compagny_type(): def get_compagny_type():
return "com" return "com"
@ -19,41 +19,29 @@ def get_compagny_name():
return "atria-soft" return "atria-soft"
def get_maintainer(): def get_maintainer():
return "authors.txt" return ["Mr DUPIN Edouard <yui.heero@gmail.com>"]
def get_version(): def get_version():
return "version.txt" return [0,1,"dev"]
def configure(target, my_module): def create(target, module_name):
my_module.add_extra_flags() my_module = module.Module(__file__, module_name, get_type())
my_module.add_extra_compile_flags()
# add the file to compile: # add the file to compile:
my_module.add_src_file([ my_module.add_src_file([
'ethread/debug.cpp', 'ethread/tools.cpp',
'ethread/Future.cpp', ])
'ethread/Promise.cpp',
'ethread/Pool.cpp',
'ethread/PoolAction.cpp',
'ethread/PoolExecutor.cpp',
])
my_module.add_header_file([ my_module.add_header_file([
'ethread/Future.hpp', 'ethread/tools.h',
'ethread/Promise.hpp', ])
'ethread/Pool.hpp',
'ethread/PoolAction.hpp',
'ethread/PoolExecutor.hpp',
])
# build in C++ mode # build in C++ mode
my_module.compile_version("c++", 2011) my_module.compile_version("c++", 2011)
# add dependency of the generic C++ library: # add dependency of the generic C++ library:
my_module.add_depend([ my_module.add_module_depend('cxx')
'elog',
'etk', my_module.add_path(tools.get_current_path(__file__))
'ethread-tools', return my_module
'echrono',
'ememory'
])
return True

View File

@ -1 +0,0 @@
1.0.0