mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:12:43 +00:00 
			
		
		
		
	 2ff3c54153
			
		
	
	
		2ff3c54153
		
	
	
	
	
		
			
			The maximum number of virtual consoles is determined at compile time, so we can pre-allocate that many slots, dodging some heap allocations. Furthermore, virtual consoles are never destroyed, so it's fine to simply store a raw pointer to the currently active one.
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.1 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/NonnullRefPtr.h>
 | |
| #include <AK/NonnullRefPtrVector.h>
 | |
| #include <AK/Types.h>
 | |
| #include <Kernel/TTY/VirtualConsole.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| class ConsoleManagement {
 | |
|     AK_MAKE_ETERNAL;
 | |
|     friend class VirtualConsole;
 | |
| 
 | |
| public:
 | |
|     ConsoleManagement();
 | |
| 
 | |
|     static constexpr size_t s_max_virtual_consoles = 6;
 | |
| 
 | |
|     static bool is_initialized();
 | |
|     static ConsoleManagement& the();
 | |
| 
 | |
|     void switch_to(unsigned);
 | |
|     void initialize();
 | |
| 
 | |
|     void resolution_was_changed();
 | |
| 
 | |
|     void switch_to_debug() { switch_to(1); }
 | |
| 
 | |
|     NonnullRefPtr<VirtualConsole> first_tty() const { return m_consoles[0]; }
 | |
|     NonnullRefPtr<VirtualConsole> debug_tty() const { return m_consoles[1]; }
 | |
| 
 | |
|     RecursiveSpinLock& tty_write_lock() { return m_tty_write_lock; }
 | |
| 
 | |
| private:
 | |
|     NonnullRefPtrVector<VirtualConsole, s_max_virtual_consoles> m_consoles;
 | |
|     VirtualConsole* m_active_console { nullptr };
 | |
|     SpinLock<u8> m_lock;
 | |
|     RecursiveSpinLock m_tty_write_lock;
 | |
| };
 | |
| 
 | |
| };
 |