mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-04-28 21:38:01 +03:00
Mega-cleanup for atomic_t<> and named bit-sets bs_t<>
Remove "atomic operator" classes Remove test, test_and_set, test_and_reset, test_and_complement global functions Simplify atomic_t<> with constexpr if, remove some garbage Redesign bs_t<> to use class, mark its methods constexpr Implement atomic_bs_t<> for optimizations Remove unused __bitwise_ops concept (should be in other header anyway) Bitsets can now be tested via safe bool conversion
This commit is contained in:
parent
a6d06b2e20
commit
8abe6489ed
23 changed files with 604 additions and 1090 deletions
|
@ -799,34 +799,34 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
|
||||
#ifdef _WIN32
|
||||
DWORD access = 0;
|
||||
if (test(mode & fs::read)) access |= GENERIC_READ;
|
||||
if (test(mode & fs::write)) access |= DELETE | (test(mode & fs::append) ? FILE_APPEND_DATA : GENERIC_WRITE);
|
||||
if (mode & fs::read) access |= GENERIC_READ;
|
||||
if (mode & fs::write) access |= DELETE | (mode & fs::append ? FILE_APPEND_DATA : GENERIC_WRITE);
|
||||
|
||||
DWORD disp = 0;
|
||||
if (test(mode & fs::create))
|
||||
if (mode & fs::create)
|
||||
{
|
||||
disp =
|
||||
test(mode & fs::excl) ? CREATE_NEW :
|
||||
test(mode & fs::trunc) ? CREATE_ALWAYS : OPEN_ALWAYS;
|
||||
mode & fs::excl ? CREATE_NEW :
|
||||
mode & fs::trunc ? CREATE_ALWAYS : OPEN_ALWAYS;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (test(mode & fs::excl))
|
||||
if (mode & fs::excl)
|
||||
{
|
||||
g_tls_error = error::inval;
|
||||
return;
|
||||
}
|
||||
|
||||
disp = test(mode & fs::trunc) ? TRUNCATE_EXISTING : OPEN_EXISTING;
|
||||
disp = mode & fs::trunc ? TRUNCATE_EXISTING : OPEN_EXISTING;
|
||||
}
|
||||
|
||||
DWORD share = 0;
|
||||
if (!test(mode, fs::unread) || !test(mode & fs::write))
|
||||
if (!(mode & fs::unread) || !(mode & fs::write))
|
||||
{
|
||||
share |= FILE_SHARE_READ;
|
||||
}
|
||||
|
||||
if (!test(mode, fs::lock + fs::unread) || !test(mode & fs::write))
|
||||
if (!(mode & (fs::lock + fs::unread)) || !(mode & fs::write))
|
||||
{
|
||||
share |= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
|
||||
}
|
||||
|
@ -949,18 +949,18 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
#else
|
||||
int flags = 0;
|
||||
|
||||
if (test(mode & fs::read) && test(mode & fs::write)) flags |= O_RDWR;
|
||||
else if (test(mode & fs::read)) flags |= O_RDONLY;
|
||||
else if (test(mode & fs::write)) flags |= O_WRONLY;
|
||||
if (mode & fs::read && mode & fs::write) flags |= O_RDWR;
|
||||
else if (mode & fs::read) flags |= O_RDONLY;
|
||||
else if (mode & fs::write) flags |= O_WRONLY;
|
||||
|
||||
if (test(mode & fs::append)) flags |= O_APPEND;
|
||||
if (test(mode & fs::create)) flags |= O_CREAT;
|
||||
if (test(mode & fs::trunc) && !test(mode, fs::lock + fs::unread)) flags |= O_TRUNC;
|
||||
if (test(mode & fs::excl)) flags |= O_EXCL;
|
||||
if (mode & fs::append) flags |= O_APPEND;
|
||||
if (mode & fs::create) flags |= O_CREAT;
|
||||
if (mode & fs::trunc && !(mode & (fs::lock + fs::unread))) flags |= O_TRUNC;
|
||||
if (mode & fs::excl) flags |= O_EXCL;
|
||||
|
||||
int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
|
||||
|
||||
if (test(mode & fs::write) && test(mode & fs::unread))
|
||||
if (mode & fs::write && mode & fs::unread)
|
||||
{
|
||||
perm = 0;
|
||||
}
|
||||
|
@ -973,14 +973,14 @@ fs::file::file(const std::string& path, bs_t<open_mode> mode)
|
|||
return;
|
||||
}
|
||||
|
||||
if (test(mode & fs::write) && test(mode, fs::lock + fs::unread) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
|
||||
if (mode & fs::write && mode & (fs::lock + fs::unread) && ::flock(fd, LOCK_EX | LOCK_NB) != 0)
|
||||
{
|
||||
g_tls_error = errno == EWOULDBLOCK ? fs::error::acces : to_error(errno);
|
||||
::close(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
if (test(mode & fs::trunc) && test(mode, fs::lock + fs::unread))
|
||||
if (mode & fs::trunc && mode & (fs::lock + fs::unread))
|
||||
{
|
||||
// Postpone truncation in order to avoid using O_TRUNC on a locked file
|
||||
::ftruncate(fd, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue