bug-gnulib
[Top][All Lists]
Advanced

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

Re: checkin of glthread/glcond modules


From: Bruno Haible
Subject: Re: checkin of glthread/glcond modules
Date: Sun, 17 Aug 2008 17:28:00 +0200
User-agent: KMail/1.5.4

Yoann Vandoorselaere wrote:
> Here is an updated patch, that fixes several naming issue and implement
> the yield module.

Thanks. I added the module 'cond' with a few modifications (attached):
  - Changed the module description to say "Condition variables".
  - Fixed specification of gl_cond_* macros. gl_cond_init and gl_cond_destroy
    were missing, and the number of arguments of gl_cond_wait and
    gl_cond_timedwait were wrong.
  - Moved large inline functions to a .c file, for smaller code size.
  - Added a gl_cond_timedwait macro that returns bool.

Bruno


2008-08-17  Yoann Vandoorselaere  <address@hidden>

        New module 'cond'.
        * modules/cond: New file.
        * lib/glthread/cond.h: New file.
        * lib/glthread/cond.c: New file.
        * m4/cond.m4: New file.
        * MODULES.html.sh (Multithreading): Add cond.

*** modules/cond        2008-08-17 17:11:17.000000000 +0200
--- /packages/GNULIB/gnulib-git/modules/cond    2008-08-17 17:05:49.000000000 
+0200
***************
*** 1,18 ****
  Description:
! Condition in multithreaded situations.
  
  Files:
  lib/glthread/cond.h
  m4/cond.m4
  
  Depends-on:
  lock
  
  configure.ac:
  gl_COND
  
  Makefile.am:
! lib_SOURCES += glthread/cond.h
  
  Include:
  "glthread/cond.h"
--- 1,21 ----
  Description:
! Condition variables for multithreading.
  
  Files:
  lib/glthread/cond.h
+ lib/glthread/cond.c
  m4/cond.m4
  
  Depends-on:
+ threadlib
  lock
+ stdbool
  
  configure.ac:
  gl_COND
  
  Makefile.am:
! lib_SOURCES += glthread/cond.h glthread/cond.c
  
  Include:
  "glthread/cond.h"
*** m4/cond.m4  2008-08-17 17:11:16.000000000 +0200
--- /packages/GNULIB/gnulib-git/m4/cond.m4      2008-08-17 17:12:34.000000000 
+0200
***************
*** 1,11 ****
! # glcond.m4 serial 1 (gettext-0.15)
! dnl Copyright (C) 2005 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
  
  AC_DEFUN([gl_COND],
  [
!   AC_C_INLINE()
!   AC_REQUIRE([gl_LOCK])
  ])
--- 1,11 ----
! # cond.m4 serial 1
! dnl Copyright (C) 2008 Free Software Foundation, Inc.
  dnl This file is free software; the Free Software Foundation
  dnl gives unlimited permission to copy and/or distribute it,
  dnl with or without modifications, as long as this notice is preserved.
  
  AC_DEFUN([gl_COND],
  [
!   AC_REQUIRE([gl_THREADLIB])
!   AC_C_INLINE
  ])
*** lib/glthread/cond.h 2008-08-17 17:11:16.000000000 +0200
--- /packages/GNULIB/gnulib-git/lib/glthread/cond.h     2008-08-17 
17:17:09.000000000 +0200
***************
*** 1,4 ****
! /* Condition waiting in multithreaded situations.
     Copyright (C) 2005-2008 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
--- 1,4 ----
! /* Condition variables for multithreading.
     Copyright (C) 2005-2008 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
***************
*** 29,38 ****
       Type:                gl_cond_t
       Declaration:         gl_cond_define(extern, name)
       Initializer:         gl_cond_define_initialized(, name)
!      Waiting:             gl_cond_wait(name)
!      Timed wait:          gl_cond_timedwait(name, tv)
!      Signaling:           gl_cond_signal(name)
!      Broadcasting:        gl_cond_broadcast(name)
  */
  
  
--- 29,48 ----
       Type:                gl_cond_t
       Declaration:         gl_cond_define(extern, name)
       Initializer:         gl_cond_define_initialized(, name)
!      Initialization:      gl_cond_init (name);
!      Waiting:             gl_cond_wait (name, lock);
!      Timed wait:          bool timedout = gl_cond_timedwait (name, lock, 
abstime);
!                           where lock is a gl_lock_t variable (cf. 
<glthread/lock.h>)
!      Signaling:           gl_cond_signal (name);
!      Broadcasting:        gl_cond_broadcast (name);
!      De-initialization:   gl_cond_destroy (name);
!    Equivalent functions with control of error handling:
!      Initialization:      err = glthread_cond_init (&name);
!      Waiting:             err = glthread_cond_wait (&name);
!      Timed wait:          err = glthread_cond_timedwait (&name, &lock, 
abstime);
!      Signaling:           err = glthread_cond_signal (&name);
!      Broadcasting:        err = glthread_cond_broadcast (&name);
!      De-initialization:   err = glthread_cond_destroy (&name);
  */
  
  
