Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


sal/osl/unx/semaphor.c contains two separate implementations of the
osl*Semaphore synchronization functions:

- a pthread one (used by default)
- an alternative one based on System V semaphores

The alternative System V implementation is only used if the macro
OSL_USE_SYS_V_SEMAPHORE is defined, which is never the case.

Since it is never used, we may as well remove it. Patch attached.

I thought it would be best to not remove such an important piece of code
without some discussion first.

-- 
Francois Tigeot
From fb6b17a9e8198d6a81367af7aca48757f2ba2bc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Tigeot?= <ftigeot@wolfpond.org>
Date: Sun, 5 Feb 2012 19:04:46 +0100
Subject: [PATCH] OSL_USE_SYS_V_SEMAPHORE is never defined

* Remove the System V semaphore implementation variant

* POSIX thread-local code was always used for synchronization
  primitives anyway
---
 sal/osl/unx/semaphor.c |  181 ------------------------------------------------
 1 files changed, 0 insertions(+), 181 deletions(-)

diff --git a/sal/osl/unx/semaphor.c b/sal/osl/unx/semaphor.c
index 7cb375f..b38113b 100644
--- a/sal/osl/unx/semaphor.c
+++ b/sal/osl/unx/semaphor.c
@@ -32,8 +32,6 @@
 #include <osl/semaphor.h>
 #include <osl/diagnose.h>
 
-#ifndef OSL_USE_SYS_V_SEMAPHORE
-
 /* This is the (default) POSIX thread-local semaphore variant */
 
 /*
@@ -134,183 +132,4 @@ sal_Bool SAL_CALL osl_releaseSemaphore(oslSemaphore Semaphore) {
     return sal_False;
 }
 
-#else /* OSL_USE_SYS_V_SEMAPHORE */
-
-/*******************************************************************************/
-
-/* This is the SYS V private semaphore variant */
-
-/*
-    Implemetation notes:
-    The void* represented by oslSemaphore is used
-    as a pointer to an osl_TSemImpl struct
-*/
-
-
-#if defined(NETBSD)
-union semun {
-        int     val;            /* value for SETVAL */
-        struct  semid_ds *buf;  /* buffer for IPC_STAT & IPC_SET */
-        u_short *array;         /* array for GETALL & SETALL */
-};
-#endif
-
-typedef struct _osl_TSemImpl
-{
-  int m_Id;
-
-} osl_TSemImpl;
-
-/*****************************************************************************/
-/* osl_createSemaphore  */
-/*****************************************************************************/
-oslSemaphore SAL_CALL osl_createSemaphore(sal_uInt32 initialCount)
-{
-    union semun arg;
-
-    oslSemaphore Semaphore;
-    osl_TSemImpl* pSem;
-
-    Semaphore= malloc(sizeof(osl_TSemImpl));
-    OSL_POSTCOND(Semaphore, "malloc failed\n");     /* ptr valid? */
-
-    pSem= (osl_TSemImpl*)Semaphore;
-
-
-    /* unnamed (private) semaphore */
-
-       pSem->m_Id= semget(IPC_PRIVATE, 1, 0666 | IPC_CREAT);
-
-
-    /* create failed? */
-    if (pSem->m_Id < 0)
-    {
-        OSL_TRACE("osl_createSemaphore failed (semget). Errno: %d; %s\n",
-               errno,
-               strerror(errno));
-
-        free(Semaphore);
-        return 0;
-    }
-
-    /* set initial count */
-
-    arg.val= initialCount;
-
-    if(semctl(pSem->m_Id, 0, SETVAL, arg) < 0)
-    {
-        OSL_TRACE("osl_createSemaphore failed (semctl(SETVAL)). Errno: %d; %s\n",
-               errno,
-               strerror(errno));
-
-        if(semctl(pSem->m_Id, 0, IPC_RMID, arg) < 0)
-        {
-            OSL_TRACE("semctl(IPC_RMID) failed. Errno: %d; %s", errno, strerror(errno));
-        }
-
-        free(Semaphore);
-        return 0;
-    }
-
-
-    return Semaphore;
-}
-
-/*****************************************************************************/
-/* osl_destroySemaphore  */
-/*****************************************************************************/
-void SAL_CALL osl_destroySemaphore(oslSemaphore Semaphore) {
-
-    if(Semaphore)           /* ptr valid? */
-    {
-        union semun arg;
-
-        osl_TSemImpl* pSem= (osl_TSemImpl*)Semaphore;
-
-        if(semctl(pSem->m_Id, 0, IPC_RMID, arg) < 0)
-
-        {
-            OSL_TRACE("osl_destroySemaphore failed. (semctl(IPC_RMID)). Errno: %d; %s\n",
-                   errno,
-                   strerror(errno));
-        }
-
-        free(Semaphore);
-    }
-}
-
-/*****************************************************************************/
-/* osl_acquireSemaphore  */
-/*****************************************************************************/
-sal_Bool SAL_CALL osl_acquireSemaphore(oslSemaphore Semaphore) {
-
-    /* abort in debug mode */
-    OSL_PRECOND(Semaphore != 0, "Semaphore not created\n");
-
-
-    if (Semaphore != 0)     /* be tolerant in release mode */
-    {
-        struct sembuf op;
-        osl_TSemImpl* pSem= (osl_TSemImpl*)Semaphore;
-
-        op.sem_num= 0;
-        op.sem_op= -1;
-        op.sem_flg= SEM_UNDO;
-
-        return semop(pSem->m_Id, &op, 1) >= 0;
-
-    }
-
-    return sal_False;
-}
-
-/*****************************************************************************/
-/* osl_tryToAcquireSemaphore  */
-/*****************************************************************************/
-sal_Bool SAL_CALL osl_tryToAcquireSemaphore(oslSemaphore Semaphore) {
-
-    /* abort in debug mode */
-    OSL_PRECOND(Semaphore != 0, "Semaphore not created\n");
-
-    if (Semaphore != 0)     /* be tolerant in release mode */
-    {
-        struct sembuf op;
-        osl_TSemImpl* pSem= (osl_TSemImpl*)Semaphore;
-
-        op.sem_num= 0;
-        op.sem_op= -1;
-        op.sem_flg= SEM_UNDO | IPC_NOWAIT;
-
-        return semop(pSem->m_Id, &op, 1) >= 0;
-    }
-
-    return sal_False;
-}
-
-/*****************************************************************************/
-/* osl_releaseSemaphore  */
-/*****************************************************************************/
-sal_Bool SAL_CALL osl_releaseSemaphore(oslSemaphore Semaphore)
-{
-
-    /* abort in debug mode */
-    OSL_PRECOND(Semaphore != 0, "Semaphore not created\n");
-
-    if (Semaphore != 0)         /* be tolerant in release mode */
-    {
-        struct sembuf op;
-        osl_TSemImpl* pSem= (osl_TSemImpl*)Semaphore;
-
-        op.sem_num= 0;
-        op.sem_op= 1;
-        op.sem_flg= SEM_UNDO;
-
-        return semop(pSem->m_Id, &op, 1) >= 0;
-    }
-
-    return sal_False;
-}
-
-#endif /* OSL_USE_SYS_V_SEMAPHORE */
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-- 
1.7.7.2


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.