SCP: Add atomic routines for temporary shmem access

This commit is contained in:
Mark Pizzolato 2018-06-01 23:16:14 -07:00
parent 0e5c60b58f
commit c1f249ec66
2 changed files with 22 additions and 0 deletions

View file

@ -458,6 +458,16 @@ if (shmem->hMapping != INVALID_HANDLE_VALUE)
free (shmem); free (shmem);
} }
int32 sim_shmem_atomic_add (int32 *p, int32 v)
{
return InterlockedExchangeAdd ((volatile long *) p,v) + (v);
}
t_bool sim_shmem_atomic_cas (int32 *ptr, int32 oldv, int32 newv)
{
return (InterlockedCompareExchange ((LONG volatile *) ptr, newv, oldv) == oldv);
}
#else /* !defined(_WIN32) */ #else /* !defined(_WIN32) */
#include <unistd.h> #include <unistd.h>
int sim_set_fsize (FILE *fptr, t_addr size) int sim_set_fsize (FILE *fptr, t_addr size)
@ -604,6 +614,16 @@ if (shmem->shm_fd != -1)
free (shmem); free (shmem);
} }
int32 sim_shmem_atomic_add (int32 *p, int32 v)
{
return __sync_add_and_fetch((int *) p, v);
}
t_bool sim_shmem_atomic_cas (int32 *ptr, int32 oldv, int32 newv)
{
return __sync_bool_compare_and_swap (ptr, oldv, newv);
}
#endif #endif
#if defined(__VAX) #if defined(__VAX)

View file

@ -76,6 +76,8 @@ const char *sim_get_os_error_text (int error);
typedef struct SHMEM SHMEM; typedef struct SHMEM SHMEM;
t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr); t_stat sim_shmem_open (const char *name, size_t size, SHMEM **shmem, void **addr);
void sim_shmem_close (SHMEM *shmem); void sim_shmem_close (SHMEM *shmem);
int32 sim_shmem_atomic_add (int32 *ptr, int32 val);
t_bool sim_shmem_atomic_cas (int32 *ptr, int32 oldv, int32 newv);
extern t_bool sim_taddr_64; /* t_addr is > 32b and Large File Support available */ extern t_bool sim_taddr_64; /* t_addr is > 32b and Large File Support available */
extern t_bool sim_toffset_64; /* Large File (>2GB) file I/O support */ extern t_bool sim_toffset_64; /* Large File (>2GB) file I/O support */