***************
*** 40,45 ****
--- 50,57 ----
  #define _GLTHREAD_COND_H
  
  #include <errno.h>
+ #include <stdbool.h>
+ 
  #include "glthread/lock.h"
  
  /* ========================================================================= 
*/
***************
*** 89,94 ****
--- 101,109 ----
  #  pragma weak pthread_cond_signal
  #  pragma weak pthread_cond_broadcast
  #  pragma weak pthread_cond_destroy
+ #  ifndef pthread_self
+ #   pragma weak pthread_self
+ #  endif
  
  #  if !PTHREAD_IN_USE_DETECTION_HARD
  #   pragma weak pthread_cancel
***************
*** 103,109 ****
  
  # endif
  
- 
  /* -------------------------- gl_cond_t datatype -------------------------- */
  
  typedef pthread_cond_t gl_cond_t;
--- 118,123 ----
***************
*** 117,124 ****
      (pthread_in_use () ? pthread_cond_init (COND, NULL) : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pthread_in_use () ? pthread_cond_wait (COND, LOCK) : 0)
! # define glthread_cond_timedwait(COND, LOCK, TS) \
!     (pthread_in_use () ? pthread_cond_timedwait (COND, LOCK, TS) : 0)
  # define glthread_cond_signal(COND) \
      (pthread_in_use () ? pthread_cond_signal (COND) : 0)
  # define glthread_cond_broadcast(COND) \
--- 131,138 ----
      (pthread_in_use () ? pthread_cond_init (COND, NULL) : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pthread_in_use () ? pthread_cond_wait (COND, LOCK) : 0)
! # define glthread_cond_timedwait(COND, LOCK, ABSTIME) \
!     (pthread_in_use () ? pthread_cond_timedwait (COND, LOCK, ABSTIME) : 0)
  # define glthread_cond_signal(COND) \
      (pthread_in_use () ? pthread_cond_signal (COND) : 0)
  # define glthread_cond_broadcast(COND) \
***************
*** 150,155 ****
--- 164,170 ----
  #  pragma weak pth_cond_notify
  #  pragma weak pth_event
  #  pragma weak pth_timeout
+ 
  #  pragma weak pth_cancel
  #  define pth_in_use() (pth_cancel != NULL)
  
***************
*** 172,206 ****
      (pth_in_use () && !pth_cond_init (COND) ? errno : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pth_in_use () && !pth_cond_await (COND, LOCK, NULL) ? errno : 0)
! 
! static inline int
! glthread_cond_timedwait (gl_cond_t * cond,
!                          gl_lock_t * lock,
!                          struct timespec *ts)
! {
!   int ret, status;
!   pth_event_t ev;
! 
!   if (!pth_in_use ())
!     return 0;
! 
!   ev = pth_event (PTH_EVENT_TIME, pth_time (ts->tv_sec, ts->tv_nsec / 1000));
!   ret = pth_cond_await (cond, lock, ev);
! 
!   status = pth_event_status (ev);
!   pth_event_free (ev, PTH_FREE_THIS);
! 
!   if (status == PTH_STATUS_OCCURRED)
!     return ETIMEDOUT;
! 
!   return ret;
! }
! 
  # define glthread_cond_signal(COND) \
      (pth_in_use () && !pth_cond_notify (COND, FALSE) ? errno : 0)
  # define glthread_cond_broadcast(COND) \
      (pth_in_use () && !pth_cond_notify (COND, TRUE) ? errno : 0)
  # define glthread_cond_destroy(COND) 0
  
  #endif
  
--- 187,200 ----
      (pth_in_use () && !pth_cond_init (COND) ? errno : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pth_in_use () && !pth_cond_await (COND, LOCK, NULL) ? errno : 0)
! # define glthread_cond_timedwait(COND, LOCK, ABSTIME) \
!     (pth_in_use () ? glthread_cond_timedwait_multithreaded (COND, LOCK, 
ABSTIME) : 0)
  # define glthread_cond_signal(COND) \
      (pth_in_use () && !pth_cond_notify (COND, FALSE) ? errno : 0)
  # define glthread_cond_broadcast(COND) \
      (pth_in_use () && !pth_cond_notify (COND, TRUE) ? errno : 0)
  # define glthread_cond_destroy(COND) 0
+ extern int glthread_cond_timedwait_multithreaded (gl_cond_t *cond, gl_lock_t 
*lock, struct timespec *abstime);
  
  #endif
  
