diff --git a/Rakefile b/Rakefile index 604f80c..b3f0005 100644 --- a/Rakefile +++ b/Rakefile @@ -10,6 +10,10 @@ Rake::ExtensionTask.new('libpsem') do |ext| ext.lib_dir = 'lib/process_shared' end +Rake::ExtensionTask.new('helper') do |ext| + ext.lib_dir = 'lib/process_shared/posix' +end + desc 'Run the tests' task :default => [:test] @@ -22,3 +26,5 @@ Gem::PackageTask.new(gemspec) do |p| p.need_tar = true p.gem_spec = gemspec end + +task :gem => :compile diff --git a/ext/helper/extconf.rb b/ext/helper/extconf.rb new file mode 100644 index 0000000..7b78fa0 --- /dev/null +++ b/ext/helper/extconf.rb @@ -0,0 +1,14 @@ +require 'mkmf' + +have_header('fcntl.h') + +have_header('sys/mman.h') + +have_header('semaphore.h') +have_type('sem_t', 'semaphore.h') + +have_header('pthread.h') +have_type('pthread_mutex_t', 'pthread.h') +have_type('pthread_mutexattr_t', 'pthread.h') + +create_makefile('helper') diff --git a/ext/helper/helper.c b/ext/helper/helper.c new file mode 100644 index 0000000..6436b98 --- /dev/null +++ b/ext/helper/helper.c @@ -0,0 +1,70 @@ +/****************************/ +/* File descriptor controls */ +/****************************/ + +#ifdef HAVE_FCNTL_H +#include +extern int o_rdwr; +int o_rdwr = O_RDWR; +extern int o_creat; +int o_creat = O_CREAT; +extern int o_excl; +int o_excl = O_EXCL; +#endif + +/************************/ +/* Memory Map constants */ +/************************/ + +#ifdef HAVE_SYS_MMAN_H +#include + +extern int prot_read; +extern int prot_write; +extern int prot_exec; +extern int prot_none; + +extern void * map_failed; +extern int map_shared; +extern int map_private; + +int prot_read = PROT_READ; +int prot_write = PROT_WRITE; +int prot_exec = PROT_EXEC; +int prot_none = PROT_NONE; + +void * map_failed = MAP_FAILED; +int map_shared = MAP_SHARED; +int map_private = MAP_PRIVATE; +#endif + +/****************************************/ +/* PThread and related types and macros */ +/****************************************/ + +#ifdef HAVE_PTHREAD_H +#include +extern int pthread_process_shared; +int pthread_process_shared = PTHREAD_PROCESS_SHARED; +#endif + +#ifdef HAVE_TYPE_PTHREAD_MUTEX_T +extern size_t sizeof_pthread_mutex_t; +size_t sizeof_pthread_mutex_t = sizeof (pthread_mutex_t); +size_t sizeof_pthread_mutexattr_t = sizeof (pthread_mutexattr_t); +#endif + +#ifdef HAVE_TYPE_PTHREAD_MUTEXATTR_T +extern size_t sizeof_pthread_mutexattr_t; +#endif + +/******************/ +/* Semaphore type */ +/******************/ + +#ifdef HAVE_TYPE_SEM_T +#include +extern size_t sizeof_sem_t; +size_t sizeof_sem_t = sizeof (sem_t); +#endif +