diff options
author | Bryan Ischo <bryan@ischo.com> | 2008-08-12 13:04:10 +0000 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2008-08-12 13:04:10 +0000 |
commit | 06fcf9839f35d1bbac18819886375b8232d73f35 (patch) | |
tree | b336da3212c8846f7dddaf6297ea153f124ecbd4 | |
parent | 953d590bd9a3508d37552efb89aaa68344466d80 (diff) | |
download | ceph-libs3-06fcf9839f35d1bbac18819886375b8232d73f35.tar.gz |
* Implement required pthreads functions for Windows
-rw-r--r-- | GNUmakefile.mingw | 12 | ||||
-rw-r--r-- | inc/mingw/pthread.h | 45 | ||||
-rw-r--r-- | src/mingw_functions.c | 31 |
3 files changed, 86 insertions, 2 deletions
diff --git a/GNUmakefile.mingw b/GNUmakefile.mingw index 3d5c332..4fc922e 100644 --- a/GNUmakefile.mingw +++ b/GNUmakefile.mingw @@ -103,7 +103,14 @@ CFLAGS += -Wall -Werror -std=c99 -Iinc $(CURL_CFLAGS) $(LIBXML2_CFLAGS) \ # -------------------------------------------------------------------------- -# Default targets are the library and driver program +# Default targets are everything + +.PHONY: all +all: exported test + + +# -------------------------------------------------------------------------- +# Exported targets are the library and driver program .PHONY: exported exported: libs3 s3 headers @@ -186,7 +193,8 @@ $(BUILD)\include\libs3.h: inc\libs3.h .PHONY: test test: $(BUILD)/bin/testsimplexml -$(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o $(BUILD)/lib/libs3.a +$(BUILD)/bin/testsimplexml: $(BUILD)/obj/testsimplexml.o \ + $(BUILD)/obj/simplexml.o -@mkdir $(subst /,\,$(dir $@)) gcc -o $@ $^ $(LIBXML2_LIBS) diff --git a/inc/mingw/pthread.h b/inc/mingw/pthread.h new file mode 100644 index 0000000..b1bd419 --- /dev/null +++ b/inc/mingw/pthread.h @@ -0,0 +1,45 @@ +/** ************************************************************************** + * pthread.h + * + * Copyright 2008 Bryan Ischo <bryan@ischo.com> + * + * This file is part of libs3. + * + * libs3 is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, version 3 of the License. + * + * In addition, as a special exception, the copyright holders give + * permission to link the code of this library and its programs with the + * OpenSSL library, and distribute linked combinations including the two. + * + * libs3 is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License version 3 + * along with libs3, in a file named COPYING. If not, see + * <http://www.gnu.org/licenses/>. + * + ************************************************************************** **/ + +#ifndef PTHREAD_H +#define PTHREAD_H + +// This is a minimal implementation of pthreads on Windows, implementing just +// the APIs needed by libs3 + +unsigned long pthread_self(); + +typedef struct +{ + CRITICAL_SECTION criticalSection; +} pthread_mutex_t; + +void pthread_mutex_init(pthread_mutex_t *mutex, void *); +void pthread_mutex_lock(pthread_mutex_t *mutex); +void pthread_mutex_unlock(pthread_mutex_t *mutex); +void pthread_mutex_destroy(pthread_mutex_t *mutex); + +#endif /* PTHREAD_H */ diff --git a/src/mingw_functions.c b/src/mingw_functions.c index cebad07..ce86c8e 100644 --- a/src/mingw_functions.c +++ b/src/mingw_functions.c @@ -24,8 +24,39 @@ * ************************************************************************** **/ +#include <pthread.h> #include <sys/utsname.h> +unsigned long pthread_self() +{ + return (unsigned long) GetCurrentThreadId(); +} + + +void pthread_mutex_init(pthread_mutex_t *mutex, void *v) +{ + InitializeCriticalSection(&(mutex->criticalSection)); +} + + +void pthread_mutex_lock(pthread_mutex_t *mutex) +{ + EnterCriticalSection(&(mutex->criticalSection)); +} + + +void pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + LeaveCriticalSection(&(mutex->criticalSection)); +} + + +void pthread_mutex_destroy(pthread_mutex_t *mutex) +{ + DeleteCriticalSection(&(mutex->criticalSection)); +} + + int uname(struct utsname *u) { OSVERSIONINFO info; |