ptos: ps: Add thread management groundwork
Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
* @Pid: Process ID
|
||||
* @Flags: Initialization flags
|
||||
*/
|
||||
typedef struct {
|
||||
typedef struct _PROCESS {
|
||||
CHAR Name[PS_NAME_MAX];
|
||||
UQUAD Pid;
|
||||
ULONG Flags;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Thread management
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#ifndef _PS_THREAD_H_
|
||||
#define _PS_THREAD_H_ 1
|
||||
|
||||
#include <ptapi/status.h>
|
||||
#include <ptdef.h>
|
||||
#include <queue.h>
|
||||
|
||||
#define THREAD_POOL_TAG 'TD'
|
||||
|
||||
struct _PROCESS;
|
||||
|
||||
/*
|
||||
* Represents a runnable thread that exists within
|
||||
* processes.
|
||||
*
|
||||
* @Tid: Thread ID
|
||||
* @ThreadLink: Thread queue link
|
||||
*/
|
||||
typedef struct _THREAD {
|
||||
UQUAD Tid;
|
||||
TAILQ_ENTRY(_THREAD) ThreadLink;
|
||||
} THREAD;
|
||||
|
||||
/*
|
||||
* Create a new thread
|
||||
*
|
||||
* @Parent: Parent of thread to create
|
||||
* @Flags: Optional init flags
|
||||
* @Result: Result is written here
|
||||
*/
|
||||
PT_STATUS PsCreateThread(struct _PROCESS *Parent, ULONG Flags, THREAD **Result);
|
||||
|
||||
#endif /* !_PS_THREAD_H_ */
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2026, Chloe M.
|
||||
* Provided under the BSD-3 clause.
|
||||
*
|
||||
* Description: Thread management
|
||||
* Author: Chloe M.
|
||||
*/
|
||||
|
||||
#include <ps/thread.h>
|
||||
#include <ps/process.h>
|
||||
#include <ex/pool.h>
|
||||
#include <atomic.h>
|
||||
|
||||
/* Globals */
|
||||
static UQUAD NextThreadTid = 0;
|
||||
|
||||
PT_STATUS
|
||||
PsCreateThread(struct _PROCESS *Parent, ULONG Flags, THREAD **Result)
|
||||
{
|
||||
THREAD *Thread;
|
||||
|
||||
if (Parent == NULL || Result == NULL) {
|
||||
return STATUS_INVALID_PARAM;
|
||||
}
|
||||
|
||||
Thread = ExAllocatePoolWithTag(
|
||||
POOL_NON_PAGED,
|
||||
sizeof(*Thread),
|
||||
THREAD_POOL_TAG
|
||||
);
|
||||
|
||||
if (Thread == NULL) {
|
||||
return STATUS_NO_MEMORY;
|
||||
}
|
||||
|
||||
Thread->Tid = AtomicIncQuad(&NextThreadTid);
|
||||
*Result = Thread;
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user