Skip to content

Commit

Permalink
add some dip1000 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
WebFreak001 committed Nov 15, 2023
1 parent 47a9ff9 commit 1082a55
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
4 changes: 2 additions & 2 deletions source/eventcore/driver.d
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ interface EventDriverFiles {
needs to make sure that either `on_read_finish` got called, or
`cancelRead` was called before issuing the next call to `read`.
*/
void write(FileFD file, ulong offset, const(ubyte)[] buffer, IOMode mode, FileIOCallback on_write_finish);
void write(FileFD file, ulong offset, return const(ubyte)[] buffer, IOMode mode, return FileIOCallback on_write_finish);

/** Cancels an ongoing write operation.
Expand All @@ -519,7 +519,7 @@ interface EventDriverFiles {
needs to make sure that either `on_read_finish` got called, or
`cancelRead` was called before issuing the next call to `read`.
*/
void read(FileFD file, ulong offset, ubyte[] buffer, IOMode mode, FileIOCallback on_read_finish);
void read(FileFD file, ulong offset, return ubyte[] buffer, IOMode mode, return FileIOCallback on_read_finish);

/** Cancels an ongoing read operation.
Expand Down
21 changes: 11 additions & 10 deletions source/eventcore/drivers/threadedfile.d
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
return FileFD(system_file_handle, vc + 1);
}

void close(FileFD file, FileCloseCallback on_closed)
void close(FileFD file, FileCloseCallback on_closed) scope
{
if (!isValid(file)) {
on_closed(file, CloseStatus.invalidHandle);
Expand Down Expand Up @@ -328,20 +328,21 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
}


final override void write(FileFD file, ulong offset, const(ubyte)[] buffer, IOMode, FileIOCallback on_write_finish)
final override void write(FileFD file, ulong offset, return const(ubyte)[] buffer, IOMode mode, return FileIOCallback on_write_finish)
{
if (!isValid(file)) {
on_write_finish(file, IOStatus.invalidHandle, 0);
return;
}

//assert(this.writable);
auto f = () @trusted { return &m_files[file]; } ();
scope f = () @trusted { return &m_files[file]; } ();

if (!safeCAS(f.write.status, ThreadedFileStatus.idle, ThreadedFileStatus.initiated))
assert(false, "Concurrent file writes are not allowed.");
assert(f.write.callback is null, "Concurrent file writes are not allowed.");
f.write.callback = on_write_finish;
// cast away return/scope
f.write.callback = (() @trusted => *cast(FileIOCallback*) &on_write_finish)();
m_activeWrites.insert(file.value);
threadSetup();
log("start write task");
Expand Down Expand Up @@ -370,7 +371,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
safeCAS(f.status, ThreadedFileStatus.processing, ThreadedFileStatus.cancelling);
}

final override void read(FileFD file, ulong offset, ubyte[] buffer, IOMode, FileIOCallback on_read_finish)
final override void read(FileFD file, ulong offset, return ubyte[] buffer, IOMode mode, return FileIOCallback on_read_finish)
{
if (!isValid(file)) {
on_read_finish(file, IOStatus.invalidHandle, 0);
Expand All @@ -382,7 +383,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
if (!safeCAS(f.read.status, ThreadedFileStatus.idle, ThreadedFileStatus.initiated))
assert(false, "Concurrent file reads are not allowed.");
assert(f.read.callback is null, "Concurrent file reads are not allowed.");
f.read.callback = on_read_finish;
f.read.callback = (() @trusted => *cast(FileIOCallback*) &on_read_finish)();
m_activeReads.insert(file.value);
threadSetup();
log("start read task");
Expand Down Expand Up @@ -411,20 +412,20 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
safeCAS(f.status, ThreadedFileStatus.processing, ThreadedFileStatus.cancelling);
}

final override bool isValid(FileFD handle)
final override bool isValid(FileFD handle) scope
const {
if (handle.value >= m_files.length) return false;
return m_files[handle.value].validationCounter == handle.validationCounter;
}

final override void addRef(FileFD descriptor)
final override void addRef(FileFD descriptor) scope
{
if (!isValid(descriptor)) return;

m_files[descriptor].refCount++;
}

final override bool releaseRef(FileFD descriptor)
final override bool releaseRef(FileFD descriptor) scope
{
if (!isValid(descriptor)) return true;

Expand Down Expand Up @@ -455,7 +456,7 @@ final class ThreadedFileEventDriver(Events : EventDriverEvents, Core : EventDriv
}

/// private
static void taskFun(string op, UB)(shared(ThreadedFileEventDriver) files, shared(FileInfo)* fi, FileFD file, ulong offset, UB[] buffer)
static void taskFun(string op, UB)(shared(ThreadedFileEventDriver) files, shared(FileInfo)* fi, FileFD file, ulong offset, scope UB[] buffer)
{
log("task fun");
shared(IOInfo)* f = mixin("&fi."~op);
Expand Down
4 changes: 3 additions & 1 deletion source/eventcore/internal/ioworker.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ struct IOWorkerPool {

auto run(alias fun, ARGS...)(ARGS args)
{
auto task = StaticTaskPool.allocTask!(fun, ARGS)(args);
import core.lifetime : forward;

auto task = StaticTaskPool.allocTask!(fun, ARGS)(forward!args);
try m_pool.put(task);
catch (Exception e) assert(false, e.msg);
return task;
Expand Down

0 comments on commit 1082a55

Please sign in to comment.