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

Where is the proper position to add PreRun and PostRun? #119

Open
creeperZY opened this issue Feb 28, 2024 · 2 comments
Open

Where is the proper position to add PreRun and PostRun? #119

creeperZY opened this issue Feb 28, 2024 · 2 comments
Labels

Comments

@creeperZY
Copy link

Excuse me, sir.
I want to add 2 new functions named PreRun and PostRun, where I want to do some preparation before running with multi-thread. I finished them in function:
void TaskScheduler::WaitforTask( const ICompletable* pCompletable_, enki::TaskPriority priorityOfLowestToRun_ )
, and added these codes at the begin:
auto* nonConstICompletablePtr = const_cast<ICompletable*>(pCompletable_);
if (nonConstICompletablePtr) nonConstICompletablePtr->PreRunExecuteRange();
added these codes at the end:
if (nonConstICompletablePtr) nonConstICompletablePtr->PostRunExecuteRange();
It works well on Linux, but reports error on Windows, I don't know what caused it.
Could you please give me some advice about where I should add these 2 functions properly?
THANKS!

@dougbinks
Copy link
Owner

dougbinks commented Feb 28, 2024

Altering enkiTS internals is non-trivial, and I wouldn't recommend doing so.

I also don't quite understand what you want to do. The function WaitforTask is not doing any multi-threaded work, it is simply running available tasks on it's own thread whilst waiting (rather than doing nothing).

If you want to run code before and after the ExecuteRange function then the best approach would be to either create a task dependency chain (see the example Dependencies.cpp), or add a new base task function as follows:

// note: untested code
class ITaskSetWithPrePost : public ITaskSet
{
public:
    virtual void ExectuteRangeWithPrePost( TaskSetPartition range_, uint32_t threadnum_  ) = 0; // override this not ExecuteRange
	
    void ExecuteRange( TaskSetPartition range_, uint32_t threadnum_  ) override final
    {
        PreFunc();
        ExectuteRangeWithPrePost( range_, threadnum_ );
        PostFunc();
    }
}

If this isn't what you are trying to achieve let me know.

You may also want to look at the ProfilerCallbacks in case what you want is to call functions when certain events occur. See the eniTSExamples for examples on how to use these.

@creeperZY
Copy link
Author

creeperZY commented Feb 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants