Skip to content
Snippets Groups Projects
Commit 358e703c authored by deuce's avatar deuce
Browse files

Basic semaphore emulation and defines for GNU/Hurd

parent 122d6f4f
No related branches found
No related tags found
No related merge requests found
...@@ -123,7 +123,7 @@ void DLLCALL unix_beep(int freq, int dur) ...@@ -123,7 +123,7 @@ void DLLCALL unix_beep(int freq, int dur)
{ {
static int console_fd=-1; static int console_fd=-1;
#if !defined(__OpenBSD__) #if !defined(__OpenBSD__) && !defined(__GNU__)
if(console_fd == -1) if(console_fd == -1)
console_fd = open("/dev/console", O_NOCTTY); console_fd = open("/dev/console", O_NOCTTY);
......
...@@ -106,6 +106,8 @@ extern "C" { ...@@ -106,6 +106,8 @@ extern "C" {
#define PLATFORM_DESC "Solaris" #define PLATFORM_DESC "Solaris"
#elif defined(__sun__) #elif defined(__sun__)
#define PLATFORM_DESC "SunOS" #define PLATFORM_DESC "SunOS"
#elif defined(__gnu__)
#define PLATFORM_DESC "GNU/Hurd"
#elif defined(__unix__) #elif defined(__unix__)
#define PLATFORM_DESC "Unix" #define PLATFORM_DESC "Unix"
#else #else
......
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include "genwrap.h"
#include "sem.h"
int sem_init(sem_t *sem, int pshared, unsigned int value) {
sem=malloc(sizeof(sem_t));
if(sem==NULL) {
errno=ENOSPC;
return(-1);
}
if(pipe((int *)sem)) {
errno=EPERM;
return(-1);
}
return(0);
}
int sem_destroy(sem_t *sem) {
close(sem->read);
close(sem->write);
sem=NULL;
return(0);
}
int sem_post(sem_t *sem) {
if(sem==NULL) {
errno=EINVAL;
return(-1);
}
write(sem->write,"-",1)==1;
return(0);
}
int sem_wait(sem_t *sem) {
char buf;
if(sem==NULL) {
errno=EINVAL;
return(-1);
}
while(read(sem->read,&buf,1)<1)
SLEEP(1);
return(0);
}
typedef struct {
int read;
int write;
} sem_t;
int sem_init(sem_t *sem, int pshared, unsigned int value);
int sem_destroy(sem_t *sem);
int sem_post(sem_t *sem);
int sem_wait(sem_t *sem);
...@@ -48,7 +48,11 @@ extern "C" { ...@@ -48,7 +48,11 @@ extern "C" {
#if defined(__unix__) #if defined(__unix__)
#include <pthread.h> /* POSIX threads and mutexes */ #include <pthread.h> /* POSIX threads and mutexes */
#if defined(_NEED_SEM)
#include "sem.h"
#else
#include <semaphore.h> /* POSIX semaphores */ #include <semaphore.h> /* POSIX semaphores */
#endif
ulong _beginthread(void( *start_address )( void * ) ulong _beginthread(void( *start_address )( void * )
,unsigned stack_size, void *arglist); ,unsigned stack_size, void *arglist);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment