From a883560b42163f5ed0c83204469d17dd4f0134b6 Mon Sep 17 00:00:00 2001 From: Niko Liikanen Date: Thu, 24 Aug 2006 16:03:09 +0000 Subject: [PATCH] Win32 tweaks --- Makefile | 24 ++++++++++++++++-------- source/application.cpp | 4 ++++ source/application.h | 4 ++++ source/event.cpp | 17 +++++++++++++++++ source/pollable.cpp | 10 ++++++++++ source/pollable.h | 4 ++++ source/poller.cpp | 4 ++++ source/poller.h | 4 ++++ source/thread.cpp | 2 +- source/thread.h | 4 ++++ source/win32poll.h | 29 +++++++++++++++++++++++++++++ 11 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 source/win32poll.h diff --git a/Makefile b/Makefile index b88954c..83df840 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +LIBRARY = framework +LIBFILE = libmspframework + TMP = $(HOME)/nightwatch/tmp TGT = $(HOME)/nightwatch @@ -5,14 +8,19 @@ CXX = g++ CC = gcc AR = ar CP = cp + INCLUDE = -Isource -I$(TMP)/include LIB = -L$(TMP) DEBUG = -CFLAGS = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0` `sdl-config --cflags` +CFLAGS = $(DEBUG) $(INCLUDE) -pipe -Wall `pkg-config --cflags sigc++-2.0` CXXFLAGS = $(CFLAGS) +LIBLDFLAGS = -lpthreadGC2 -lsigc-2.0 +MAKEFLAGS += -s --no-print-directory + +PIC = -fPIC +SHARED = .so +STATIC = .a -LIBRARY = framework -LIBFILE = libmspframework SRC = source LIBOBJS = $(addprefix $(TMP)/, $(addsuffix .o, $(notdir $(basename $(wildcard $(SRC)/*.cpp))))) @@ -20,19 +28,19 @@ pkgincludedir = include/msp/$(LIBRARY) libdir = lib .PHONY: all -all: $(TMP) $(TMP)/$(LIBFILE).so $(TMP)/$(LIBFILE).a tmpheaders +all: $(TMP) $(TMP)/$(LIBFILE)$(SHARED) $(TMP)/$(LIBFILE)$(STATIC) tmpheaders # Create temp directory $(TMP): mkdir -p $@ # Dynamic library -$(TMP)/$(LIBFILE).so: $(LIBOBJS) +$(TMP)/$(LIBFILE)$(SHARED): $(LIBOBJS) echo "Compiling $(notdir $@)" - $(CXX) $^ -shared -o $@ $(LIB) $(LIBRARYLIBS) + $(CXX) $^ -shared -o $@ $(LIB) $(LIBLDFLAGS) # Static library -$(TMP)/$(LIBFILE).a: $(LIBOBJS) +$(TMP)/$(LIBFILE)$(STATIC): $(LIBOBJS) echo "Compiling $(notdir $@)" $(AR) rcs $@ $^ @@ -47,7 +55,7 @@ $(TMP)/$(pkgincludedir): # Library object file $(TMP)/%.o: $(SRC)/%.cpp $(wildcard $(SRC)/*.h) echo "Compiling $(LIBRARY)/$(notdir $(basename $@))" - $(CXX) -fPIC $(CXXFLAGS) -c $< -o $@ + $(CXX) $(PIC) $(CXXFLAGS) -c $< -o $@ # Installs .PHONY: install diff --git a/source/application.cpp b/source/application.cpp index 765b067..22c8d26 100644 --- a/source/application.cpp +++ b/source/application.cpp @@ -114,8 +114,12 @@ int Application::main() poller_->poll(-1); else { +#ifdef WIN32 + Sleep(1); +#else timespec ts={1000,0}; nanosleep(&ts, 0); +#endif } if(tick_mode_!=NONE) tick(); diff --git a/source/application.h b/source/application.h index 4296b6f..b2502ed 100644 --- a/source/application.h +++ b/source/application.h @@ -6,6 +6,10 @@ Distributed under the LGPL #ifndef MSP_FRAMEWORK_APPLICATION_H_ #define MSP_FRAMEWORK_APPLICATION_H_ +#ifdef WIN32 +#include "win32signum.h" +#endif + #include #include "event.h" #include "poller.h" diff --git a/source/event.cpp b/source/event.cpp index b314fca..01b8542 100644 --- a/source/event.cpp +++ b/source/event.cpp @@ -3,6 +3,11 @@ This file is part of libmspframework Copyright © 2006 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#ifdef WIN32 +#include +#include +#endif + #include "application.h" #include "event.h" @@ -42,17 +47,29 @@ void EventManager::Event::trigger() EventManager::Pipe::Pipe() { +#ifdef WIN32 + _pipe(fd, 1024, _O_BINARY); +#else ::pipe(fd); +#endif } int EventManager::Pipe::write(char *buf, unsigned len) { +#ifdef WIN32 + return _write(fd[1], buf, len); +#else return ::write(fd[1], buf, len); +#endif } int EventManager::Pipe::read(char *buf, unsigned len) { +#ifdef WIN32 + return _read(fd[0], buf, len); +#else return ::read(fd[0], buf, len); +#endif } } // namespace Msp diff --git a/source/pollable.cpp b/source/pollable.cpp index 805521d..4b0cb1c 100644 --- a/source/pollable.cpp +++ b/source/pollable.cpp @@ -3,18 +3,28 @@ This file is part of libmspframework Copyright © 2006 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ +#ifdef WIN32 +#include +#include "win32poll.h" +#else #include +#endif #include "pollable.h" namespace Msp { short Pollable::poll(short events, int timeout) { +#ifdef WIN32 + return 0; +#else pollfd pfd={get_fd(), events, 0}; + int result=select(&pfd, 1, timeout); int result=::poll(&pfd, 1, timeout); if(result<=0) return result; return pfd.revents; +#endif } } diff --git a/source/pollable.h b/source/pollable.h index 46cfb23..f676d55 100644 --- a/source/pollable.h +++ b/source/pollable.h @@ -6,6 +6,10 @@ Distributed under the LGPL #ifndef MSP_FRAMEWORK_POLLABLE_H_ #define MSP_FRAMEWORK_POLLABLE_H_ +#ifdef WIN32 +#include "win32poll.h" +#endif + #include namespace Msp { diff --git a/source/poller.cpp b/source/poller.cpp index 0919366..4a623d4 100644 --- a/source/poller.cpp +++ b/source/poller.cpp @@ -27,6 +27,9 @@ Poller::Slot &Poller::add_pollable(Pollable *obj, short events) int Poller::poll(int timeout) { +#ifdef WIN32 + return 0; +#else slots_mutex.lock(); for(list::iterator i=slots.begin(); i!=slots.end();) { @@ -71,6 +74,7 @@ int Poller::poll(int timeout) pfd_mutex.unlock(); return result; +#endif } void Poller::rebuild_pfd() diff --git a/source/poller.h b/source/poller.h index b299b75..dcd3658 100644 --- a/source/poller.h +++ b/source/poller.h @@ -6,7 +6,11 @@ Distributed under the LGPL #ifndef MSP_FRAMEWORK_POLLER_H_ #define MSP_FRAMEWORK_POLLER_H_ +#ifdef WIN32 +#include "win32poll.h" +#else #include +#endif #include #include #include "mutex.h" diff --git a/source/thread.cpp b/source/thread.cpp index 6bc7444..ba0c479 100644 --- a/source/thread.cpp +++ b/source/thread.cpp @@ -21,7 +21,7 @@ void *Thread::join() Thread::~Thread() { - if(valid) + if(valid_) kill(SIGKILL); } diff --git a/source/thread.h b/source/thread.h index b9910ff..51ca0ef 100644 --- a/source/thread.h +++ b/source/thread.h @@ -6,6 +6,10 @@ Distributed under the LGPL #ifndef MSP_FRAMEWORK_THREAD_H_ #define MSP_FRAMEWORK_THREAD_H_ +#ifdef WIN32 +#include "win32signum.h" +#endif + #include namespace Msp { diff --git a/source/win32poll.h b/source/win32poll.h new file mode 100644 index 0000000..f39d53e --- /dev/null +++ b/source/win32poll.h @@ -0,0 +1,29 @@ +/* +This file is part of libmspframework +Copyright © 2006 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ +#ifndef MSP_FRAMEWORK_WIN32POLL_H_ +#define MSP_FRAMEWORK_WIN32POLL_H_ + +#ifdef WIN32 +// From Linux sys/poll.h +struct pollfd +{ + int fd; /* File descriptor to poll. */ + short int events; /* Types of events poller cares about. */ + short int revents; /* Types of events that actually occurred. */ +}; + +#ifndef POLLIN +// From Linux pth.h +#define POLLIN 0x0001 /* any readable data available */ +#endif + +#ifndef POLLNVAL +// From Linux pth.h +#define POLLNVAL 0x0020 /* requested events "invalid" */ +#endif + +#endif // Win32 +#endif -- 2.45.2