Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some dip1000 attributes #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be scope instead? What does return mean when there is no return value? I guess I should do more research of what DIP1000 has become by now, but somehow I can't really force myself to do that.

Copy link
Author

@WebFreak001 WebFreak001 Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return means that the parameter is then stored on the this object, aka the lifetime of the this object must be larger than the parameter's lifetime, since we are inside a class, although I haven't verified that.

It does make sense for that is how it works in the constructor and what it means to annotate the function itself as return.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after quick testing, it seems that return and scope on classes is a mess

but at least compilation works without warnings for now lol


/** 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
Loading