amiga-libnix3/extra/sem_post.c

45 lines
900 B
C

/**
* POSIX Semaphores Emulation for AmigaOS
* Copyright (C)2009 Diego Casorran
*
* Public Domain as long this copyright notice is left unchanged.
*
* Implementation conforms to POSIX.1-2008 where possible.
*/
#include "psem.h"
#include <string.h> /* memset */
int sem_post (sem_t *__sem)
{
psem_t *sem = sem2psem(__sem);
ENTER();
POINTER(sem);
if(_PSEM_INVALID(sem))
{
DBG("Invalid sem_t provided, magic=%lx\n",((psem_t *)__sem)->magic);
errno = EINVAL;
return -1;
}
Forbid();
if((_SSEM(sem)->ss_QueueCount != -1)
&& ((_SSEM(sem)->ss_Owner == NULL) || (_SSEM(sem)->ss_Owner == FindTask(NULL))))
{
ReleaseSemaphore(_SSEM(sem));
}
if((sem->flags & SEMF_EXPUNGE) && (_SSEM(sem)->ss_QueueCount == -1))
{
DBG("Delayed expunge will take action now...\n");
psem_destroy(sem);
memset(__sem,_PSEM_ERASEDBIT,sizeof(*__sem));
}
Permit();
LEAVE();
return 0;
}