[php-i18n-commits] cvs commit: libmbfl/mbfl mbfl_mutex.c

Back to archive index

Moriyoshi Koizumi moriy****@users*****
2003年 1月 3日 (金) 21:56:25 JST


moriyoshi    03/01/03 21:56:25

  Modified:    .        configure.in
               mbfl     mbfl_mutex.c
  Log:
  Added missing ";;" to configure.in
  BeOS native thread support
  
  Revision  Changes    Path
  1.8       +5 -0      libmbfl/configure.in
  
  Index: configure.in
  ===================================================================
  RCS file: /cvsroot/php-i18n/libmbfl/configure.in,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- configure.in	3 Jan 2003 09:19:03 -0000	1.7
  +++ configure.in	3 Jan 2003 12:56:25 -0000	1.8
  @@ -86,8 +86,13 @@
         ;;
       "win32native" [)]
         AC_DEFINE([USE_WIN32_NATIVE_THREAD],[1],[Define to 1 if win32 native thread is adopted for threading])
  +      ;;
       "gnupth" [)]
         AC_DEFINE([USE_GNUPTH],[1],[Define to 1 if GNUPth is adopted for threading])
  +      ;;
  +    "benative" [)]
  +      AC_DEFINE([USE_BE_NATIVE_THREAD],[1],[Define to 1 if BeOS native thread is adopted for threading])
  +      ;;
     esac
   fi
   
  
  
  
  1.4       +72 -2     libmbfl/mbfl/mbfl_mutex.c
  
  Index: mbfl_mutex.c
  ===================================================================
  RCS file: /cvsroot/php-i18n/libmbfl/mbfl/mbfl_mutex.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- mbfl_mutex.c	3 Jan 2003 09:19:04 -0000	1.3
  +++ mbfl_mutex.c	3 Jan 2003 12:56:25 -0000	1.4
  @@ -29,11 +29,21 @@
   #endif
   #include <windows.h>
   #else
  -#error "You can't enable win32 native thread support in this build" 
  +#error "Win32 native thread support cannot be enabled in this build" 
   #endif
   #elif USE_GNUPTH
   #if defined(HAVE_GNUPTH)
   #include <pth.h>
  +#else
  +#error "GNUPth is not available"
  +#endif
  +#elif USE_BE_NATIVE_THREAD
  +#if defined(__BEOS__)
  +#include <kernel/OS.h>
  +#include <support/TLS.h>
  +#include <errno.h>
  +#else
  +#error "BeOS native thread support cannot be enabled in this build"
   #endif
   #endif
   
  @@ -42,6 +52,14 @@
   #include "mbfl_allocators.h"
   #include "mbfl_mutex.h"
   
  +#if USE_BE_NATIVE_THREAD
  +typedef struct _mbfl_be_mtx {
  +	sem_id lock_sem;
  +	int lock_cnt;
  +	thread_id owner_thid;
  +} mbfl_be_mtx; 
  +#endif
  +
   MBFLAPI mbfl_mutex *mbfl_mutex_new(void)
   {
   #if defined(USE_PTHREAD)
  @@ -72,6 +90,19 @@
   		return NULL;
   	}
   	pth_mutex_init(mutex);
  +#elif defined(USE_BE_NATIVE_THREAD)
  +	mbfl_be_mtx *mutex = NULL;
  +	
  +	if ((mutex = mbfl_malloc(sizeof(mbfl_be_mtx))) == NULL) {
  +		return NULL;
  +	}
  +	
  +	if ((mutex->lock_sem = create_sem(0, "mbfl_mutex")) < B_NO_ERROR) {
  +		mbfl_free(mutex);
  +		return NULL;
  +	}
  +	mutex->lock_cnt = 0;
  +	mutex->owner = 0; /* 0 should be an invalid thread id */
   #endif
   	return (mbfl_mutex *)mutex;
   }
  @@ -97,6 +128,28 @@
   		default:
   			return -1;
   	}
  +#elif defined(USE_BE_NATIVE_THREAD)
  +	thread_id cur_thid;
  +
  +	if ((cur_thid = find_thread(NULL)) == 0) {
  +		/* should not happen */
  +		return -1;
  +	}
  +
  +	/* increase the lock cnt */
  +	if (atomic_add(&(((mbfl_be_mtx *)mutex)->lock_cnt), 1) > 0) {
  + 		/* we don't have to acquire a semaphore without a obvious need for
  +		   synchronization; for the sake of performance */ 
  +
  +		/* do some polling here */
  +		/* FIXME: this code is not dead-lock aware in contrast to POSIX
  +		   implementation */
  +		if (acquire_sem(((mbfl_be_mtx *)mutex)->lock_sem) != B_NO_ERROR) {
  +			/* should not happen */
  +			return -1;
  +		}
  +	}
  +	mutex->owner_thid = cur_thid;
   #endif
   	return 0;
   }
  @@ -125,9 +178,24 @@
   		default:
   			return -1;
   	}
  +#elif defined(USE_BE_NATIVE_THREAD)
  +	thread_id cur_thid;
  +
  +	if ((cur_thid = find_thread(NULL)) == 0) {
  +		/* should not happen */
  +		return -1;
  +	}
  +
  +	/* decrease the lock cnt (lock_cnt + (-1))*/
  +	if (atomic_add(&(((mbfl_be_mtx *)mutex)->lock_cnt), -1) > 0) {
  +		if (release_sem(((mbfl_be_mtx *)mutex)->lock_sem) != B_NO_ERROR) {
  +			/* scary... this must be a sort of panic! */
  +			return -1;
  +		}
  +	}
   #endif
   	return 0;
  -}
  +n}
   
   MBFLAPI void mbfl_mutex_free(mbfl_mutex *mutex)
   {
  @@ -137,6 +205,8 @@
   	DeleteCriticalSection((CRITICAL_SECTION *)mutex);
   #elif defined(USE_GNUPTH)
   	/* GNU Pth mutexes don't need destruction */
  +#elif defined(USE_BE_NATIVE_THREAD)
  +	delete_sem(((mbfl_be_mtx *)mutex)->lock_sem);
   #endif
   	mbfl_free(mutex);
   }
  
  
  



php-i18n-commits メーリングリストの案内
Back to archive index