Project

General

Profile

Bug #115

Mac OSX

Added by François Ingrand about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-

Description

Voici 2 patches… le premier me semble sans danger et élimine un warning de clang, le second est pour palier a l’absence de spinlock sur OSX (trouvé sur le web).

ashitaka:genom3-pocolibs felix$ git diff
diff --git a/common/typecopy.h b/common/typecopy.h
index ca0e93c..fce6db4 100644
--- a/common/typecopy.h
++ b/common/typecopy.h
@ -253,6 +253,7 @ genom_tcopy_<"[$t mangle]">(<"[$t argument reference dst]">,
<"[$e pass value src->[$e name]]">);
if (s) return s;
<' }'>
return 0; /* fix Wreturn-type /
<' } else {'>
(void)dst; (void)src; /
fix -Wunused-parameter */
<' }'>
diff --git a/server/control_task.h b/server/control_task.h
index 8ee261f..c756e76 100644
--
a/server/control_task.h
+++ b/server/control_task.h
@ -42,6 +42,49 @ lang c
#include "<"$comp">_remotelib.h"
#include "<"$comp">_activity.h"

#ifdef APPLE
+typedef int pthread_spinlock_t;

static inline
+int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
asm volatile ("" ::: "memory");
+ *lock = 0;
+ return 0;
}

static inline
+int pthread_spin_destroy(pthread_spinlock_t *lock) {
return 0;
}

static inline
+int pthread_spin_lock(pthread_spinlock_t *lock) {
while (1) {
+ int i;
+ for (i=0; i < 10000; i++) {
+ if (sync_bool_compare_and_swap(lock, 0, 1)) {
+ return 0;
+ }
+ }
+ sched_yield();
+ }
}

static __inline

+int pthread_spin_trylock(pthread_spinlock_t *lock) {
if (sync_bool_compare_and_swap(lock, 0, 1)) {
+ return 0;
+ }
+ return EBUSY;
}

static __inline

+int pthread_spin_unlock(pthread_spinlock_t *lock) {
asm volatile ("" ::: "memory");
+ *lock = 0;
+ return 0;
}
#endif

/* --- an enum of all the codels defined ----------------------------------------------------- */

ashitaka:genom3-pocolibs felix$


Felix


Files

signature.asc (801 Bytes) signature.asc François Ingrand, 2017-06-01 17:19

Associated revisions

Revision 9ed403a0 (diff)
Added by Anthony Mallet about 2 years ago

Add missing return statement in function returning value

Partially addresses issue #115

Revision dba71e62 (diff)
Added by Anthony Mallet about 2 years ago

Provide a darwin implementation of pthread_spin_lock(3) et al.

Fixes #115.

Revision 9ce77fc9 (diff)
Added by Anthony Mallet almost 2 years ago

Add missing return statement in function returning value

Partially addresses issue #115

History

#1

Updated by François Ingrand about 2 years ago

As for missing spin lock on OSX, there is in fact a "replacement"... so here is another implementation which I prefer...

#include <libkern/OSAtomic.h>

typedef OSSpinLock pthread_spinlock_t;

static __inline__
int pthread_spin_init(pthread_spinlock_t *lock, int pshared) {
    __asm__ __volatile__ ("" ::: "memory"); /* this does not hurt to keep it */
    *lock = 0;
    return 0;
}

static __inline__
int pthread_spin_destroy(pthread_spinlock_t *lock) {
    return 0;            /* Nothing to do, just an int */
}

static __inline__
int pthread_spin_lock(pthread_spinlock_t *lock) {
  OSSpinLockLock(lock);
  return 0;
}

static __inline__
int pthread_spin_trylock(pthread_spinlock_t *lock) {
  if (OSSpinLockTry(lock)) return 0; /* OSSpinLockTry return true on success, and pthread_spin_trylock 0 */
  else return EBUSY;
}

static __inline__
int pthread_spin_unlock(pthread_spinlock_t *lock) {
  OSSpinLockUnlock(lock);
  return 0;
}

#2

Updated by Anthony Mallet about 2 years ago

  • Status changed from New to Closed

Also available in: Atom PDF