Merge branch 'master' into vulkan
This commit is contained in:
@@ -69,6 +69,11 @@ class global_critical_region {
|
||||
return std::unique_lock<std::recursive_mutex>(mutex());
|
||||
}
|
||||
|
||||
// Acquires a deferred lock on the global critical section.
|
||||
inline std::unique_lock<std::recursive_mutex> AcquireDeferred() {
|
||||
return std::unique_lock<std::recursive_mutex>(mutex(), std::defer_lock);
|
||||
}
|
||||
|
||||
// Tries to acquire a lock on the glboal critical section.
|
||||
// Check owns_lock() to see if the lock was successfully acquired.
|
||||
inline std::unique_lock<std::recursive_mutex> TryAcquire() {
|
||||
|
||||
@@ -34,6 +34,11 @@
|
||||
namespace xe {
|
||||
namespace string_util {
|
||||
|
||||
enum class Safety {
|
||||
IDontKnowWhatIAmDoing,
|
||||
IKnowWhatIAmDoing,
|
||||
};
|
||||
|
||||
inline size_t copy_truncating(char* dest, const std::string_view source,
|
||||
size_t dest_buffer_count) {
|
||||
if (!dest_buffer_count) {
|
||||
@@ -68,6 +73,44 @@ inline size_t copy_and_swap_truncating(char16_t* dest,
|
||||
return chars_copied;
|
||||
}
|
||||
|
||||
template <Safety safety = Safety::IDontKnowWhatIAmDoing>
|
||||
inline size_t copy_maybe_truncating(char* dest, const std::string_view source,
|
||||
size_t dest_buffer_count) {
|
||||
static_assert(safety == Safety::IKnowWhatIAmDoing);
|
||||
if (!dest_buffer_count) {
|
||||
return 0;
|
||||
}
|
||||
size_t chars_copied = std::min(source.size(), dest_buffer_count);
|
||||
std::memcpy(dest, source.data(), chars_copied);
|
||||
return chars_copied;
|
||||
}
|
||||
|
||||
template <Safety safety = Safety::IDontKnowWhatIAmDoing>
|
||||
inline size_t copy_maybe_truncating(char16_t* dest,
|
||||
const std::u16string_view source,
|
||||
size_t dest_buffer_count) {
|
||||
static_assert(safety == Safety::IKnowWhatIAmDoing);
|
||||
if (!dest_buffer_count) {
|
||||
return 0;
|
||||
}
|
||||
size_t chars_copied = std::min(source.size(), dest_buffer_count);
|
||||
std::memcpy(dest, source.data(), chars_copied * sizeof(char16_t));
|
||||
return chars_copied;
|
||||
}
|
||||
|
||||
template <Safety safety = Safety::IDontKnowWhatIAmDoing>
|
||||
inline size_t copy_and_swap_maybe_truncating(char16_t* dest,
|
||||
const std::u16string_view source,
|
||||
size_t dest_buffer_count) {
|
||||
static_assert(safety == Safety::IKnowWhatIAmDoing);
|
||||
if (!dest_buffer_count) {
|
||||
return 0;
|
||||
}
|
||||
size_t chars_copied = std::min(source.size(), dest_buffer_count);
|
||||
xe::copy_and_swap(dest, source.data(), chars_copied);
|
||||
return chars_copied;
|
||||
}
|
||||
|
||||
inline std::string to_hex_string(uint32_t value) {
|
||||
return fmt::format("{:08X}", value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user