***************
*** 252,259 ****
      (pthread_in_use () ? cond_init (COND, USYNC_THREAD, NULL) : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pthread_in_use () ? cond_wait (COND, LOCK) : 0)
! # define glthread_cond_timedwait(COND, LOCK, TS) \
!     (pthread_in_use () ? cond_timedwait (COND, LOCK, TS) : 0)
  # define glthread_cond_signal(COND) \
      (pthread_in_use () ? cond_signal (COND) : 0)
  # define glthread_cond_broadcast(COND) \
--- 246,253 ----
      (pthread_in_use () ? cond_init (COND, USYNC_THREAD, NULL) : 0)
  # define glthread_cond_wait(COND, LOCK) \
      (pthread_in_use () ? cond_wait (COND, LOCK) : 0)
! # define glthread_cond_timedwait(COND, LOCK, ABSTIME) \
!     (pthread_in_use () ? cond_timedwait (COND, LOCK, ABSTIME) : 0)
  # define glthread_cond_signal(COND) \
      (pthread_in_use () ? cond_signal (COND) : 0)
  # define glthread_cond_broadcast(COND) \
***************
*** 273,287 ****
  # define gl_cond_define(STORAGECLASS, NAME)
  # define gl_cond_define_initialized(STORAGECLASS, NAME)
  # define glthread_cond_init(COND) 0
  # define glthread_cond_signal(COND) 0
  # define glthread_cond_broadcast(COND) 0
- # define glthread_cond_wait(COND, LOCK) 0
- # define glthread_cond_timedwait(COND, LOCK, TS) 0
  # define glthread_cond_destroy(COND) 0
  
  #endif
  
- 
  /* ========================================================================= 
*/
  
  /* Macros with built-in error handling.  */
--- 267,280 ----
  # define gl_cond_define(STORAGECLASS, NAME)
  # define gl_cond_define_initialized(STORAGECLASS, NAME)
  # define glthread_cond_init(COND) 0
+ # define glthread_cond_wait(COND, LOCK) 0
+ # define glthread_cond_timedwait(COND, LOCK, ABSTIME) 0
  # define glthread_cond_signal(COND) 0
  # define glthread_cond_broadcast(COND) 0
  # define glthread_cond_destroy(COND) 0
  
  #endif
  
  /* ========================================================================= 
*/
  
  /* Macros with built-in error handling.  */
***************
*** 300,305 ****
--- 293,310 ----
           abort ();                            \
       }                                        \
     while (0)
+ #define gl_cond_timedwait(COND, LOCK, ABSTIME) \
+   gl_cond_timedwait_func (&COND, &LOCK, ABSTIME)
+ static inline bool
+ gl_cond_timedwait_func (gl_cond_t *cond, gl_lock_t *lock, struct timespec 
*abstime)
+ {
+   int err = glthread_cond_timedwait (cond, lock, abstime);
+   if (err == ETIMEDOUT)
+     return true;
+   if (err != 0)
+     abort ();
+   return false;
+ }
  #define gl_cond_signal(COND)             \
     do                                    \
       {                                   \
*** /dev/null   2003-09-23 19:59:22.000000000 +0200
--- /packages/GNULIB/gnulib-git/lib/glthread/cond.c     2008-08-17 
17:01:52.000000000 +0200
***************
*** 0 ****
--- 1,52 ----
+ /* Condition variables for multithreading.
+    Copyright (C) 2008 Free Software Foundation, Inc.
+ 
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2, or (at your option)
+    any later version.
+ 
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+ 
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software Foundation,
+    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+ 
+ /* Written by Yoann Vandoorselaere <address@hidden>, 2008.  */
+ 
+ #include <config.h>
+ 
+ #include "glthread/cond.h"
+ 
+ /* ========================================================================= 
*/
+ 
+ #if USE_PTH_THREADS
+ 
+ /* -------------------------- gl_cond_t datatype -------------------------- */
+ 
+ int
+ glthread_cond_timedwait_multithreaded (gl_cond_t *cond,
+                                      gl_lock_t *lock,
+                                      struct timespec *abstime)
+ {
+   int ret, status;
+   pth_event_t ev;
+ 
+   ev = pth_event (PTH_EVENT_TIME, pth_time (abstime->tv_sec, abstime->tv_nsec 
/ 1000));
+   ret = pth_cond_await (cond, lock, ev);
+ 
+   status = pth_event_status (ev);
+   pth_event_free (ev, PTH_FREE_THIS);
+ 
+   if (status == PTH_STATUS_OCCURRED)
+     return ETIMEDOUT;
+ 
+   return ret;
+ }
+ 
+ #endif
+ 
+ /* ========================================================================= 
*/





reply via email to

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