2013-11-26 18:15:31 +01:00
|
|
|
/*
|
|
|
|
Minetest
|
2015-04-07 12:13:12 +02:00
|
|
|
Copyright (C) 2013 sapier <sapier AT gmx DOT net>
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License along
|
|
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
#ifndef THREADING_SEMAPHORE_H
|
|
|
|
#define THREADING_SEMAPHORE_H
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
#if defined(_WIN32)
|
|
|
|
#include <windows.h>
|
2015-01-20 10:41:51 +01:00
|
|
|
#elif defined(__MACH__) && defined(__APPLE__)
|
2015-04-07 12:13:12 +02:00
|
|
|
#include <mach/semaphore.h>
|
2013-11-26 18:15:31 +01:00
|
|
|
#else
|
2015-04-07 12:13:12 +02:00
|
|
|
#include <semaphore.h>
|
2013-11-26 18:15:31 +01:00
|
|
|
#endif
|
|
|
|
|
2015-10-27 07:51:43 +01:00
|
|
|
#include "basicmacros.h"
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
class Semaphore {
|
|
|
|
public:
|
|
|
|
Semaphore(int val=0);
|
|
|
|
~Semaphore();
|
2013-11-26 18:15:31 +01:00
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
void post(unsigned int num=1);
|
|
|
|
void wait();
|
|
|
|
bool wait(unsigned int time_ms);
|
2013-11-26 18:15:31 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
#if defined(WIN32)
|
2015-04-07 12:13:12 +02:00
|
|
|
HANDLE semaphore;
|
2015-01-20 10:41:51 +01:00
|
|
|
#elif defined(__MACH__) && defined(__APPLE__)
|
2015-04-07 12:13:12 +02:00
|
|
|
semaphore_t semaphore;
|
2013-11-26 18:15:31 +01:00
|
|
|
#else
|
2015-04-07 12:13:12 +02:00
|
|
|
sem_t semaphore;
|
2013-11-26 18:15:31 +01:00
|
|
|
#endif
|
2015-10-27 07:51:43 +01:00
|
|
|
|
|
|
|
DISABLE_CLASS_COPY(Semaphore);
|
2013-11-26 18:15:31 +01:00
|
|
|
};
|
|
|
|
|
2015-04-07 12:13:12 +02:00
|
|
|
#endif
|
2014-06-26 20:30:22 +02:00
|
|
|
|