Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions common/enumerable.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#pragma once
#include <type_traits>
#include <utility>
#include <photon/common/utility.h>

// If class A can be enumerable with A::get() and A::next(),
// then objects of A can be enumerated by the `for` statement
Expand Down
1 change: 1 addition & 0 deletions fs/cache/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#include <sys/uio.h>
#include <stdlib.h>
#include <sys/fcntl.h>
#include <fcntl.h>
#include <photon/fs/filesystem.h>
#include <photon/fs/cache/pool_store.h>

Expand Down
7 changes: 7 additions & 0 deletions fs/cache/forwardcfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ limitations under the License.

namespace photon {
namespace fs{
class ICacheStore;
class ICachePool;
template <class IForwardCachedFile>
class ForwardCachedFileBase : public IForwardCachedFile {
protected:
Expand All @@ -38,6 +40,8 @@ class ForwardCachedFileBase : public IForwardCachedFile {
return Base::m_file->query(offset, count);
}
};

class ICachedFile;
using ForwardCachedFile = ForwardCachedFileBase<photon::fs::ForwardFileBase<ICachedFile>>;
using ForwardCachedFile_Ownership =
ForwardCachedFileBase<photon::fs::ForwardFileBase_Ownership<ICachedFile>>;
Expand All @@ -60,6 +64,9 @@ class ForwardCachedFSBase : public IForwardCachedFS {
return Base::m_fs->set_pool(pool);
}
};

class ICachedFileSystem;

using ForwardCachedFS = ForwardCachedFSBase<photon::fs::ForwardFSBase<ICachedFileSystem>>;
using ForwardCachedFS_Ownership =
ForwardCachedFSBase<photon::fs::ForwardFSBase_Ownership<ICachedFileSystem>>;
Expand Down
22 changes: 14 additions & 8 deletions include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,20 @@ limitations under the License.
#define O_NONBLOCK 0x4000
#endif

// Windows/MinGW lacks posix_fadvise() and its POSIX_FADV_* constants. The
// fadvise() override on Windows is a no-op, so any integer value is safe;
// using 0 for all of them keeps the shim minimal and call sites unchanged.
#else
// Non-Windows: forward to the real libc <fcntl.h>.
#include_next <fcntl.h>
#endif

// posix_fadvise() and its POSIX_FADV_* constants are Linux-only: neither MinGW
// nor Darwin has them (Darwin's SDK defines no POSIX_FADV_* and declares no
// posix_fadvise at all). Every platform that lacks them also lacks the
// fadvise() override -- fs/localfs.cpp puts it under #ifdef __linux__, so the
// base UNIMPLEMENTED(int fadvise(...)) in fs/filesystem.h handles the call and
// the advice value never reaches a syscall. Any integer is therefore safe; 0
// for all of them keeps the shim minimal and call sites unchanged. These are
// outside the _WIN32 branch above and #ifndef-guarded, so Linux, whose <fcntl.h>
// does define them, keeps the real values.
#ifndef POSIX_FADV_NORMAL
#define POSIX_FADV_NORMAL 0
#endif
Expand All @@ -58,8 +69,3 @@ limitations under the License.
#ifndef POSIX_FADV_NOREUSE
#define POSIX_FADV_NOREUSE 0
#endif

#else
// Non-Windows: forward to the real libc <fcntl.h>.
#include_next <fcntl.h>
#endif
1 change: 1 addition & 0 deletions io/iocp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.

#pragma once

#include <fcntl.h>
#include <photon/common/timeout.h>
#include <photon/io/fd-events.h>
#include <sys/uio.h>
Expand Down
74 changes: 74 additions & 0 deletions test/test-includes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Compile every header under include/photon/ on its own, so a header that is not
# self-contained fails here instead of in whichever .cpp happens to include it
# second. Up to JOBS compilations run at once, defaulting to the number of
# online CPUs; JOBS=1 gives the old serial behaviour.
#
# Extra arguments are passed through to gcc, which is how you supply a dependency
# this machine keeps somewhere off the default search path:
# test/test-includes.sh -I/opt/homebrew/include
#
# Exits non-zero if any header failed.
cd `dirname $0`/../include || exit 1

# getconf rather than nproc: nproc is GNU coreutils and macOS does not have it.
# The case arm catches both a machine where getconf is missing and a JOBS that
# was set to something xargs -P would reject.
JOBS=${JOBS:-`getconf _NPROCESSORS_ONLN 2>/dev/null`}
case $JOBS in ('' | *[!0-9]*) JOBS=1 ;; esac

# Force colour ONLY when this script's own stdout is a terminal; into a
# redirected log the escape bytes are just noise, so COLOR stays empty and gcc is
# invoked exactly as before.
#
# Why forcing is needed at all: gcc and clang colour diagnostics only when their
# own output is a TTY, and this script captures them through a pipe so each can
# be attributed to its header -- which silently drops the colour. Which flag
# forces it back on is not portable: gcc 15 ignores -fcolor-diagnostics and clang
# older than 17 does not know -fdiagnostics-color, so probe for the flag that
# actually puts an escape byte into a pipe rather than guessing from a version
# number.
COLOR=
if [ -t 1 ]; then
esc=`printf '\033'`
for f in -fdiagnostics-color=always -fcolor-diagnostics; do
if printf 'int x = "s";\n' | gcc -x c - -c -o /dev/null "$f" 2>&1 | grep -q "$esc"; then
COLOR=$f
break
fi
done
fi

# xargs appends its own items after the command, so the gcc flags cannot be
# handed to `sh -c` as leading arguments; they travel in the environment instead.
# The worker expands this unquoted on purpose -- it is a flag list, not one
# argument. $COLOR goes first so that passing -fdiagnostics-color=never on the
# command line still turns the colour back off. That spelling, not clang's
# -fno-color-diagnostics: gcc rejects the latter outright with "unrecognized
# command-line option".
PHOTON_HDR_FLAGS="$COLOR $*"
export PHOTON_HDR_FLAGS

result=`mktemp`
trap 'rm -f "$result"' EXIT

# Each header's diagnostics are captured and then printed under its own FAIL
# line. Letting gcc write straight to the terminal was fine serially, but with
# -P 8 the streams interleave and an error can no longer be attributed to the
# header that produced it.
find photon -name "*.h" -print0 |
xargs -0 -P "$JOBS" -n1 sh -c '
h=$1
if err=`printf "#include <%s>\n" "$h" |
gcc -x c++ - -std=c++20 -c -I . -o /dev/null $PHOTON_HDR_FLAGS 2>&1`; then
printf "PASS %s\n" "$h"
else
printf "FAIL %s\n" "$h"
printf "%s\n" "$err" | sed "s/^/ /"
fi
' _ | tee "$result"

pass=`grep -c "^PASS " "$result"`
fail=`grep -c "^FAIL " "$result"`
printf "\n%d headers: %d passed, %d failed (JOBS=%d)\n" \
"$((pass + fail))" "$pass" "$fail" "$JOBS"
[ "$fail" -eq 0 ]
3 changes: 2 additions & 1 deletion thread/coro20.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,8 @@ auto run(F &&f, Args &&... args) {
}

inline auto usleep(uint64_t time) {
return wrapper(photon::thread_usleep, time);
int (*f)(Timeout) = &photon::thread_usleep;
return wrapper(f, Timeout(time));
}

inline auto sleep(uint64_t time) { return wrapper(photon::thread_sleep, time); }
Expand Down
Loading