fork download
  1. #include <stdint.h>
  2.  
  3. #define CLI __asm__ __volatile__( "cli" )
  4. #define STI __asm__ __volatile__( "sti" )
  5.  
  6. class spin_lock
  7. {
  8. public:
  9. spin_lock() : _isr_state{0}, _lock{0} {};
  10.  
  11. void lock( void )
  12. {
  13. /* remember the current IF flag and disable interrupts */
  14. _isr_state = ( processor::core::read_eflags() & ( 1 << 9 ) );
  15. CLI;
  16.  
  17. /* go for the lock */
  18. do {} while( __sync_lock_test_and_set( &_lock, 1 ) );
  19. }
  20.  
  21. void unlock( void )
  22. {
  23. /* release the lock */
  24. __sync_lock_release( &_lock );
  25.  
  26. if( _isr_state )
  27. {
  28. /* if IF was set re-enable interrupts */
  29. STI;
  30. }
  31. }
  32.  
  33. private:
  34. bool _isr_state = 0;
  35. volatile uint8_t _lock = 0;
  36. };
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘void spin_lock::lock()’:
prog.cpp:11:18: error: ‘processor’ has not been declared
   _isr_state = ( processor::core::read_flags() & ( 1 << 9 ) );
                  ^
prog.cpp:12:3: error: ‘processor’ has not been declared
   processor::core::disable_interrupts();
   ^
prog.cpp: In member function ‘void spin_lock::unlock()’:
prog.cpp:26:4: error: ‘processor’ has not been declared
    processor::core::enable_interrupts();
    ^
stdout
Standard output is empty