/* 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 . * * Valentin Verdier */ #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--; } } }