Skip to content

Commit

Permalink
Get around a picky gcc 12 on linux. Avoid defining the sqOSSemaphore …
Browse files Browse the repository at this point in the history
…struct

twice, getting around the sqPlatformSpecific.h gymnastics caused by the config.h
putsch (that has made my life hell).
  • Loading branch information
eliotmiranda committed Jul 28, 2022
1 parent 4be61d9 commit 1668c76
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
1 change: 0 additions & 1 deletion platforms/iOS/vm/OSX/sqPlatformSpecific.h
Expand Up @@ -151,7 +151,6 @@ typedef struct {
pthread_mutex_t mutex;
int count;
} sqOSSemaphore;
# define ioDestroyOSSemaphore(ptr) 0
# if !ForCOGMTVMImplementation /* this is a read-only export */
extern const pthread_key_t tltiIndex;
# endif
Expand Down
1 change: 0 additions & 1 deletion platforms/minheadless/unix/sqPlatformSpecific-Unix.h
Expand Up @@ -63,7 +63,6 @@ typedef struct {
pthread_mutex_t mutex;
int count;
} sqOSSemaphore;
# define ioDestroyOSSemaphore(ptr) 0
# if !ForCOGMTVMImplementation /* this is a read-only export */
extern const pthread_key_t tltiIndex;
# endif
Expand Down
4 changes: 3 additions & 1 deletion platforms/unix/vm/sqPlatformSpecific.h
Expand Up @@ -68,12 +68,14 @@ extern void reportMinimumUnusedHeadroom(void);
/* Please read the comment for CogThreadManager in the VMMaker package for
* documentation of this API.
*/
# if !defined(_SQ_OSSEMAPHORE)
# define _SQ_OSSEMAPHORE
typedef struct {
pthread_cond_t cond;
pthread_mutex_t mutex;
int count;
} sqOSSemaphore;
# define ioDestroyOSSemaphore(ptr) 0
# endif
# if !ForCOGMTVMImplementation /* this is a read-only export */
extern const pthread_key_t tltiIndex;
# endif
Expand Down
19 changes: 18 additions & 1 deletion platforms/unix/vm/sqUnixThreads.c
Expand Up @@ -28,8 +28,11 @@
# include <sys/sysctl.h> /* for ioNumProcesors */
#endif
#include <errno.h>
#include <string.h>
#include <pthread.h>

#define pthreadperror(s,e) fprintf(stderr,"%s: %s\n", s, strerror(e))

int
ioNewOSThread(void (*func)(void *), void *arg)
{
Expand All @@ -41,7 +44,7 @@ ioNewOSThread(void (*func)(void *), void *arg)
0, /* const pthread_attr_t *attr */
(void *(*)(void *))func,/* void * (*thread_execp)(void *) */
(void *)arg /* void *arg */))) {
perror("pthread_create");
pthreadperror("pthread_create",err);
return err;
}
return 0;
Expand All @@ -67,6 +70,20 @@ ioNewOSSemaphore(sqOSSemaphore *sem)
: 0;
}

#if !defined(ioDestroyOSSemaphore)
void
ioDestroyOSSemaphore(sqOSSemaphore *sem)
{
int err;

sem->count = 0;
if ((err = pthread_cond_destroy(&sem->cond)))
pthreadperror("pthread_cond_destroy",err);
if ((err = pthread_mutex_destroy(&sem->mutex)))
pthreadperror("pthread_mutex_destroy",err);
}
#endif

#define DEBUG 1
#if DEBUG
# include "sqAtomicOps.h"
Expand Down

0 comments on commit 1668c76

Please sign in to comment.