forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Eliminate fakepthread dependency (#27)
* [WASM] Minimize dependences of pthread * [WASM] Built fakepthread as a part of swift project * [WASM] Always build WasiPthread as static * [WASM] Fix to emit libswiftWasiPthread.a in swift_static * [WASM] Remove unused header file
- Loading branch information
1 parent
7b5516f
commit a2bb344
Showing
18 changed files
with
334 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
//===--- MutexWin32.h - -----------------------------------------*- C++ -*-===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Mutex, ConditionVariable, Read/Write lock, and Scoped lock implementations | ||
// using Windows Slim Reader/Writer Locks and Conditional Variables. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_RUNTIME_MUTEX_WASI_H | ||
#define SWIFT_RUNTIME_MUTEX_WASI_H | ||
|
||
namespace swift { | ||
|
||
typedef void* ConditionHandle; | ||
typedef void* MutexHandle; | ||
typedef void* ReadWriteLockHandle; | ||
|
||
#define SWIFT_CONDITION_SUPPORTS_CONSTEXPR 1 | ||
#define SWIFT_MUTEX_SUPPORTS_CONSTEXPR 1 | ||
#define SWIFT_READWRITELOCK_SUPPORTS_CONSTEXPR 1 | ||
|
||
struct ConditionPlatformHelper { | ||
static constexpr ConditionHandle staticInit() { | ||
return nullptr; | ||
}; | ||
static void init(ConditionHandle &condition) {} | ||
static void destroy(ConditionHandle &condition) {} | ||
static void notifyOne(ConditionHandle &condition) {} | ||
static void notifyAll(ConditionHandle &condition) {} | ||
static void wait(ConditionHandle &condition, MutexHandle &mutex); | ||
}; | ||
|
||
struct MutexPlatformHelper { | ||
static constexpr MutexHandle staticInit() { return nullptr; } | ||
static void init(MutexHandle &mutex, bool checked = false) {} | ||
static void destroy(MutexHandle &mutex) {} | ||
static void lock(MutexHandle &mutex) {} | ||
static void unlock(MutexHandle &mutex) {} | ||
static bool try_lock(MutexHandle &mutex) { return true; } | ||
static void unsafeLock(MutexHandle &mutex) {} | ||
static void unsafeUnlock(MutexHandle &mutex) {} | ||
}; | ||
|
||
struct ReadWriteLockPlatformHelper { | ||
static constexpr ReadWriteLockHandle staticInit() { return nullptr; } | ||
static void init(ReadWriteLockHandle &rwlock) {} | ||
static void destroy(ReadWriteLockHandle &rwlock) {} | ||
static void readLock(ReadWriteLockHandle &rwlock) {} | ||
static bool try_readLock(ReadWriteLockHandle &rwlock) { return true; } | ||
static void readUnlock(ReadWriteLockHandle &rwlock) {} | ||
static void writeLock(ReadWriteLockHandle &rwlock) {} | ||
static bool try_writeLock(ReadWriteLockHandle &rwlock) { return true; } | ||
static void writeUnlock(ReadWriteLockHandle &rwlock) {} | ||
}; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
add_swift_target_library(swiftWasiPthread STATIC IS_STDLIB | ||
Pthread.cpp | ||
INSTALL_IN_COMPONENT stdlib) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
// SPDX-License-Identifier: 0BSD | ||
// prototypes taken from opengroup | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <pthread.h> | ||
#include <semaphore.h> | ||
|
||
#define STUB() do {fprintf(stderr, "FakePthread: unsupported %s\n", __func__);abort();}while(0) | ||
|
||
// mutexes: just no-ops | ||
|
||
int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutex_destroy(pthread_mutex_t *mutex) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutexattr_init(pthread_mutexattr_t *attr) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *type) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutex_lock(pthread_mutex_t *mutex) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutex_trylock(pthread_mutex_t *mutex) { | ||
return 0; | ||
} | ||
|
||
int pthread_mutex_unlock(pthread_mutex_t *mutex) { | ||
return 0; | ||
} | ||
|
||
// pthread_cond: STUB | ||
|
||
int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) { | ||
return 0; | ||
} | ||
|
||
int pthread_cond_destroy(pthread_cond_t *cond) { | ||
return 0; | ||
} | ||
|
||
int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { | ||
STUB(); | ||
} | ||
|
||
int pthread_cond_timedwait(pthread_cond_t *cond, | ||
pthread_mutex_t *mutex, const struct timespec *abstime) { | ||
STUB(); | ||
} | ||
|
||
int pthread_cond_broadcast(pthread_cond_t *cond) { | ||
return 0; | ||
} | ||
|
||
int pthread_cond_signal(pthread_cond_t *cond) { | ||
return 0; | ||
} | ||
|
||
// tls | ||
|
||
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) { | ||
STUB(); | ||
} | ||
|
||
void *pthread_getspecific(pthread_key_t key) { | ||
STUB(); | ||
} | ||
|
||
int pthread_setspecific(pthread_key_t key, const void *value) { | ||
STUB(); | ||
} | ||
|
||
// threads | ||
|
||
pthread_t pthread_self() { | ||
return (pthread_t)1234; | ||
} | ||
|
||
#undef pthread_equal | ||
|
||
int pthread_equal(pthread_t t1, pthread_t t2) { | ||
return t1 == t2; | ||
} | ||
|
||
int pthread_join(pthread_t thread, void **value_ptr) { | ||
STUB(); | ||
} | ||
|
||
int pthread_detach(pthread_t thread) { | ||
STUB(); | ||
} | ||
|
||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg) { | ||
return 0; | ||
} | ||
|
||
// once | ||
|
||
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { | ||
STUB(); | ||
} | ||
|
||
// rwlock | ||
|
||
int pthread_rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { | ||
return 0; | ||
} | ||
|
||
// named semaphores | ||
|
||
sem_t *sem_open(const char *name, int oflag, ...) { | ||
STUB(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.