Skip to content

Commit bc9b8b5

Browse files
author
icex2
committed
refactor(api): Thread and log API
Split files and add name spacing.
1 parent dedbdaf commit bc9b8b5

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

src/api/log.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef BEMANITOOLS_API_THREAD_H
2+
#define BEMANITOOLS_API_THREAD_H
3+
4+
#include <stdint.h>
5+
6+
#ifdef __GNUC__
7+
/* Bemanitools is compiled with GCC (MinGW, specifically) as of version 5 */
8+
#define LOG_CHECK_FMT __attribute__((format(printf, 2, 3)))
9+
#else
10+
/* Compile it out for MSVC plebs */
11+
#define LOG_CHECK_FMT
12+
#endif
13+
14+
/* An AVS-style logger function. Comes in four flavors: misc, info, warning,
15+
and fatal, with increasing severity. Fatal loggers do not return, they
16+
abort the running process after writing their message to the log.
17+
18+
"module" is an arbitrary short string identifying the source of the log
19+
message. The name of the calling DLL is a good default choice for this
20+
string, although you might want to identify a module within your DLL here
21+
instead.
22+
23+
"fmt" is a printf-style format string. Depending on the context in which
24+
your DLL is running you might end up calling a logger function exported
25+
from libavs, which has its own printf implementation (including a number of
26+
proprietary extensions), so don't use any overly exotic formats. */
27+
28+
typedef void (*btapi_log_formatter_t)(const char *module, const char *fmt, ...)
29+
LOG_CHECK_FMT;
30+
31+
#endif

src/api/thread.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef BEMANITOOLS_API_THREAD_H
2+
#define BEMANITOOLS_API_THREAD_H
3+
4+
#include <stdint.h>
5+
6+
/* An API for spawning threads. This API is defined by libavs, although
7+
Bemanitools itself may supply compatible implementations of these functions
8+
to your DLL, depending on the context in which it runs.
9+
10+
NOTE: You may only use the logging functions from a thread where Bemanitools
11+
calls you, or a thread that you create using this API. Failure to observe
12+
this restriction will cause the process to crash. This is a limitation of
13+
libavs itself, not Bemanitools. */
14+
15+
typedef int (*btapi_thread_create_t)(
16+
int (*proc)(void *), void *ctx, uint32_t stack_sz, unsigned int priority);
17+
typedef void (*btapi_thread_join_t)(int thread_id, int *result);
18+
typedef void (*btapi_thread_destroy_t)(int thread_id);
19+
20+
#endif

0 commit comments

Comments
 (0)