bug-commoncpp
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: another Semaphore patch


From: David Sugar
Subject: Re: another Semaphore patch
Date: Mon, 25 Jun 2001 09:07:55 -0400
User-agent: Mozilla/5.0 (X11; U; Linux 2.2.16-9mdk i686; en-US; m18) Gecko/20001013

I happened to like this change request when I first saw it submitted, because it was simple to add and allowed Common C++ to be used on older FreeBSD releases. I changed it a bit from the original to get it out of the headers, though I didn't have a FreeBSD target to test my changes with.

David

Vaclav Haisman wrote:

Hi,
I tryed to compile demo and it failed becuse of undefined reference to
sem_getvalue(). This was caused by Semaphore::getValue() not being inside
#ifdef _SYSV_SEMAPHORES block and haveing only Posix version implemented.
The patch fixes it. I also moved definition of _SYSV_SEMAPHORES before
inclusion of semaphores.h and made the inclusion conditional with
_SYSV_SEMAPHORES. The change in initializers is to get rid of warning:
aggregate has a partly bracketed initializer.


Vaclav Haisman


------------------------------------------------------------------------

Index: semaphore.cpp
===================================================================
RCS file: /cvsroot/cplusplus/CommonC++/posix/semaphore.cpp,v
retrieving revision 1.9
diff -c -r1.9 semaphore.cpp
*** semaphore.cpp       2001/06/23 12:42:17     1.9
--- semaphore.cpp       2001/06/24 13:31:27
***************
*** 76,100 ****
void Semaphore::Wait(void)
  {
!       struct sembuf ops[] = {0, -1, 0};
        
        semop(_semaphore, ops, 1);
  }
bool Semaphore::TryWait(void)
  {
!       struct sembuf ops[] = {0, -1, IPC_NOWAIT};
        
        return (semop(_semaphore, ops, 1) == EAGAIN) ? false : true;
  }
void Semaphore::Post(void)
  {
!       struct sembuf ops[] = {0, 1, 0};
semop(_semaphore, ops, 1);
  }
#else Semaphore::Semaphore(size_t resource) --- 76,105 ---- void Semaphore::Wait(void)
  {
!       struct sembuf ops[] = {{0, -1, 0}};
        
        semop(_semaphore, ops, 1);
  }
bool Semaphore::TryWait(void)
  {
!       struct sembuf ops[] = {{0, -1, IPC_NOWAIT}};
        
        return (semop(_semaphore, ops, 1) == EAGAIN) ? false : true;
  }
void Semaphore::Post(void)
  {
!       struct sembuf ops[] = {{0, 1, 0}};
semop(_semaphore, ops, 1);
  }
+ int Semaphore::getValue(void)
+ {
+       return semctl(_semaphore,0,GETVAL);
+ }
+ #else Semaphore::Semaphore(size_t resource) ***************
*** 104,111 ****
                        throw(this);
  }
- #endif - #ifdef __linux__ Semaphore::~Semaphore()
--- 109,114 ----
***************
*** 128,141 ****
        return (sem_trywait(&_semaphore) == 0) ? true : false;
  }
- #endif - int Semaphore::getValue(void)
  {
        int value;
        sem_getvalue(&_semaphore, &value);
        return value;
  }
/** EMACS **
   * Local variables:
--- 131,145 ----
        return (sem_trywait(&_semaphore) == 0) ? true : false;
  }
int Semaphore::getValue(void)
  {
        int value;
        sem_getvalue(&_semaphore, &value);
        return value;
  }
+ + #endif
+ #endif
/** EMACS **
   * Local variables:
Index: thread.h
===================================================================
RCS file: /cvsroot/cplusplus/CommonC++/posix/thread.h,v
retrieving revision 1.33
diff -c -r1.33 thread.h
*** thread.h    2001/06/22 18:38:19     1.33
--- thread.h    2001/06/24 13:31:28
***************
*** 61,70 ****
--- 61,76 ----
  #include <cc++/config.h>
  #endif
+ #if defined(__FreeBSD__) && __FreeBSD__ <= 3
+ #define       _SYSV_SEMAPHORES
+ #endif
+ #ifndef HAVE_PTHREAD_H
  #include <pthread.h>
+ #ifndef _SYSV_SEMAPHORES
  #include <semaphore.h>
  #endif
+ #endif
#ifndef __CCXX_MACROS_H__
  #include <cc++/macros.h>
***************
*** 78,87 ****
  #include <signal.h>
  #include <setjmp.h>
  #include <unistd.h>
- - #if defined(__FreeBSD__) && __FreeBSD__ <= 3
- #define       _SYSV_SEMAPHORES
- #endif
#ifdef __linux__
  #define _SIG_THREAD_STOPCONT
--- 84,89 ----
moresemaphores.diff

Content-Type:

TEXT/PLAIN
Content-Encoding:

BASE64




reply via email to

[Prev in Thread] Current Thread [Next in Thread]