- Moved the signal semaphore allocation/initialization/deallocation

into a dedicated module. This also has the advantage that it's
  harder to break code by accidentally forgetting to call
  InitSemaphore() after having allocated the memory for it.


git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14853 87f5fb63-7c3d-0410-a384-fd976d0f7a62
This commit is contained in:
Olaf Barthel
2005-03-03 14:20:55 +00:00
parent ebd6cc3639
commit ec3d921f7b
19 changed files with 148 additions and 74 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.68k,v 1.33 2005-03-02 12:57:53 obarthel Exp $
# $Id: GNUmakefile.68k,v 1.34 2005-03-03 14:20:55 obarthel Exp $
#
# :ts=8
#
@@ -317,6 +317,7 @@ C_LIB = \
stdlib_rand_r.o \
stdlib_realloc.o \
stdlib_red_black.o \
stdlib_semaphore.o \
stdlib_setenv.o \
stdlib_setjmp.o \
stdlib_set_errno.o \
+2 -1
View File
@@ -1,5 +1,5 @@
#
# $Id: GNUmakefile.os4,v 1.33 2005-03-02 12:57:53 obarthel Exp $
# $Id: GNUmakefile.os4,v 1.34 2005-03-03 14:20:55 obarthel Exp $
#
# :ts=8
#
@@ -321,6 +321,7 @@ C_LIB = \
stdlib_rand_r.o \
stdlib_realloc.o \
stdlib_red_black.o \
stdlib_semaphore.o \
stdlib_setenv.o \
stdlib_setjmp.o \
stdlib_set_errno.o \
+5
View File
@@ -91,6 +91,11 @@
- The shell command parameter parser now considers the non-breaking
space character (ISO code 160) to be a blank space character, too.
- Moved the signal semaphore allocation/initialization/deallocation
into a dedicated module. This also has the advantage that it's
harder to break code by accidentally forgetting to call
InitSemaphore() after having allocated the memory for it.
c.lib 1.188 (7.2.2005)
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: dirent_data.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $
* $Id: dirent_data.c,v 1.8 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -82,11 +82,9 @@ CLIB_CONSTRUCTOR(__dirent_init)
#if defined(__THREAD_SAFE)
{
dirent_lock = AllocVec(sizeof(*dirent_lock),MEMF_ANY|MEMF_PUBLIC);
dirent_lock = __create_semaphore();
if(dirent_lock == NULL)
goto out;
InitSemaphore(dirent_lock);
}
#endif /* __THREAD_SAFE */
@@ -116,7 +114,7 @@ CLIB_DESTRUCTOR(__dirent_exit)
#if defined(__THREAD_SAFE)
{
FreeVec(dirent_lock);
__delete_semaphore(dirent_lock);
dirent_lock = NULL;
}
#endif /* __THREAD_SAFE */
+2 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: fcntl_open.c,v 1.12 2005-02-28 13:22:53 obarthel Exp $
* $Id: fcntl_open.c,v 1.13 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -331,14 +331,12 @@ open(const char *path_name, int open_flag, ... /* mode_t mode */ )
#if defined(__THREAD_SAFE)
{
fd_lock = AllocVec(sizeof(*fd_lock),MEMF_ANY|MEMF_PUBLIC);
fd_lock = __create_semaphore();
if(fd_lock == NULL)
{
__set_errno(ENOMEM);
goto out;
}
InitSemaphore(fd_lock);
}
#else
{
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: locale_init_exit.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $
* $Id: locale_init_exit.c,v 1.8 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -222,7 +222,7 @@ CLIB_DESTRUCTOR(__locale_exit_destructor)
#if defined(__THREAD_SAFE)
{
FreeVec(locale_lock);
__delete_semaphore(locale_lock);
locale_lock = NULL;
}
#endif /* __THREAD_SAFE */
@@ -241,11 +241,9 @@ CLIB_CONSTRUCTOR(__locale_init_constructor)
#if defined(__THREAD_SAFE)
{
locale_lock = AllocVec(sizeof(*locale_lock),MEMF_ANY|MEMF_PUBLIC);
locale_lock = __create_semaphore();
if(locale_lock == NULL)
goto out;
InitSemaphore(locale_lock);
}
#endif /* __THREAD_SAFE */
+4 -3
View File
@@ -1,5 +1,5 @@
_#
# $Id: smakefile,v 1.27 2005-03-02 12:57:53 obarthel Exp $
#
# $Id: smakefile,v 1.28 2005-03-03 14:20:55 obarthel Exp $
#
# :ts=8
#
@@ -36,7 +36,7 @@ INCLUDE_DIR = V:include
CPU = cpu=060
MATH = define=IEEE_FLOATING_POINT_SUPPORT math=IEEE
SUPPORT = define=UNIX_PATH_SEMANTICS define=SOCKET_SUPPORT define=USERGROUP_SUPPORT \
define=__C_MACROS__
define=__C_MACROS__ define=__THREAD_SAFE
##############################################################################
@@ -395,6 +395,7 @@ STDLIB_OBJ = \
stdlib_dosbase.o \
stdlib_get_errno.o \
stdlib_set_errno.o \
stdlib_semaphore.o \
stdlib_sysbase.o \
stdlib_termination_message.o \
stdlib_threshold.o \
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: socket_accept.c,v 1.7 2005-02-28 13:22:53 obarthel Exp $
* $Id: socket_accept.c,v 1.8 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -106,14 +106,12 @@ accept(int sockfd,struct sockaddr *cliaddr,int *addrlen)
#if defined(__THREAD_SAFE)
{
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
lock = __create_semaphore();
if(lock == NULL)
{
__set_errno(ENOMEM);
goto out;
}
InitSemaphore(lock);
}
#endif /* __THREAD_SAFE */
@@ -141,7 +139,7 @@ accept(int sockfd,struct sockaddr *cliaddr,int *addrlen)
__stdio_unlock();
FreeVec(lock);
__delete_semaphore(lock);
if(__check_abort_enabled)
__check_abort();
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* $Id: socket_hook_entry.c,v 1.10 2005-02-28 13:22:53 obarthel Exp $
* $Id: socket_hook_entry.c,v 1.11 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -125,7 +125,7 @@ __socket_hook_entry(
__fd_unlock(fd);
/* Free the lock semaphore now. */
FreeVec(fd->fd_Lock);
__delete_semaphore(fd->fd_Lock);
/* And that's the last for this file descriptor. */
memset(fd,0,sizeof(*fd));
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: socket_init_exit.c,v 1.10 2005-02-28 13:22:53 obarthel Exp $
* $Id: socket_init_exit.c,v 1.11 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -257,11 +257,9 @@ __socket_init(void)
{
#if defined(__THREAD_SAFE)
{
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
lock = __create_semaphore();
if(lock == NULL)
goto out;
InitSemaphore(lock);
}
#else
{
@@ -287,7 +285,7 @@ __socket_init(void)
{
SHOWMSG("could not duplicate daemon socket");
FreeVec(lock);
__delete_semaphore(lock);
__show_error("Network server streams could not be initialized.");
goto out;
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: socket_socket.c,v 1.5 2005-02-28 13:22:53 obarthel Exp $
* $Id: socket_socket.c,v 1.6 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -73,14 +73,12 @@ socket(int domain,int type,int protocol)
#if defined(__THREAD_SAFE)
{
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
lock = __create_semaphore();
if(lock == NULL)
{
__set_errno(ENOMEM);
goto out;
}
InitSemaphore(lock);
}
#endif /* __THREAD_SAFE */
@@ -106,7 +104,7 @@ socket(int domain,int type,int protocol)
__stdio_unlock();
FreeVec(lock);
__delete_semaphore(lock);
if(__check_abort_enabled)
__check_abort();
+2 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdio_fclose.c,v 1.7 2005-02-28 10:07:30 obarthel Exp $
* $Id: stdio_fclose.c,v 1.8 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -62,8 +62,6 @@ fclose(FILE *stream)
assert( stream != NULL );
assert( file->iob_Lock == NULL || file->iob_Lock->ss_Owner == NULL );
if(__check_abort_enabled)
__check_abort();
@@ -142,7 +140,7 @@ fclose(FILE *stream)
free(file->iob_CustomBuffer);
/* Free the lock semaphore now. */
FreeVec(file->iob_Lock);
__delete_semaphore(file->iob_Lock);
memset(file,0,sizeof(*file));
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdio_fdhookentry.c,v 1.15 2005-02-28 13:22:53 obarthel Exp $
* $Id: stdio_fdhookentry.c,v 1.16 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -356,7 +356,7 @@ __fd_hook_entry(
__fd_unlock(fd);
/* Free the lock semaphore now. */
FreeVec(fd->fd_Lock);
__delete_semaphore(fd->fd_Lock);
/* And that's the last for this file descriptor. */
memset(fd,0,sizeof(*fd));
+5 -8
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdio_init_exit.c,v 1.21 2005-02-28 13:22:53 obarthel Exp $
* $Id: stdio_init_exit.c,v 1.22 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -202,19 +202,16 @@ __stdio_init(void)
{
/* Allocate memory for an arbitration mechanism, then
initialize it. */
stdio_lock = AllocVec(sizeof(*stdio_lock),MEMF_ANY|MEMF_PUBLIC);
fd_lock = AllocVec(sizeof(*fd_lock),MEMF_ANY|MEMF_PUBLIC);
stdio_lock = __create_semaphore();
fd_lock = __create_semaphore();
if(stdio_lock == NULL || fd_lock == NULL)
{
FreeVec(stdio_lock);
FreeVec(fd_lock);
__delete_semaphore(stdio_lock);
__delete_semaphore(fd_lock);
goto out;
}
InitSemaphore(stdio_lock);
InitSemaphore(fd_lock);
}
#else
{
+4 -11
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdio_lock.c,v 1.2 2005-02-28 10:07:31 obarthel Exp $
* $Id: stdio_lock.c,v 1.3 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -70,13 +70,8 @@ __stdio_unlock(void)
void
__stdio_lock_exit(void)
{
assert( stdio_lock == NULL || stdio_lock->ss_Owner == NULL );
if(stdio_lock != NULL)
{
FreeVec(stdio_lock);
stdio_lock = NULL;
}
__delete_semaphore(stdio_lock);
stdio_lock = NULL;
}
/****************************************************************************/
@@ -86,12 +81,10 @@ __stdio_lock_init(void)
{
int result = -1;
stdio_lock = AllocVec(sizeof(*stdio_lock),MEMF_ANY|MEMF_PUBLIC);
stdio_lock = __create_semaphore();
if(stdio_lock == NULL)
goto out;
InitSemaphore(stdio_lock);
result = 0;
out:
+2 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdio_openiob.c,v 1.10 2005-02-28 10:07:31 obarthel Exp $
* $Id: stdio_openiob.c,v 1.11 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -169,11 +169,9 @@ __open_iob(const char *filename, const char *mode, int file_descriptor, int slot
{
/* Allocate memory for an arbitration mechanism, then
initialize it. */
lock = AllocVec(sizeof(*lock),MEMF_ANY|MEMF_PUBLIC);
lock = __create_semaphore();
if(lock == NULL)
goto out;
InitSemaphore(lock);
}
#else
{
+3 -5
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdlib_malloc.c,v 1.9 2005-02-28 10:07:32 obarthel Exp $
* $Id: stdlib_malloc.c,v 1.10 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -358,7 +358,7 @@ __memory_exit(void)
#if defined(__THREAD_SAFE)
{
FreeVec(memory_semaphore);
__delete_semaphore(memory_semaphore);
memory_semaphore = NULL;
}
#endif /* __THREAD_SAFE */
@@ -377,11 +377,9 @@ __memory_init(void)
#if defined(__THREAD_SAFE)
{
memory_semaphore = AllocVec(sizeof(*memory_semaphore),MEMF_ANY|MEMF_PUBLIC);
memory_semaphore = __create_semaphore();
if(memory_semaphore == NULL)
goto out;
InitSemaphore(memory_semaphore);
}
#endif /* __THREAD_SAFE */
+12 -4
View File
@@ -1,5 +1,5 @@
/*
* $Id: stdlib_protos.h,v 1.10 2005-03-03 09:32:09 obarthel Exp $
* $Id: stdlib_protos.h,v 1.11 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
@@ -185,18 +185,26 @@ extern void __stkovf(void);
/* stdlib_termination_message.c */
extern void __print_termination_message(const char * termination_message);
/****************************************************************************/
/* stdlib_set_process_window.c */
APTR __set_process_window(APTR new_window_pointer);
extern APTR __set_process_window(APTR new_window_pointer);
/****************************************************************************/
/* stdlib_set_errno.c */
void __set_errno(int new_errno);
extern void __set_errno(int new_errno);
/****************************************************************************/
/* stdlib_get_errno.c */
int __get_errno(void);
extern int __get_errno(void);
/****************************************************************************/
/* stdlib_semaphore.c */
extern struct SignalSemaphore * __create_semaphore(void);
extern void __delete_semaphore(struct SignalSemaphore * semaphore);
/****************************************************************************/
+86
View File
@@ -0,0 +1,86 @@
/*
* $Id: stdlib_semaphore.c,v 1.1 2005-03-03 14:20:55 obarthel Exp $
*
* :ts=4
*
* Portable ISO 'C' (1994) runtime library for the Amiga computer
* Copyright (c) 2002-2005 by Olaf Barthel <olsen@sourcery.han.de>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of Olaf Barthel nor the names of contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "stdlib_headers.h"
/****************************************************************************/
struct SignalSemaphore *
__create_semaphore(void)
{
struct SignalSemaphore * semaphore;
#if defined(__amigaos4__)
{
semaphore = AllocSysObject(ASOT_SEMAPHORE,NULL);
}
#else
{
semaphore = AllocVec(sizeof(*semaphore),MEMF_ANY|MEMF_PUBLIC);
if(semaphore != NULL)
InitSemaphore(semaphore);
}
#endif /* __amigaos4 */
return(semaphore);
}
/****************************************************************************/
void
__delete_semaphore(struct SignalSemaphore * semaphore)
{
if(semaphore != NULL)
{
#if defined(__amigaos4__)
{
FreeSysObject(ASOT_SEMAPHORE,semaphore);
}
#else
{
assert( semaphore->ss_Owner == NULL );
#if defined(DEBUG)
{
/* Just in case somebody tries to reuse this data
structure; this should produce an alert if
attempted. */
memset(semaphore,0,sizeof(*semaphore));
}
#endif /* DEBUG */
FreeVec(semaphore);
}
#endif /* __amigaos4 */
}
}