Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
thread_common.c File Reference

Cross-platform thread helpers and registry used by OP_THREAD_SPAWN/OP_THREAD_JOIN. More...

#include <stdint.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
Include dependency graph for thread_common.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  FunThreadEntry
struct  FunTask

Macros

#define FUN_THREAD_CALL
#define FUN_MAX_THREADS   64

Typedefs

typedef pthread_t fun_thread_handle_t
typedef void * fun_thread_ret_t

Functions

static void fun_sleep_ms (long ms)
static void fun_lock (void)
static void fun_unlock (void)
static fun_thread_ret_t fun_thread_main (void *param)
static int fun_alloc_thread_slot (void)
static int fun_thread_spawn (Value fnVal, Value argsMaybe, int hasArgs)
static Value fun_thread_join (int tid)

Variables

static FunThreadEntry g_threads [FUN_MAX_THREADS]
static pthread_mutex_t g_thr_lock = PTHREAD_MUTEX_INITIALIZER

Detailed Description

Cross-platform thread helpers and registry used by OP_THREAD_SPAWN/OP_THREAD_JOIN.

This file provides a tiny cross-platform threading layer (Windows/UNIX) embedded into the VM translation unit. It exposes utilities used by VM opcodes to spawn a function call in a background thread and later join it to retrieve the result.

Notes:

  • Thread registry is bounded by FUN_MAX_THREADS; not intended for high concurrency.
  • Each task owns its argument Values and transfers ownership of the result to the caller on successful join.

Definition in file thread_common.c.

Macro Definition Documentation

◆ FUN_MAX_THREADS

#define FUN_MAX_THREADS   64

Definition at line 51 of file thread_common.c.

◆ FUN_THREAD_CALL

#define FUN_THREAD_CALL

Definition at line 40 of file thread_common.c.

Typedef Documentation

◆ fun_thread_handle_t

typedef pthread_t fun_thread_handle_t

Definition at line 38 of file thread_common.c.

◆ fun_thread_ret_t

typedef void* fun_thread_ret_t

Definition at line 39 of file thread_common.c.

Function Documentation

◆ fun_alloc_thread_slot()

int fun_alloc_thread_slot ( void )
static

Definition at line 165 of file thread_common.c.

◆ fun_lock()

void fun_lock ( void )
static

Definition at line 84 of file thread_common.c.

◆ fun_sleep_ms()

void fun_sleep_ms ( long ms)
inlinestatic

Definition at line 41 of file thread_common.c.

◆ fun_thread_join()

Value fun_thread_join ( int tid)
static

Definition at line 280 of file thread_common.c.

◆ fun_thread_main()

fun_thread_ret_t fun_thread_main ( void * param)
static

Definition at line 102 of file thread_common.c.

◆ fun_thread_spawn()

int fun_thread_spawn ( Value fnVal,
Value argsMaybe,
int hasArgs )
static

Definition at line 181 of file thread_common.c.

◆ fun_unlock()

void fun_unlock ( void )
static

Definition at line 87 of file thread_common.c.

Variable Documentation

◆ g_thr_lock

pthread_mutex_t g_thr_lock = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 83 of file thread_common.c.

◆ g_threads

FunThreadEntry g_threads[FUN_MAX_THREADS]
static

Definition at line 64 of file thread_common.c.