summaryrefslogtreecommitdiff
path: root/Objective-C
diff options
context:
space:
mode:
authorMatthias Benkard <code@mail.matthias.benkard.de>2008-02-16 14:32:36 +0100
committerMatthias Benkard <code@mail.matthias.benkard.de>2008-02-16 14:32:36 +0100
commit82f36a23a52b6e25703a70c40568feb0cd0e3fd2 (patch)
tree43b3d019be16bc96514f415b514e005ff0f72f96 /Objective-C
parent2a61fbdd27d9a3ff4dea7b2f1f193668b13f2f1b (diff)
Use NSRecursiveLock rather than POSIX semaphores.
darcs-hash:247b2833d2767a5c432fc1f64155ed5ff2b8763f
Diffstat (limited to 'Objective-C')
-rw-r--r--Objective-C/PyObjC/libffi_support.m3
-rw-r--r--Objective-C/libobjcl.h26
-rw-r--r--Objective-C/libobjcl.m65
3 files changed, 19 insertions, 75 deletions
diff --git a/Objective-C/PyObjC/libffi_support.m b/Objective-C/PyObjC/libffi_support.m
index 4bc1137..b98201f 100644
--- a/Objective-C/PyObjC/libffi_support.m
+++ b/Objective-C/PyObjC/libffi_support.m
@@ -13,8 +13,9 @@
#include "pyobjc.h"
#import <Foundation/NSDictionary.h>
-#import <Foundation/NSString.h>
#import <Foundation/NSHost.h>
+#import <Foundation/NSString.h>
+#import <Foundation/NSValue.h>
#ifdef MACOSX
/*
diff --git a/Objective-C/libobjcl.h b/Objective-C/libobjcl.h
index 35d6150..c8c6766 100644
--- a/Objective-C/libobjcl.h
+++ b/Objective-C/libobjcl.h
@@ -17,7 +17,9 @@
* <http://www.gnu.org/licenses/>.
*/
-#import "Foundation/Foundation.h"
+#import "Foundation/NSException.h"
+#import "Foundation/NSLock.h"
+
#include <objc/objc-api.h>
#include "../config.h"
@@ -43,23 +45,10 @@ typedef Ivar IVAR_T;
typedef struct objc_ivar *IVAR_T;
#endif
-#ifdef HAVE_SYS_SEM_H
-#include <sys/sem.h>
-#ifndef __APPLE__
-/* According to the Single Unix Specification, Version 3, the semun
- union type must be defined by the application writer as follows: */
-union semun
-{
- int val; /* Value for SETVAL */
- struct semid_ds *buf; /* Buffer for IPC_STAT, IPC_SET */
- unsigned short *array; /* Array for GETALL, SETALL */
-};
-#endif
-#endif
extern NSException *objcl_oom_exception;
extern id objcl_current_exception;
-extern void *objcl_current_exception_lock;
+extern NSRecursiveLock *objcl_current_exception_lock;
void
@@ -173,13 +162,10 @@ objcl_create_imp (IMP callback,
const char *arg_typespecs[]);
void
-objcl_acquire_lock (void *lock);
-
-void
-objcl_release_lock (void *lock);
+objcl_acquire_lock (id lock);
void
-objcl_initialise_lock (void **lock);
+objcl_release_lock (id lock);
Class
objcl_create_class (const char *class_name,
diff --git a/Objective-C/libobjcl.m b/Objective-C/libobjcl.m
index 9af9960..e7d8148 100644
--- a/Objective-C/libobjcl.m
+++ b/Objective-C/libobjcl.m
@@ -22,7 +22,8 @@
#import "PyObjC/libffi_support.h"
#import "JIGS/ObjcRuntimeUtilities.h"
-#import <Foundation/Foundation.h>
+#import "Foundation/Foundation.h"
+
#include <stdarg.h>
#include <sys/mman.h>
#include <objc/objc-api.h>
@@ -49,7 +50,7 @@ static NSAutoreleasePool *objcl_autorelease_pool = nil;
NSException *objcl_oom_exception = nil;
id objcl_current_exception = nil;
-void *objcl_current_exception_lock = NULL;
+NSRecursiveLock *objcl_current_exception_lock = nil;
static NSMutableDictionary *method_lists = nil;
static NSMutableDictionary *method_list_lengths = nil;
@@ -72,7 +73,7 @@ objcl_initialise_runtime (void)
PyObjC_SetupRuntimeCompat ();
#endif
- objcl_initialise_lock (&objcl_current_exception_lock);
+ objcl_current_exception_lock = [[NSRecursiveLock alloc] init];
method_lists = [[NSMutableDictionary alloc] init];
method_list_lengths = [[NSMutableDictionary alloc] init];
objcl_initialise_instance_wrappers ();
@@ -101,6 +102,7 @@ objcl_shutdown_runtime (void)
if (init_count == 0)
{
release_unless_null (&objcl_autorelease_pool);
+ release_unless_null (&objcl_current_exception_lock);
release_unless_null (&objcl_oom_exception);
release_unless_null (&method_lists);
release_unless_null (&method_list_lengths);
@@ -633,63 +635,18 @@ objcl_create_imp (IMP callback,
void
-objcl_initialise_lock (void **lock)
-{
-#ifdef HAVE_SYS_SEM_H
- int sem;
- union semun initop;
-
- sem = semget (IPC_PRIVATE, 1, IPC_CREAT | 0600);
- *lock = malloc (sizeof (int));
- *((int *) *lock) = sem;
-
- initop.val = 1;
- semctl (sem, 0, SETVAL, initop);
-#else
-#warning "I do not know how to do locking on this platform."
-#endif
-}
-
-
-void
-objcl_acquire_lock (void *lock)
+objcl_acquire_lock (id lock)
{
-#ifdef HAVE_SYS_SEM_H
- struct sembuf op;
- op.sem_num = 0; op.sem_op = +1; op.sem_flg = 0;
-
- if ((semop (*((int *) lock), &op, 1)) < 0)
- {
- [[NSException exceptionWithName: @"MLKLockLossage"
- reason: @"Acquiring the exception lock failed (don't ask me why)."
- userInfo: nil] raise];
- }
-
- TRACE (@"Exception buffer locked.");
-#else
-#warning "I do not know how to do locking on this platform."
-#endif
+ [lock lock];
+ TRACE (@"Lock %@ acquired.", lock);
}
void
-objcl_release_lock (void *lock)
+objcl_release_lock (id lock)
{
-#ifdef HAVE_SYS_SEM_H
- struct sembuf op;
- op.sem_num = 0; op.sem_op = +1; op.sem_flg = 0;
-
- if ((semop (*((int *) lock), &op, 1)) < 0)
- {
- [[NSException exceptionWithName: @"MLKLockLossage"
- reason: @"Acquiring the exception lock failed (don't ask me why)."
- userInfo: nil] raise];
- }
-
- TRACE (@"Exception buffer unlocked.");
-#else
-#warning "I do not know how to do locking on this platform."
-#endif
+ [lock unlock];
+ TRACE (@"Lock %@ released.", lock);
}