Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

semaphore.c

Go to the documentation of this file.
00001 /*!     \file kernel/semaphore.c
00002  *      \brief Mutex semaphores.
00003  *      \author Andrea Righi <drizzt@inwind.it>
00004  *      \date Last update: 2003-10-27
00005  *      \note Copyright (&copy;) 2003 Andrea Righi
00006  */
00007 
00008 #include <const.h>
00009 #include <arch/i386.h>
00010 #include <kernel/task.h>
00011 #include <kernel/semaphore.h>
00012 
00013 //! \brief
00014 //!     Initialize a semaphore variable.
00015 //! \param sem The semaphore variable to initialize.
00016 void INIT_MUTEX(semaphore_t *sem)
00017 {
00018         atomic_set(sem, 1);
00019 }
00020 
00021 //! \brief
00022 //!     Semaphore "down" function.
00023 //! \param sem The semaphore variable.
00024 void DOWN(semaphore_t *sem)
00025 {
00026         dword IF = GET_IF();
00027 
00028         wait_for_wakeup:
00029         if ( atomic_read(sem) )
00030         {
00031                 atomic_set(sem, 0);
00032         }
00033         else
00034         {
00035                 enable();
00036                 // Wait for a wake-up.
00037                 idle();
00038                 goto wait_for_wakeup;
00039         }
00040         SET_IF(IF);
00041 }
00042 
00043 //! \brief
00044 //!     Semaphore "up" function.
00045 //! \param sem The semaphore variable.
00046 void UP(semaphore_t *sem)
00047 {
00048         atomic_set(sem, 1);
00049 }

Generated on Fri Feb 20 15:32:16 2004 for Minirighi by doxygen1.2.18