NutsOS/kernel/src/ipc.c
2020-04-17 17:44:23 +02:00

56 lines
1.3 KiB
C

/* ipc.c - This file is a part of NutsOS
*
* NutsOS
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* NutsOS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* NutsOS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with NutsOS; If not, see <http://www.gnu.org/licenses/>.
*
* Valentin Verdier <valentin.verdier03@gmail.com>
*/
#include "ipc.h"
#include "types.h"
#include "asm_x86.h"
#include "process.h"
void IPC_MutexLock(unsigned int* mutex)
{
if(CurrentProcess)
{
if(_AtomicTestAndSet(mutex))
{
CurrentProcess->ipcWaitMutex = mutex;
CurrentProcess->status = 1;
Schedule();
}
else
{
CurrentProcess->ipcInSection++;
}
}
}
void IPC_MutexUnlock(unsigned int* mutex)
{
if(CurrentProcess)
{
if(CurrentProcess->ipcInSection > 0)
{
*mutex = 0;
CurrentProcess->ipcInSection--;
}
}
}