BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
rithreadlib.c File Reference
#include "blitzlib.h"
#include "blitzexec.h"
#include <dos/dosextens.h>
#include <dos/dostags.h>
#include <utility/tagitem.h>

Data Structures

struct  thstart
struct  thstate

Macros

#define LVO_CreateNewProc   (-498)
#define STRINGBUFFERSIZE   2048

Functions

void _createthread (void)
void _activethreads (void)
void rithreadlib_libinit (void)
void rithreadlib_libfinit (void)
void startupcode (void)
void cleanup (void)
void c_cleanup (void)
 The exit code of every thread (NP_ExitCode; DOS calls it when the thread's code returns).
ULONG c_activethreads (void)
 ActiveThreads: the number of threads not yet ended.
void c_createthread (const ULONG *r)
 CreateThread name$,address: run the Blitz code at address as a new DOS process (CreateNewProc).
static void c_libinit (void)
 init: a signal of the calling task, the task, dos.library V36.
static void c_libfinit (void)
 finit: wait for the last thread, close dos.library, free the signal.

Variables

struct thstate th
static const char dosname [] = "dos.library"

Macro Definition Documentation

◆ LVO_CreateNewProc

#define LVO_CreateNewProc   (-498)

◆ STRINGBUFFERSIZE

#define STRINGBUFFERSIZE   2048

Function Documentation

◆ _activethreads()

void _activethreads ( void )

◆ _createthread()

void _createthread ( void )

◆ c_activethreads()

ULONG c_activethreads ( void )

ActiveThreads: the number of threads not yet ended.

The function is a word one; the count is returned as a long, the caller takes the low word, which is the count (no defect).

Returns
d0: the count

◆ c_cleanup()

void c_cleanup ( void )

The exit code of every thread (NP_ExitCode; DOS calls it when the thread's code returns).

Counts the thread down (one SUBQ.l, the parent and the threads change the count) and sends the parent task the init's signal when the count is 0.

◆ c_createthread()

void c_createthread ( const ULONG * r)

CreateThread name$,address: run the Blitz code at address as a new DOS process (CreateNewProc).

Nothing without dos.library V36 (init). Counts the thread up, takes 10240 bytes (stringbuffersize + 8192, MEMF_CLEAR) and the start data behind them through memlib's globalloc (freed by memlib's finit; globalloc never returns 0, it raises "Out of Memory!") and saves d0-d7/a1-a6 as they are after that call (d0 = the memory), the address and the memory in the start data, which the new process gets in tc_UserData (set before it can run: Forbid ... Permit around CreateNewProc). startupcode loads them, sets a2/a3/a4 in the memory and jumps to the address. The thread shares the program's globals (a5). Fixed (#838): the original keeps registers, memory and address in single variables - a second CreateThread before the first thread has started gives both threads the second call's. When CreateNewProc returns 0 the count goes down again (Fixed (#1086): the original kept it, ActiveThreads one too high and finit waiting for that thread; the memory stays allocated until memlib's finit, as in the original).

Parameters
ra0: the registers of the call as the thunk pushed them, d0-d7/a0-a6 (d0 = name$, the process name as it is, which CreateNewProc copies; d1 = address)

◆ c_libfinit()

void c_libfinit ( void )
static

finit: wait for the last thread, close dos.library, free the signal.

Waits for the signal until no thread runs (the last one to end sends it). Fixed (#837): the original waits only once, so a signal left from an earlier time the count was 0 lets it go on while threads run. Fixed (#839): the original never frees the signal and leaves the base set; the signal is freed (cleared first) also when dos.library did not open.

◆ c_libinit()

void c_libinit ( void )
static

init: a signal of the calling task, the task, dos.library V36.

The highest free signal of 31 down to 17; without one, dos.library is not opened (dbase = 0, every CreateThread does nothing).

◆ cleanup()

void cleanup ( void )

◆ rithreadlib_libfinit()

void rithreadlib_libfinit ( void )

◆ rithreadlib_libinit()

void rithreadlib_libinit ( void )

◆ startupcode()

void startupcode ( void )

Variable Documentation

◆ dosname

const char dosname[] = "dos.library"
static

◆ th

struct thstate th
Initial value:
= {
.thesignal = (ULONG)-1,
.stringbuffersize = STRINGBUFFERSIZE,
.threadtaglist = { { NP_Entry, (ULONG)startupcode }, { NP_Name, 0 },
{ NP_ExitCode, (ULONG)cleanup }, { TAG_END, TAG_END } },
}
static void cleanup(void)
Cleanup ($C105) at program end: remove the servers, free all nodes of both sets.
Definition intlib.c:165
void startupcode(void)
#define STRINGBUFFERSIZE
Definition rithreadlib.c:99