fix: new spinlock implementation, ramdisk max files, wallpaper scan locations
This commit is contained in:
@@ -8,12 +8,17 @@
|
|||||||
|
|
||||||
namespace kcp {
|
namespace kcp {
|
||||||
void Spinlock::Acquire() {
|
void Spinlock::Acquire() {
|
||||||
|
uint64_t flags;
|
||||||
|
asm volatile("pushfq; pop %0; cli" : "=r"(flags) :: "memory");
|
||||||
while (atomic_flag.test_and_set(std::memory_order_acquire)) {
|
while (atomic_flag.test_and_set(std::memory_order_acquire)) {
|
||||||
asm volatile("pause");
|
asm volatile("pause");
|
||||||
}
|
}
|
||||||
|
savedFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Spinlock::Release() {
|
void Spinlock::Release() {
|
||||||
|
uint64_t flags = savedFlags;
|
||||||
atomic_flag.clear(std::memory_order_release);
|
atomic_flag.clear(std::memory_order_release);
|
||||||
|
asm volatile("push %0; popfq" :: "r"(flags) : "memory");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
namespace kcp {
|
namespace kcp {
|
||||||
class Spinlock {
|
class Spinlock {
|
||||||
std::atomic_flag atomic_flag{ATOMIC_FLAG_INIT};
|
std::atomic_flag atomic_flag{ATOMIC_FLAG_INIT};
|
||||||
|
uint64_t savedFlags = 0;
|
||||||
public:
|
public:
|
||||||
void Acquire();
|
void Acquire();
|
||||||
void Release();
|
void Release();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
namespace Fs::Ramdisk {
|
namespace Fs::Ramdisk {
|
||||||
|
|
||||||
static constexpr int MaxFiles = 256;
|
static constexpr int MaxFiles = 512;
|
||||||
static constexpr int MaxNameLen = 100;
|
static constexpr int MaxNameLen = 100;
|
||||||
|
|
||||||
struct FileEntry {
|
struct FileEntry {
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -177,7 +177,7 @@ static void settings_draw_appearance(Canvas& c, SettingsState* st) {
|
|||||||
if (mode_image) {
|
if (mode_image) {
|
||||||
// Scan for images lazily
|
// Scan for images lazily
|
||||||
if (!st->wp_scanned) {
|
if (!st->wp_scanned) {
|
||||||
wallpaper_scan_dir(st->desktop->home_dir, &st->wp_files);
|
wallpaper_scan_home(st->desktop->home_dir, &st->wp_files);
|
||||||
st->wp_scanned = true;
|
st->wp_scanned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1156,7 +1156,7 @@ static void settings_on_mouse(Window* win, MouseEvent& ev) {
|
|||||||
s.bg_image = true;
|
s.bg_image = true;
|
||||||
s.bg_gradient = false;
|
s.bg_gradient = false;
|
||||||
if (!st->wp_scanned) {
|
if (!st->wp_scanned) {
|
||||||
wallpaper_scan_dir(st->desktop->home_dir, &st->wp_files);
|
wallpaper_scan_home(st->desktop->home_dir, &st->wp_files);
|
||||||
st->wp_scanned = true;
|
st->wp_scanned = true;
|
||||||
}
|
}
|
||||||
settings_persist(st);
|
settings_persist(st);
|
||||||
|
|||||||
@@ -139,9 +139,11 @@ struct WallpaperFileList {
|
|||||||
int count;
|
int count;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void wallpaper_scan_dir(const char* dir_path, WallpaperFileList* list) {
|
// Scan dir_path for JPEG files and append to list.
|
||||||
list->count = 0;
|
// name_prefix is prepended to each stored filename (e.g. "Pictures/").
|
||||||
|
// Caller must zero list->count before the first call if starting fresh.
|
||||||
|
inline void wallpaper_scan_dir(const char* dir_path, WallpaperFileList* list,
|
||||||
|
const char* name_prefix = nullptr) {
|
||||||
const char* raw_names[64];
|
const char* raw_names[64];
|
||||||
int total = montauk::readdir(dir_path, raw_names, 64);
|
int total = montauk::readdir(dir_path, raw_names, 64);
|
||||||
if (total <= 0) return;
|
if (total <= 0) return;
|
||||||
@@ -165,6 +167,8 @@ inline void wallpaper_scan_dir(const char* dir_path, WallpaperFileList* list) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int np_len = name_prefix ? montauk::slen(name_prefix) : 0;
|
||||||
|
|
||||||
auto to_lower = [](char c) -> char {
|
auto to_lower = [](char c) -> char {
|
||||||
return (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c;
|
return (c >= 'A' && c <= 'Z') ? (char)(c + 32) : c;
|
||||||
};
|
};
|
||||||
@@ -206,10 +210,34 @@ inline void wallpaper_scan_dir(const char* dir_path, WallpaperFileList* list) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_jpeg) {
|
if (is_jpeg) {
|
||||||
montauk::strncpy(list->names[list->count], name, 63);
|
if (np_len > 0) {
|
||||||
|
montauk::strncpy(list->names[list->count], name_prefix, 63);
|
||||||
|
int cur = np_len < 63 ? np_len : 63;
|
||||||
|
montauk::strncpy(list->names[list->count] + cur, name,
|
||||||
|
63 - cur);
|
||||||
|
} else {
|
||||||
|
montauk::strncpy(list->names[list->count], name, 63);
|
||||||
|
}
|
||||||
list->count++;
|
list->count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scan Pictures/ subdirectory first, then home directory.
|
||||||
|
inline void wallpaper_scan_home(const char* home_dir, WallpaperFileList* list) {
|
||||||
|
list->count = 0;
|
||||||
|
|
||||||
|
char pictures[256];
|
||||||
|
montauk::strcpy(pictures, home_dir);
|
||||||
|
int hlen = montauk::slen(pictures);
|
||||||
|
if (hlen > 0 && pictures[hlen - 1] != '/') {
|
||||||
|
pictures[hlen++] = '/';
|
||||||
|
pictures[hlen] = '\0';
|
||||||
|
}
|
||||||
|
montauk::strncpy(pictures + hlen, "Pictures", 256 - hlen);
|
||||||
|
|
||||||
|
wallpaper_scan_dir(pictures, list, "Pictures/");
|
||||||
|
wallpaper_scan_dir(home_dir, list);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace gui
|
} // namespace gui
|
||||||
|
|||||||
Reference in New Issue
Block a user