summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread
diff options
context:
space:
mode:
Diffstat (limited to 'fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread')
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt81
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt46
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c92
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c48
-rw-r--r--fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c36
5 files changed, 0 insertions, 303 deletions
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt
deleted file mode 100644
index 67819eca2..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/CMakeLists.txt
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-cmake_minimum_required(VERSION 3.14)
-
-include(CheckPIESupported)
-
-project(pthread)
-
-################ runtime settings ################
-string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
-if (APPLE)
- add_definitions(-DBH_PLATFORM_DARWIN)
-endif ()
-
-# Resetdefault linker flags
-set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
-set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "")
-
-# WAMR features switch
-
-# Set WAMR_BUILD_TARGET, currently values supported:
-# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]",
-# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]"
-if (NOT DEFINED WAMR_BUILD_TARGET)
- if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)")
- set (WAMR_BUILD_TARGET "AARCH64")
- elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64")
- set (WAMR_BUILD_TARGET "RISCV64")
- elseif (CMAKE_SIZEOF_VOID_P EQUAL 8)
- # Build as X86_64 by default in 64-bit platform
- set (WAMR_BUILD_TARGET "X86_64")
- elseif (CMAKE_SIZEOF_VOID_P EQUAL 4)
- # Build as X86_32 by default in 32-bit platform
- set (WAMR_BUILD_TARGET "X86_32")
- else ()
- message(SEND_ERROR "Unsupported build target platform!")
- endif ()
-endif ()
-
-if (NOT CMAKE_BUILD_TYPE)
- set (CMAKE_BUILD_TYPE Release)
-endif ()
-
-set(WAMR_BUILD_INTERP 1)
-set(WAMR_BUILD_AOT 1)
-set(WAMR_BUILD_JIT 0)
-set(WAMR_BUILD_LIBC_BUILTIN 1)
-set(WAMR_BUILD_FAST_INTERP 1)
-set(WAMR_BUILD_LIB_PTHREAD 1)
-set(WAMR_BUILD_LIB_PTHREAD_SEMAPHORE 1)
-
-# compiling and linking flags
-if (NOT (CMAKE_C_COMPILER MATCHES ".*clang.*" OR CMAKE_C_COMPILER_ID MATCHES ".*Clang"))
- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
-endif ()
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat -Wformat-security")
-
-# build out vmlib
-set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
-include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
-
-add_library(vmlib ${WAMR_RUNTIME_LIB_SOURCE})
-################################################
-
-
-################ wasm application ################
-add_subdirectory(wasm-apps)
-
-################ wamr runtime ################
-include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake)
-
-set (RUNTIME_SOURCE_ALL
- ${CMAKE_CURRENT_LIST_DIR}/../../product-mini/platforms/linux/main.c
- ${UNCOMMON_SHARED_SOURCE}
-)
-add_executable (iwasm ${RUNTIME_SOURCE_ALL})
-check_pie_supported()
-set_target_properties (iwasm PROPERTIES POSITION_INDEPENDENT_CODE ON)
-target_link_libraries(iwasm vmlib -lpthread -lm -ldl)
-
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt
deleted file mode 100644
index d7352e427..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/CMakeLists.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (C) 2019 Intel Corporation. All rights reserved.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-cmake_minimum_required(VERSION 2.8)
-project(wasm-apps)
-
-set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
-
-if (APPLE)
- set (HAVE_FLAG_SEARCH_PATHS_FIRST 0)
- set (CMAKE_C_LINK_FLAGS "")
- set (CMAKE_CXX_LINK_FLAGS "")
-endif ()
-set(CMAKE_SYSTEM_PROCESSOR wasm32)
-set (CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot)
-
-if (NOT DEFINED WASI_SDK_DIR)
- set (WASI_SDK_DIR "/opt/wasi-sdk")
-endif ()
-
-set (CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments")
-set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=32768")
-set (CMAKE_C_COMPILER_TARGET "wasm32")
-set (CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang")
-
-set (DEFINED_SYMBOLS
-"${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt")
-
-set (CMAKE_EXE_LINKER_FLAGS
- "-Wl,--shared-memory,--max-memory=131072, \
- -Wl,--no-entry,--strip-all, \
- -Wl,--export=__heap_base,--export=__data_end \
- -Wl,--export=__wasm_call_ctors \
- -Wl,--export=main -Wl,--export=__main_argc_argv \
- -Wl,--allow-undefined"
- #-Wl,--allow-undefined-file=${DEFINED_SYMBOLS}"
-)
-
-add_executable(test.wasm main.c)
-target_link_libraries(test.wasm)
-
-add_executable(main_thread_exception.wasm main_thread_exception.c)
-target_link_libraries(main_thread_exception.wasm)
-
-add_executable(main_global_atomic.wasm main_global_atomic.c)
-target_link_libraries(main_global_atomic.wasm) \ No newline at end of file
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c
deleted file mode 100644
index 2b9581f1c..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main.c
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#include <stdio.h>
-#include <pthread.h>
-#include <semaphore.h>
-
-static pthread_mutex_t mutex;
-static pthread_cond_t cond;
-static sem_t *sem;
-
-static void *
-thread(void *arg)
-{
- int *num = (int *)arg;
-
- pthread_mutex_lock(&mutex);
- printf("thread start \n");
-
- for (int i = 0; i < 10; i++) {
- *num = *num + 1;
- printf("num: %d\n", *num);
- }
-
- pthread_cond_signal(&cond);
- pthread_mutex_unlock(&mutex);
- sem_post(sem);
-
- printf("thread exit \n");
-
- return NULL;
-}
-
-int
-main(int argc, char *argv[])
-{
- pthread_t tid;
- int num = 0, ret = -1;
-
- if (pthread_mutex_init(&mutex, NULL) != 0) {
- printf("Failed to init mutex.\n");
- return -1;
- }
- if (pthread_cond_init(&cond, NULL) != 0) {
- printf("Failed to init cond.\n");
- goto fail1;
- }
-
- // O_CREAT and S_IRGRPS_IRGRP | S_IWGRP on linux (glibc), initial value is 0
-
- if (!(sem = sem_open("tessstsem", 0100, 0x10 | 0x20, 0))) {
- printf("Failed to open sem. %p\n", sem);
- goto fail2;
- }
-
- pthread_mutex_lock(&mutex);
- if (pthread_create(&tid, NULL, thread, &num) != 0) {
- printf("Failed to create thread.\n");
- pthread_mutex_unlock(&mutex);
- goto fail3;
- }
-
- printf("cond wait start\n");
- pthread_cond_wait(&cond, &mutex);
- pthread_mutex_unlock(&mutex);
- printf("cond wait success.\n");
-
- if (sem_wait(sem) != 0) {
- printf("Failed to wait sem.\n");
- }
- else {
- printf("sem wait success.\n");
- }
-
- if (pthread_join(tid, NULL) != 0) {
- printf("Failed to join thread.\n");
- }
-
- ret = 0;
-
-fail3:
- sem_close(sem);
- sem_unlink("tessstsem");
-fail2:
- pthread_cond_destroy(&cond);
-fail1:
- pthread_mutex_destroy(&mutex);
-
- return ret;
-} \ No newline at end of file
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c
deleted file mode 100644
index dafbea886..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_global_atomic.c
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#include <stdio.h>
-#include <pthread.h>
-
-#define MAX_NUM_THREADS 4
-#define NUM_ITER 1000
-
-int g_count = 0;
-
-static void *
-thread(void *arg)
-{
- for (int i = 0; i < NUM_ITER; i++) {
- __atomic_fetch_add(&g_count, 1, __ATOMIC_SEQ_CST);
- }
-
- return NULL;
-}
-
-int
-main(int argc, char **argv)
-{
- pthread_t tids[MAX_NUM_THREADS];
-
- for (int i = 0; i < MAX_NUM_THREADS; i++) {
- if (pthread_create(&tids[i], NULL, thread, NULL) != 0) {
- printf("Thread creation failed\n");
- }
- }
-
- for (int i = 0; i < MAX_NUM_THREADS; i++) {
- if (pthread_join(tids[i], NULL) != 0) {
- printf("Thread join failed\n");
- }
- }
-
- printf("Value of counter after update: %d (expected=%d)\n", g_count,
- MAX_NUM_THREADS * NUM_ITER);
- if (g_count != MAX_NUM_THREADS * NUM_ITER) {
- __builtin_trap();
- }
-
- return -1;
-} \ No newline at end of file
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c
deleted file mode 100644
index 80f170d40..000000000
--- a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/samples/multi-thread/wasm-apps/main_thread_exception.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2019 Intel Corporation. All rights reserved.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-#include <stdio.h>
-#include <pthread.h>
-
-typedef struct ThreadArgs {
- int start;
- int length;
-} ThreadArgs;
-
-void *
-thread(void *args)
-{
- while (1) {
- /* When other threads (including main thread) throw exception,
- this thread can successfully exit the dead loop */
- }
-}
-
-int
-main()
-{
- pthread_t tids;
-
- if (pthread_create(&tids, NULL, thread, NULL) != 0) {
- printf("pthread_create failed\n");
- }
-
- /* Trigger an exception */
- __builtin_trap();
-
- return 0;
-}