Skip to content

Commit 0938e8f

Browse files
Improve Multi-threaded Performance. (#450)
* Optimized multi-threading. * Remove old multi-threading implementation. * Release files instead of removing. * Lock before choosing to check cache or download. * Unlock directly after verifying directory exists.
1 parent 09b056a commit 0938e8f

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

cmake/CPM.cmake

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -713,9 +713,15 @@ function(CPMAddPackage)
713713
get_filename_component(download_directory ${download_directory} ABSOLUTE)
714714
list(APPEND CPM_ARGS_UNPARSED_ARGUMENTS SOURCE_DIR ${download_directory})
715715

716-
file(LOCK ${download_directory}/../cmake.lock)
716+
if(CPM_SOURCE_CACHE)
717+
file(LOCK ${download_directory}/../cmake.lock)
718+
endif()
717719

718720
if(EXISTS ${download_directory})
721+
if(CPM_SOURCE_CACHE)
722+
file(LOCK ${download_directory}/../cmake.lock RELEASE)
723+
endif()
724+
719725
cpm_store_fetch_properties(
720726
${CPM_ARGS_NAME} "${download_directory}"
721727
"${CPM_FETCHCONTENT_BASE_DIR}/${lower_case_name}-build"
@@ -783,6 +789,9 @@ function(CPMAddPackage)
783789
"${CPM_ARGS_NAME}" "${CPM_ARGS_VERSION}" "${PACKAGE_INFO}" "${CPM_ARGS_UNPARSED_ARGUMENTS}"
784790
)
785791
cpm_fetch_package("${CPM_ARGS_NAME}" populated)
792+
if(CPM_CACHE_SOURCE AND download_directory)
793+
file(LOCK ${download_directory}/../cmake.lock RELEASE)
794+
endif()
786795
if(${populated})
787796
cpm_add_subdirectory(
788797
"${CPM_ARGS_NAME}" "${DOWNLOAD_ONLY}"
@@ -793,10 +802,6 @@ function(CPMAddPackage)
793802
cpm_get_fetch_properties("${CPM_ARGS_NAME}")
794803
endif()
795804

796-
if(EXISTS ${download_directory}/../cmake.lock)
797-
file(LOCK ${download_directory}/../cmake.lock RELEASE)
798-
endif()
799-
800805
set(${CPM_ARGS_NAME}_ADDED YES)
801806
cpm_export_variables("${CPM_ARGS_NAME}")
802807
endfunction()

0 commit comments

Comments
 (0)