Skip to content

Commit

Permalink
Add function to check whether task is ready (i.e., scheduled)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-torrance committed Nov 21, 2024
1 parent 0d91bf4 commit 507e642
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions M2/Macaulay2/d/pthread.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ taskCreate(f:function(TaskCellBody):null,tb:TaskCellBody) ::= Ccode(taskPointer

export taskDone(tp:taskPointer) ::= Ccode(int, "taskDone(",tp,")")==1;
export taskStarted(tp:taskPointer) ::=Ccode(int, "taskStarted(",tp,")")==1;
export taskReady(tp:taskPointer) ::= Ccode(int, "taskReady(", tp, ")") == 1;
pushTask(tp:taskPointer) ::=Ccode(void, "pushTask(",tp,")");
taskResult(tp:taskPointer) ::=Ccode(voidPointer, "taskResult(",tp,")");
export taskKeepRunning(tp:taskPointer) ::= Ccode(int, "taskKeepRunning(",tp,")")==1;
Expand Down
7 changes: 7 additions & 0 deletions M2/Macaulay2/system/supervisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ extern "C" {
// synchronizes-with the task's thread, avoids data races
return task->m_Started;
}
int taskReady(struct ThreadTask *task)
{
if (!task)
return false;
lock_guard<pthreadMutex> lock(task->m_Mutex);
return task->m_ReadyToRun;
}
void* taskResult(struct ThreadTask* task)
{
lock_guard<pthreadMutex> lock(task->m_Mutex);
Expand Down
4 changes: 4 additions & 0 deletions M2/Macaulay2/system/supervisorinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ extern "C" {
Returns 1 if the task has been started, 0 otherwise
**/
extern int taskStarted(struct ThreadTask* task);
/**
Returns 1 if the task is ready to run, 0 otherwise
**/
extern int taskReady(struct ThreadTask* task);
/**
Returns the taskResult if finished, NULL otherwise
**/
Expand Down

0 comments on commit 507e642

Please sign in to comment.