Max OS 0.3
Loading...
Searching...
No Matches
MaxOS::processes::resources::ThreadResourceRegistry Class Reference

Manages the creation, retention and destruction of resources representing threads. More...

#include <scheduler_resources.h>

Inheritance diagram for MaxOS::processes::resources::ThreadResourceRegistry:
MaxOS::processes::resources::ResourceRegistry< ThreadResource > MaxOS::processes::resources::BaseResourceRegistry

Public Member Functions

Resource * get_resource (const string &name) final
 Gets a resource from the registry by name.
 
Resource * create_resource (const string &name, size_t flags, uintptr_t data) final
 td
 
- Public Member Functions inherited from MaxOS::processes::resources::ResourceRegistry< ThreadResource >
 ResourceRegistry (resource_type_t type)
 Constructor for ResourceRegistry of a specific type.
 
- Public Member Functions inherited from MaxOS::processes::resources::BaseResourceRegistry
 BaseResourceRegistry (resource_type_t type)
 Constructs a new BaseResourceRegistry object and registers it globally.
 
 ~BaseResourceRegistry ()
 Destructor for BaseResourceRegistry, removes it from the global list.
 
resource_type_t type ()
 Gets the type of resources this registry handles.
 
bool register_resource (Resource *resource)
 Registers a resource in the registry.
 
void close_resource (Resource *resource, size_t flags)
 Close the resource provided, if it exists in this registry.
 

Additional Inherited Members

- Protected Attributes inherited from MaxOS::processes::resources::BaseResourceRegistry
common::Map< string, Resource * > m_resources
 The map of resource names to resource instances.
 
common::Map< string, uint64_t > m_resource_uses
 The map of resource names to how many processes are using them.
 
common::Spinlock m_lock
 The lock to make the registry threadsafe.
 
resource_type_t m_type
 The resource type that this registry manages.
 

Detailed Description

Manages the creation, retention and destruction of resources representing threads.

Definition at line 79 of file scheduler_resources.h.

Constructor & Destructor Documentation

◆ ThreadResourceRegistry()

ThreadResourceRegistry::ThreadResourceRegistry ( )

Definition at line 302 of file scheduler_resources.cpp.

303: ResourceRegistry<ThreadResource>(resource_type_t::THREAD)
304{
305
306}
A resource registry for a specific resource type.
Definition resource.h:61

Member Function Documentation

◆ create_resource()

Resource * ThreadResourceRegistry::create_resource ( const string &  name,
size_t  flags,
uintptr_t  data 
)
finalvirtual

td

Parameters
nametd
flagstd
Returns
td
Todo:
Implement opening threads

Reimplemented from MaxOS::processes::resources::ResourceRegistry< ThreadResource >.

Definition at line 316 of file scheduler_resources.cpp.

316 {
317
318 return ResourceRegistry::create_resource(name, flags, data);
319}
Resource * create_resource(const string &name, size_t flags, uintptr_t data) override
Create a new resource of the specific type.
Definition resource.h:74

References MaxOS::processes::resources::ResourceRegistry< Type >::create_resource().

◆ get_resource()

Resource * ThreadResourceRegistry::get_resource ( const string &  name)
finalvirtual

Gets a resource from the registry by name.

Parameters
nameThe name of the resource to find
Returns
The resource or nullptr if the resource was not found

Reimplemented from MaxOS::processes::resources::BaseResourceRegistry.

Definition at line 321 of file scheduler_resources.cpp.

321 {
322
323 // Resource already opened
324 auto resource = BaseResourceRegistry::get_resource(name);
325 if(resource != nullptr)
326 return resource;
327
328 // Get the thread
329 uint64_t tid = name.to_int();
330 auto thread = name == "this" ? GlobalScheduler::current_thread() : GlobalScheduler::get_thread(tid);
331
332 // Self refrence may already be open
333 resource = BaseResourceRegistry::get_resource(string(thread -> tid));
334 if(resource != nullptr)
335 return resource;
336
337 // Create the resource
338 auto thread_resource = new ThreadResource(string(thread -> tid), 0, resource_type_t::PROCESS);
339 thread_resource->thread = thread;
340
341 register_resource(thread_resource);
342 return thread_resource;
343}
The global scheduler that manages all processes and threads across all cores.
Definition scheduler.h:28
static Thread * current_thread()
Gets the thread on the currently executing core.
virtual Resource * get_resource(const string &name)
Gets a resource from the registry by name.
Definition resource.cpp:52
bool register_resource(Resource *resource)
Registers a resource in the registry.
Definition resource.cpp:76
A wrapper for a Thread which exposes Thread operations as Resource operations.

References MaxOS::processes::GlobalScheduler::current_thread(), MaxOS::processes::resources::BaseResourceRegistry::get_resource(), MaxOS::processes::GlobalScheduler::get_thread(), and MaxOS::processes::resources::BaseResourceRegistry::register_resource().


The documentation for this class was generated from the following files: