[beast/win32: 3/44] Applied 004b_birnet_os.diff: added OS abstraction layer to birnet.
- From: Stefan Westerfeld <stw src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [beast/win32: 3/44] Applied 004b_birnet_os.diff: added OS abstraction layer to birnet.
- Date: Fri, 29 Jan 2010 16:21:40 +0000 (UTC)
commit a3c1e503c1d8c023dad9a1714d5dea421b2c4f34
Author: Stefan Westerfeld <stefan space twc de>
Date: Thu Aug 27 17:07:14 2009 +0200
Applied 004b_birnet_os.diff: added OS abstraction layer to birnet.
birnet/Makefile.am | 8 +++++++-
birnet/birnet.hh | 1 +
birnet/birnetcpu.cc | 20 ++------------------
birnet/birnetdebugtools.cc | 1 -
birnet/birnetmsg.cc | 10 +++++-----
birnet/birnetthreadimpl.cc | 10 ++++------
birnet/birnetutils.cc | 37 +++++++++++++++----------------------
birnet/birnetutils.hh | 1 +
birnet/configure.inc | 3 +++
birnet/tests/systest.cc | 4 ++++
birnet/tests/threads.cc | 5 +++--
11 files changed, 45 insertions(+), 55 deletions(-)
---
diff --git a/birnet/Makefile.am b/birnet/Makefile.am
index ee3427c..088c4a3 100644
--- a/birnet/Makefile.am
+++ b/birnet/Makefile.am
@@ -5,7 +5,7 @@
include $(top_srcdir)/Makefile.decl
SUBDIRS = . tests
-INCLUDES += -I$(top_srcdir) -I$(top_builddir) -I$(srcdir) -I. $(BIRNET_CFLAGS)
+INCLUDES += -I$(top_srcdir) -I$(top_builddir) -I$(srcdir) -I. $(CFLAGS) $(BIRNET_CFLAGS)
DEFS = -DBIRNET_LOG_DOMAIN=\"BIRNET\" -D_BIRNET_SOURCE_EXTENSIONS
GLIB_MKENUMS = glib-mkenums
@@ -33,6 +33,12 @@ birnet_sources = $(strip \
birnetutf8.cc \
birnetutils.cc \
)
+if BIRNET_OS_WIN32
+birnet_sources += birnetoswin32.cc
+endif
+if BIRNET_OS_UNIX
+birnet_sources += birnetosunix.cc
+endif
birnet_private_headers = $(strip \
birnetsignalslot.hh \
birnetsignaltemplate.hh \
diff --git a/birnet/birnet.hh b/birnet/birnet.hh
index c8c1127..279091b 100644
--- a/birnet/birnet.hh
+++ b/birnet/birnet.hh
@@ -20,6 +20,7 @@
#include <birnet/birnetconfig.h>
#include <birnet/birnetcpu.hh>
#include <birnet/birnetdebugtools.hh>
+#include <birnet/birnetos.hh>
#include <birnet/birnetmsg.hh>
diff --git a/birnet/birnetcpu.cc b/birnet/birnetcpu.cc
index 5c4ffb5..ba49ce8 100644
--- a/birnet/birnetcpu.cc
+++ b/birnet/birnetcpu.cc
@@ -16,6 +16,7 @@
*/
#include <glib.h>
#include "birnetcpu.hh"
+#include "birnetos.hh"
#include <setjmp.h>
#include <signal.h>
#include <string.h>
@@ -196,24 +197,7 @@ get_x86_cpu_features (CPUInfo *ci,
/* check system support for SSE */
if (ci->x86_sse)
{
- struct sigaction action, old_action;
- action.sa_handler = cpu_info_sigill_handler;
- sigemptyset (&action.sa_mask);
- action.sa_flags = SA_NOMASK;
- sigaction (SIGILL, &action, &old_action);
- if (setjmp (cpu_info_jmp_buf) == 0)
- {
- unsigned int mxcsr;
- __asm__ __volatile__ ("stmxcsr %0 ; sfence ; emms" : "=m" (mxcsr));
- /* executed SIMD instructions without exception */
- ci->x86_ssesys = true;
- }
- else
- {
- /* signal handler jumped here */
- // g_printerr ("caught SIGILL\n");
- }
- sigaction (SIGILL, &old_action, NULL);
+ ci->x86_ssesys = OS::check_sse_sys();
}
return true;
diff --git a/birnet/birnetdebugtools.cc b/birnet/birnetdebugtools.cc
index e02432c..902cd6e 100644
--- a/birnet/birnetdebugtools.cc
+++ b/birnet/birnetdebugtools.cc
@@ -16,7 +16,6 @@
*/
#include "birnetdebugtools.hh"
#include "birnetthread.hh"
-#include <syslog.h>
#include <errno.h>
#include <stdio.h>
diff --git a/birnet/birnetmsg.cc b/birnet/birnetmsg.cc
index 6dc0002..31eebac 100644
--- a/birnet/birnetmsg.cc
+++ b/birnet/birnetmsg.cc
@@ -17,7 +17,7 @@
#include <glib.h>
#include "birnetmsg.hh"
#include "birnetthread.hh"
-#include <syslog.h>
+#include "birnetos.hh"
#include <errno.h>
#include <string.h>
#include <stdio.h>
@@ -495,13 +495,13 @@ Msg::display_parts (const char *domain,
{
String prefix = log_prefix ("", 0, domain, "", ident);
if (title.size() && false) // skip title in syslog
- syslog (msg_syslog_priority, "%s:0: %s\n", prefix.c_str(), title.c_str());
+ OS::syslog (msg_syslog_priority, "%s:0: %s\n", prefix.c_str(), title.c_str());
if (primary.size())
- syslog (msg_syslog_priority, "%s:1: %s\n", prefix.c_str(), primary.c_str());
+ OS::syslog (msg_syslog_priority, "%s:1: %s\n", prefix.c_str(), primary.c_str());
if (secondary.size())
- syslog (msg_syslog_priority, "%s:2: %s\n", prefix.c_str(), secondary.c_str());
+ OS::syslog (msg_syslog_priority, "%s:2: %s\n", prefix.c_str(), secondary.c_str());
if (details.size() && false) // skip details in syslog
- syslog (msg_syslog_priority, "%s:3: %s\n", prefix.c_str(), details.c_str());
+ OS::syslog (msg_syslog_priority, "%s:3: %s\n", prefix.c_str(), details.c_str());
}
/* log to logfile */
if (msg_log_file && (actions & LOG_TO_STDLOG))
diff --git a/birnet/birnetthreadimpl.cc b/birnet/birnetthreadimpl.cc
index e06f4fe..60f23c9 100644
--- a/birnet/birnetthreadimpl.cc
+++ b/birnet/birnetthreadimpl.cc
@@ -23,19 +23,16 @@
#define _XOPEN_SOURCE 600 /* for full pthread facilities */
#endif /* defining _XOPEN_SOURCE on random systems can have bad effects */
#include <glib.h>
-#include <sys/time.h>
-#include <sched.h>
#include <unistd.h> /* sched_yield() */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <string.h>
-#include <sys/resource.h>
#include <sys/time.h>
-#include <sys/times.h>
#include "birnetutils.hh"
#include "birnetthread.hh"
+#include "birnetos.hh"
#define FLOATING_FLAG (1 << 31)
#define THREAD_REF_COUNT(thread) (thread->ref_field & ~FLOATING_FLAG)
@@ -906,7 +903,7 @@ birnet_thread_accounting_L (BirnetThread *self,
gint64 old_cstime = self->ac.cstime;
gdouble dfact = 1000000.0 / MAX (diff, 1);
self->ac.stamp = stamp;
- if (0)
+#if 0
{
struct rusage res = { { 0 } };
getrusage (RUSAGE_SELF, &res);
@@ -916,8 +913,9 @@ birnet_thread_accounting_L (BirnetThread *self,
self->ac.cutime = timeval_usecs (&res.ru_utime);
self->ac.cstime = timeval_usecs (&res.ru_stime);
}
+#endif
thread_info_from_stat_L (self, dfact);
- self->info.priority = getpriority (PRIO_PROCESS, self->tid);
+ self->info.priority = OS::get_thread_priority (self->tid);
self->info.utime = int64 (MAX (self->ac.utime - old_utime, 0) * dfact);
self->info.stime = int64 (MAX (self->ac.stime - old_stime, 0) * dfact);
self->info.cutime = int64 (MAX (self->ac.cutime - old_cutime, 0) * dfact);
diff --git a/birnet/birnetutils.cc b/birnet/birnetutils.cc
index a17f7a8..d44bcd1 100644
--- a/birnet/birnetutils.cc
+++ b/birnet/birnetutils.cc
@@ -20,6 +20,7 @@
#include "birnetthread.hh"
#include "birnetmsg.hh"
#include "birnetcpu.hh"
+#include "birnetos.hh"
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
@@ -188,8 +189,8 @@ birnet_init (int *argcp,
{
struct timeval tv;
gettimeofday (&tv, NULL);
- srand48 (tv.tv_usec + (tv.tv_sec << 16));
- srand (lrand48());
+ OS::srand48 (tv.tv_usec + (tv.tv_sec << 16));
+ srand (OS::lrand48());
}
/* initialize sub systems */
@@ -258,11 +259,6 @@ BIRNET_STATIC_ASSERT (LDBL_MAX >= 1E+37);
BIRNET_STATIC_ASSERT (LDBL_EPSILON <= 1E-9);
/* --- assertions/warnings/errors --- */
-void
-raise_sigtrap ()
-{
- raise (SIGTRAP);
-}
static void
stderr_print (bool bail_out,
@@ -431,7 +427,7 @@ string_vprintf (const char *format,
va_list vargs)
{
char *str = NULL;
- if (vasprintf (&str, format, vargs) >= 0 && str)
+ if (OS::vasprintf (&str, format, vargs) >= 0 && str)
{
String s = str;
free (str);
@@ -610,7 +606,7 @@ string_from_errno (int errno_val)
{
char buffer[1024] = { 0, };
/* strerror_r() is broken on GNU systems, especially if _GNU_SOURCE is defined, so fall back to strerror() */
- if (strerror_r (errno_val, buffer, sizeof (buffer)) < 0 || !buffer[0])
+ if (OS::strerror_r (errno_val, buffer, sizeof (buffer)) < 0 || !buffer[0])
return strerror (errno_val);
return buffer;
}
@@ -739,7 +735,7 @@ errno_check_file (const char *file_name,
if (check_link)
{
- if (lstat (file_name, &st) < 0)
+ if (OS::lstat (file_name, &st) < 0)
return -errno;
}
else if (stat (file_name, &st) < 0)
@@ -750,11 +746,11 @@ errno_check_file (const char *file_name,
file_name, mode,
S_ISREG (st.st_mode) ? "f" : "",
S_ISDIR (st.st_mode) ? "d" : "",
- S_ISLNK (st.st_mode) ? "l" : "",
+ OS::stat_is_link (st.st_mode) ? "l" : "",
S_ISCHR (st.st_mode) ? "c" : "",
S_ISBLK (st.st_mode) ? "b" : "",
S_ISFIFO (st.st_mode) ? "p" : "",
- S_ISSOCK (st.st_mode) ? "s" : "");
+ OS::stat_is_socket (st.st_mode) ? "s" : "");
if (S_ISDIR (st.st_mode) && (check_file || check_link || check_char || check_block || check_pipe))
return -EISDIR;
@@ -762,17 +758,17 @@ errno_check_file (const char *file_name,
return -EINVAL;
if (check_dir && !S_ISDIR (st.st_mode))
return -ENOTDIR;
- if (check_link && !S_ISLNK (st.st_mode))
+ if (check_link && !OS::stat_is_link (st.st_mode))
return -EINVAL;
if (check_char && !S_ISCHR (st.st_mode))
return -ENODEV;
if (check_block && !S_ISBLK (st.st_mode))
- return -ENOTBLK;
+ return -OS_ENOTBLK;
if (check_pipe && !S_ISFIFO (st.st_mode))
return -ENXIO;
- if (check_socket && !S_ISSOCK (st.st_mode))
- return -ENOTSOCK;
- if (check_exec && !(st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))
+ if (check_socket && !OS::stat_is_socket (st.st_mode))
+ return -OS_ENOTSOCK;
+ if (check_exec && !(st.st_mode & (S_IXUSR | OS_S_IXGRP | OS_S_IXOTH)))
return -EACCES; /* for root executable, any +x bit is good enough */
}
@@ -1225,7 +1221,7 @@ url_create_redirect (const char *url,
while (fd < 0)
{
g_free (tname);
- tname = g_strdup_printf ("/tmp/Url%08X%04X.html", (int) lrand48(), getpid());
+ tname = g_strdup_printf ("/tmp/Url%08X%04X.html", (int) OS::lrand48(), OS::getpid());
fd = open (tname, O_WRONLY | O_CREAT | O_EXCL, 00600);
if (fd < 0 && errno != EEXIST)
{
@@ -1366,10 +1362,7 @@ memset4 (guint32 *mem,
guint32 filler,
guint length)
{
- BIRNET_STATIC_ASSERT (sizeof (*mem) == 4);
- BIRNET_STATIC_ASSERT (sizeof (filler) == 4);
- BIRNET_STATIC_ASSERT (sizeof (wchar_t) == 4);
- wmemset ((wchar_t*) mem, filler, length);
+ OS::memset4 (mem, filler, length);
}
/* --- memory utils --- */
diff --git a/birnet/birnetutils.hh b/birnet/birnetutils.hh
index 1d8b143..ccda7bd 100644
--- a/birnet/birnetutils.hh
+++ b/birnet/birnetutils.hh
@@ -18,6 +18,7 @@
#define __BIRNET_UTILS_XX_HH__
#include <birnet/birnetcdefs.h>
+#include <stdarg.h>
#include <string>
#include <vector>
#include <map>
diff --git a/birnet/configure.inc b/birnet/configure.inc
index 2e17f20..6dabed7 100644
--- a/birnet/configure.inc
+++ b/birnet/configure.inc
@@ -61,6 +61,9 @@ AC_DEFUN([AC_BIRNET_REQUIREMENTS],
;;
esac
AC_SUBST(BIRNET_OS)
+ AM_CONDITIONAL([BIRNET_OS_WIN32], [test x$BIRNET_OS = xWIN32])
+ AM_CONDITIONAL([BIRNET_OS_UNIX], [test x$BIRNET_OS = xUNIX])
+ AC_SUBST(BIRNET_OS_IMPL)
AC_SUBST(BIRNET_OS_CHOICES)
AC_DEFINE_UNQUOTED(BIRNET_OS_$BIRNET_OS, "1", [Win32 detection])
diff --git a/birnet/tests/systest.cc b/birnet/tests/systest.cc
index b5440f7..4e82ff8 100644
--- a/birnet/tests/systest.cc
+++ b/birnet/tests/systest.cc
@@ -16,7 +16,9 @@
*/
//#define TEST_VERBOSE
#include <birnet/birnettests.h>
+#ifndef WIN32
#include <poll.h>
+#endif
namespace {
using namespace Birnet;
@@ -25,6 +27,7 @@ static void
test_poll()
{
TSTART("POLL constants");
+#ifndef WIN32
TASSERT (BIRNET_SYSVAL_POLLIN == POLLIN);
TASSERT (BIRNET_SYSVAL_POLLPRI == POLLPRI);
TASSERT (BIRNET_SYSVAL_POLLOUT == POLLOUT);
@@ -35,6 +38,7 @@ test_poll()
TASSERT (BIRNET_SYSVAL_POLLERR == POLLERR);
TASSERT (BIRNET_SYSVAL_POLLHUP == POLLHUP);
TASSERT (BIRNET_SYSVAL_POLLNVAL == POLLNVAL);
+#endif
TDONE();
}
diff --git a/birnet/tests/threads.cc b/birnet/tests/threads.cc
index 0c32b67..ee0bf26 100644
--- a/birnet/tests/threads.cc
+++ b/birnet/tests/threads.cc
@@ -17,6 +17,7 @@
//#define TEST_VERBOSE
#include <birnet/birnettests.h>
#include <stdlib.h>
+#include <unistd.h>
namespace {
using namespace Birnet;
@@ -934,7 +935,7 @@ struct RingBufferReader : public virtual Birnet::Thread, IntSequence {
for (uint l = 0; l < ring_buffer_test_length;)
{
uint k, n = ring->n_readable();
- n = lrand48() % MIN (n + 1, 65536 * 2);
+ n = OS::lrand48() % MIN (n + 1, 65536 * 2);
int buffer[n], *b = buffer;
if (rand() & 1)
{
@@ -1007,7 +1008,7 @@ test_ring_buffer ()
{
TSTART ("AsyncRingBuffer-big");
uint ring_buffer_test_length = 999999 * (init_settings().test_quick ? 1 : 20);
- IntRingBuffer irb (16384 + (lrand48() % 8192));
+ IntRingBuffer irb (16384 + (OS::lrand48() % 8192));
RingBufferReader *rbr = new RingBufferReader (&irb, ring_buffer_test_length);
ref_sink (rbr);
RingBufferWriter *rbw = new RingBufferWriter (&irb, ring_buffer_test_length);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]