Files

71 lines
2.3 KiB
C
Raw Permalink Normal View History

/*
2023-12-10 23:19:58 +08:00
* lib/thread/include/thread.h: -- basic thread management
2022-02-03 14:26:20 +08:00
*
* Copyright (c) 2018-2025, Liu chao <lc-soft@live.cn> All rights reserved.
2021-07-24 21:09:05 +08:00
*
2023-12-10 23:19:58 +08:00
* SPDX-License-Identifier: MIT
2021-07-24 21:09:05 +08:00
*
* This file is part of LCUI, distributed under the MIT License found in the
* LICENSE.TXT file in the root directory of this source tree.
2021-07-24 21:09:05 +08:00
*/
2023-04-29 23:38:26 +08:00
#ifndef LIB_THREAD_INCLUDE_THREAD_H
#define LIB_THREAD_INCLUDE_THREAD_H
2021-07-24 21:09:05 +08:00
#define LIBTHREAD_VERSION "1.0.0"
#define LIBTHREAD_VERSION_MAJOR 1
#define LIBTHREAD_VERSION_MINOR 0
2023-04-29 23:38:26 +08:00
#define LIBTHREAD_VERSION_ALTER 0
2023-03-04 22:21:39 +08:00
#define LIBTHREAD_STATIC_BUILD 1
2023-04-29 23:38:26 +08:00
#ifndef LIBTHREAD_PUBLIC
#if defined(_MSC_VER) && !defined(LIBTHREAD_STATIC_BUILD)
#ifdef LIBTHREAD_DLL_EXPORT
#define LIBTHREAD_PUBLIC __declspec(dllexport)
#else
#define LIBTHREAD_PUBLIC __declspec(dllimport)
#endif
#elif __GNUC__ >= 4
#define LIBTHREAD_PUBLIC extern __attribute__((visibility("default")))
#else
#define LIBTHREAD_PUBLIC extern
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
2021-07-24 21:09:05 +08:00
2022-02-03 14:26:20 +08:00
typedef unsigned long thread_t;
typedef union thread_mutex_record_t *thread_mutex_t;
typedef union thread_cond_record_t *thread_cond_t;
2021-07-24 21:09:05 +08:00
2023-04-29 23:38:26 +08:00
LIBTHREAD_PUBLIC int thread_mutex_init(thread_mutex_t *mutex);
LIBTHREAD_PUBLIC void thread_mutex_destroy(thread_mutex_t *mutex);
LIBTHREAD_PUBLIC int thread_mutex_trylock(thread_mutex_t *mutex);
LIBTHREAD_PUBLIC int thread_mutex_lock(thread_mutex_t *mutex);
LIBTHREAD_PUBLIC int thread_mutex_unlock(thread_mutex_t *mutex);
2021-07-24 21:09:05 +08:00
2023-04-29 23:38:26 +08:00
LIBTHREAD_PUBLIC int thread_cond_init(thread_cond_t *cond);
LIBTHREAD_PUBLIC int thread_cond_destroy(thread_cond_t *cond);
LIBTHREAD_PUBLIC int thread_cond_wait(thread_cond_t *cond,
thread_mutex_t *mutex);
LIBTHREAD_PUBLIC int thread_cond_timedwait(thread_cond_t *cond,
thread_mutex_t *mutex,
unsigned int ms);
LIBTHREAD_PUBLIC int thread_cond_signal(thread_cond_t *cond);
LIBTHREAD_PUBLIC int thread_cond_broadcast(thread_cond_t *cond);
2021-07-24 21:09:05 +08:00
2023-04-29 23:38:26 +08:00
LIBTHREAD_PUBLIC thread_t thread_self(void);
LIBTHREAD_PUBLIC int thread_create(thread_t *tidp, void (*start_rtn)(void *),
void *arg);
LIBTHREAD_PUBLIC int thread_join(thread_t thread, void **retval);
LIBTHREAD_PUBLIC void thread_cancel(thread_t thread);
LIBTHREAD_PUBLIC void thread_exit(void *retval);
2022-02-03 14:26:20 +08:00
2023-04-29 23:38:26 +08:00
#ifdef __cplusplus
}
#endif
2022-02-03 14:26:20 +08:00
#endif