-
Notifications
You must be signed in to change notification settings - Fork 95
Feature/769 libuv package and thread header #815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pnoltes
wants to merge
8
commits into
master
Choose a base branch
from
feature/769-libuv-package-and-thread-header
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+396
−4
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2127aeb
gh-769: Add libuv dep, update ci workflows and add smoke test
pnoltes e2d3cee
gh-769: Add celix_uv_cleanup.h
pnoltes 1b0b093
gh-769: Update conan libuv dep to build_utils
pnoltes e0af030
Exclude try locks on macos rwlock test
pnoltes feb9d8e
Remove libuv linkng from ei tests
pnoltes 23a3408
gh-769: Move trylock test for rwlock to in sep thread
pnoltes 5ef11d9
gh-769: Move trylock test for mutex to a sep thread
pnoltes 9f46175
gh-769: Refactor celix_uv_cleanup func and struct naming
pnoltes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache 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 | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-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. | ||
|
|
||
| # - Try to find libuv | ||
| # Once done this will define | ||
| # libuv_FOUND - System has libuv | ||
| # LIBUV_INCLUDE_DIR - The libuv include directory | ||
| # LIBUV_LIBRARY - The libuv library | ||
| # uv - Imported target for libuv | ||
|
|
||
| find_package(libuv CONFIG QUIET) | ||
|
|
||
| if (NOT libuv_FOUND) | ||
| find_package(PkgConfig QUIET) | ||
| if (PkgConfig_FOUND) | ||
| pkg_check_modules(LIBUV QUIET libuv) | ||
| endif () | ||
| endif () | ||
|
|
||
| if (NOT libuv_FOUND) | ||
| find_path(LIBUV_INCLUDE_DIR | ||
| NAMES uv.h | ||
| HINTS ${LIBUV_INCLUDEDIR} ${LIBUV_INCLUDE_DIRS} | ||
| ) | ||
|
|
||
| find_library(LIBUV_LIBRARY | ||
| NAMES uv libuv | ||
| HINTS ${LIBUV_LIBDIR} ${LIBUV_LIBRARY_DIRS} | ||
| ) | ||
|
|
||
| include(FindPackageHandleStandardArgs) | ||
| find_package_handle_standard_args(libuv DEFAULT_MSG LIBUV_LIBRARY LIBUV_INCLUDE_DIR) | ||
| mark_as_advanced(LIBUV_INCLUDE_DIR LIBUV_LIBRARY) | ||
| endif () | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| if (libuv_FOUND AND NOT TARGET libuv::uv AND TARGET libuv::libuv) | ||
| #Note: libuv cmake config possible defines libuv::libuv target | ||
| # and conan libuv package defines uv target | ||
| # so create an alias target uv for consistency | ||
| add_library(libuv::uv ALIAS libuv::libuv) | ||
| elseif (libuv_FOUND AND NOT TARGET libuv::uv AND LIBUV_LIBRARY AND LIBUV_INCLUDE_DIR) | ||
| add_library(libuv::uv SHARED IMPORTED) | ||
| set_target_properties(libuv::uv PROPERTIES | ||
| IMPORTED_LOCATION "${LIBUV_LIBRARY}" | ||
| INTERFACE_INCLUDE_DIRECTORIES "${LIBUV_INCLUDE_DIR}" | ||
| ) | ||
| endif () | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,13 @@ | |
| celix_subproject(UTILS "Option to enable building the Utilities library" ON) | ||
| if (UTILS) | ||
| find_package(libzip REQUIRED) | ||
| find_package(jansson REQUIRED) #TODO add jansson dep info to build (conan) and documentation info | ||
| find_package(jansson REQUIRED) | ||
| find_package(libuv REQUIRED) | ||
|
|
||
| if (NOT TARGET libuv::uv AND TARGET uv) | ||
| #Note: conan libuv package 1.49.2 defines uv target, but 1.51.0 defines libuv::uv target | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using latest conan 1.x is OK, thus this hack can be removed. |
||
| add_library(libuv::uv ALIAS uv) | ||
| endif () | ||
|
|
||
| set(MEMSTREAM_SOURCES ) | ||
| set(MEMSTREAM_INCLUDES ) | ||
|
|
@@ -46,7 +52,7 @@ if (UTILS) | |
| ${MEMSTREAM_SOURCES} | ||
| ) | ||
| set(UTILS_PRIVATE_DEPS libzip::zip jansson::jansson) | ||
| set(UTILS_PUBLIC_DEPS) | ||
| set(UTILS_PUBLIC_DEPS libuv::uv) | ||
|
|
||
| add_library(utils SHARED ${UTILS_SRC}) | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache 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 | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-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. | ||
|
|
||
| #include "celix_uv_cleanup.h" | ||
|
|
||
| #include <atomic> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| class UvThreadsTestSuite : public ::testing::Test { | ||
| }; | ||
|
|
||
| static void uvThreadIncrement(void* data) { | ||
| auto* counter = static_cast<std::atomic<int>*>(data); | ||
| counter->fetch_add(1); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, ThreadAutoCleanupTest) { | ||
| std::atomic<int> counter{0}; | ||
| { | ||
| celix_auto(uv_thread_t) thread; | ||
| ASSERT_EQ(0, uv_thread_create(&thread, uvThreadIncrement, &counter)); | ||
| } //thread out of scope -> join | ||
| EXPECT_EQ(1, counter.load()); | ||
| } | ||
|
|
||
| static void uvThreadTryLockForMutex(void* data) { | ||
| auto* mutex = static_cast<uv_mutex_t*>(data); | ||
| EXPECT_NE(0, uv_mutex_trylock(mutex)); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, MutexGuardTest) { | ||
| uv_mutex_t mutex; | ||
| ASSERT_EQ(0, uv_mutex_init(&mutex)); | ||
| celix_autoptr(uv_mutex_t) mutexCleanup = &mutex; | ||
|
|
||
| { | ||
| celix_auto(celix_uv_mutex_lock_guard_t) guard = celix_uvMutexLockGuard_init(&mutex); | ||
| uv_thread_t thread; | ||
| ASSERT_EQ(0, uv_thread_create(&thread, uvThreadTryLockForMutex, &mutex)); | ||
| EXPECT_EQ(0, uv_thread_join(&thread)); | ||
| } //guard out of scope -> unlock | ||
|
|
||
| ASSERT_EQ(0, uv_mutex_trylock(&mutex)); | ||
| uv_mutex_unlock(&mutex); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, MutexStealTest) { | ||
| uv_mutex_t mutex; | ||
| ASSERT_EQ(0, uv_mutex_init(&mutex)); | ||
| celix_autoptr(uv_mutex_t) mutexCleanup = &mutex; | ||
| celix_steal_ptr(mutexCleanup); | ||
| uv_mutex_destroy(&mutex); | ||
| } | ||
|
|
||
| static void uvThreadTryLocksForWriteLock(void* data) { | ||
| auto* lock = static_cast<uv_rwlock_t*>(data); | ||
| EXPECT_NE(0, uv_rwlock_tryrdlock(lock)); | ||
| EXPECT_NE(0, uv_rwlock_trywrlock(lock)); | ||
| } | ||
|
|
||
| static void uvThreadTryLocksForReadLock(void* data) { | ||
| auto* lock = static_cast<uv_rwlock_t*>(data); | ||
| EXPECT_NE(0, uv_rwlock_trywrlock(lock)); | ||
| EXPECT_EQ(0, uv_rwlock_tryrdlock(lock)); //additional read lock on read lock should succeed | ||
| uv_rwlock_rdunlock(lock); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, RwlockGuardTest) { | ||
| uv_rwlock_t lock; | ||
| ASSERT_EQ(0, uv_rwlock_init(&lock)); | ||
| celix_autoptr(uv_rwlock_t) lockCleanup = &lock; | ||
|
|
||
| { | ||
| celix_auto(celix_uv_write_lock_guard_t) writeGuard = celix_uvWriteLockGuard_init(&lock); | ||
| uv_thread_t thread; | ||
| ASSERT_EQ(0, uv_thread_create(&thread, uvThreadTryLocksForWriteLock, &lock)); | ||
| EXPECT_EQ(0, uv_thread_join(&thread)); | ||
| } //guard out of scope -> unlock write lock | ||
|
|
||
| { | ||
| celix_auto(celix_uv_read_lock_guard_t) readGuard = celix_uvReadLockGuard_init(&lock); | ||
| uv_thread_t thread; | ||
| ASSERT_EQ(0, uv_thread_create(&thread, uvThreadTryLocksForReadLock, &lock)); | ||
| EXPECT_EQ(0, uv_thread_join(&thread)); | ||
| } //guard out of scope -> unlock read lock | ||
|
|
||
| ASSERT_EQ(0, uv_rwlock_trywrlock(&lock)); | ||
| uv_rwlock_wrunlock(&lock); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, RwlockStealdTest) { | ||
| uv_rwlock_t lock; | ||
| ASSERT_EQ(0, uv_rwlock_init(&lock)); | ||
| celix_autoptr(uv_rwlock_t) lockCleanup = &lock; | ||
| celix_steal_ptr(lockCleanup); | ||
| uv_rwlock_destroy(&lock); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, ConditionAutoCleanupTest) { | ||
| uv_cond_t cond; | ||
| ASSERT_EQ(0, uv_cond_init(&cond)); | ||
| celix_autoptr(uv_cond_t) condCleanup = &cond; | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, ConditionStealTest) { | ||
| uv_cond_t cond; | ||
| ASSERT_EQ(0, uv_cond_init(&cond)); | ||
| celix_autoptr(uv_cond_t) condCleanup = &cond; | ||
| celix_steal_ptr(condCleanup); | ||
| uv_cond_destroy(&cond); | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, LocalThreadStorageKeyAutoCleanupTest) { | ||
| uv_key_t key; | ||
| ASSERT_EQ(0, uv_key_create(&key)); | ||
| celix_autoptr(uv_key_t) keyCleanup = &key; | ||
| } | ||
|
|
||
| TEST_F(UvThreadsTestSuite, LocalThreadStorageKeyStealTest) { | ||
| uv_key_t key; | ||
| ASSERT_EQ(0, uv_key_create(&key)); | ||
| celix_autoptr(uv_key_t) keyCleanup = &key; | ||
| celix_steal_ptr(keyCleanup); | ||
| uv_key_delete(&key); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cmake/CelixDeps.cmake.inshould also be updated.