dev 移动文件夹,添加kfifo,修改CMakeLists
This commit is contained in:
parent
ea7c81cea0
commit
e3fa5fd34b
4
.gitignore
vendored
4
.gitignore
vendored
@ -2,10 +2,8 @@
|
||||
!.gitignore
|
||||
!README.txt
|
||||
!version.txt
|
||||
!ssocket.h
|
||||
!tthread.h
|
||||
!sysenv.h
|
||||
!*/
|
||||
!include/*
|
||||
!test/client/client.c
|
||||
!test/client/CMakeLists.txt
|
||||
!test/server/server.c
|
||||
|
0
include/kfifo.h
Normal file
0
include/kfifo.h
Normal file
@ -3,15 +3,14 @@
|
||||
|
||||
#include "sysenv.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#if _OS_WIN
|
||||
#include <CoreWindow.h>
|
||||
//#include <handleapi.h>
|
||||
//#include <synchapi.h>
|
||||
//#include <processthreadsapi.h>
|
||||
//#define INFINITE 0xFFFFFFFF // Infinite timeout
|
||||
//#define WAIT_FAILED ((DWORD)0xFFFFFFFF)
|
||||
//#include <WinBase.h>
|
||||
#include <Windows.h>
|
||||
|
||||
typedef DWORD TID;
|
||||
typedef CRITICAL_SECTION MUTEX;
|
||||
typedef CONDITION_VARIABLE COND;
|
||||
@ -102,11 +101,12 @@ static inline void thread_exit(void) {
|
||||
static inline int thread_join(TID tid) {
|
||||
#if _OS_WIN
|
||||
HANDLE h = OpenThread(THREAD_ALL_ACCESS, 0, tid);
|
||||
//if (h == NULL) { return ERR_THREAD_WIN_OPEN_THREAD; }
|
||||
if (WaitForSingleObject(h, INFINITE) == WAIT_FAILED) { return ERR_THREAD_JOIN; }
|
||||
if (!CloseHandle(h)) { return ERR_THREAD_WIN_CLOSE_HANDLE; }
|
||||
if (h != NULL) {
|
||||
if (WaitForSingleObject(h, INFINITE) == WAIT_FAILED) { return -ERR_THREAD_JOIN; }
|
||||
if (!CloseHandle(h)) { return -ERR_THREAD_WIN_CLOSE_HANDLE; }
|
||||
}
|
||||
#elif _OS_LINUX
|
||||
if (pthread_join(tid, NULL) != 0) { return ERR_THREAD_JOIN; }
|
||||
if (pthread_join(tid, NULL) != 0) { return -ERR_THREAD_JOIN; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -125,7 +125,7 @@ static inline int thread_mutex_init(MUTEX* mutex) {
|
||||
#if _OS_WIN
|
||||
InitializeCriticalSection(mutex);
|
||||
#elif _OS_LINUX
|
||||
if (pthread_mutex_init() != 0) { return ERR_THREAD_MUTEX_INIT; }
|
||||
if (pthread_mutex_init() != 0) { return -ERR_THREAD_MUTEX_INIT; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -133,7 +133,7 @@ static inline int thread_mutex_init(MUTEX* mutex) {
|
||||
static inline int thread_mutex_destroy(MUTEX* mutex) {
|
||||
#if _OS_WIN
|
||||
#elif _OS_LINUX
|
||||
if (pthread_mutex_destroy(mutex) != 0) { return ERR_THREAD_MUTEX_DESTROY; }
|
||||
if (pthread_mutex_destroy(mutex) != 0) { return -ERR_THREAD_MUTEX_DESTROY; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -142,7 +142,7 @@ static inline int thread_mutex_lock(MUTEX* mutex) {
|
||||
#if _OS_WIN
|
||||
EnterCriticalSection(mutex);
|
||||
#elif _OS_LINUX
|
||||
if (pthread_mutex_lock(mutex) != 0) { return ERR_THREAD_MUTEX_LOCK; }
|
||||
if (pthread_mutex_lock(mutex) != 0) { return -ERR_THREAD_MUTEX_LOCK; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -151,7 +151,7 @@ static inline int thread_mutex_unlock(MUTEX* mutex) {
|
||||
#if _OS_WIN
|
||||
LeaveCriticalSection(mutex);
|
||||
#elif _OS_LINUX
|
||||
if (pthread_mutex_unlock(mutex) != 0) { return ERR_THREAD_MUTEX_UNLOCK; }
|
||||
if (pthread_mutex_unlock(mutex) != 0) { return -ERR_THREAD_MUTEX_UNLOCK; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -160,9 +160,9 @@ static inline int thread_mutex_unlock(MUTEX* mutex) {
|
||||
static inline int thread_cond_init(COND* cond) {
|
||||
#if _OS_WIN
|
||||
InitializeConditionVariable(cond);
|
||||
if (cond == NULL) { return ERR_THREAD_COND_INIT; }
|
||||
if (cond == NULL) { return -ERR_THREAD_COND_INIT; }
|
||||
#elif _OS_LINUX
|
||||
if (pthread_cond_init(cond) != 0) { return ERR_THREAD_COND_INIT; }
|
||||
if (pthread_cond_init(cond) != 0) { return -ERR_THREAD_COND_INIT; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -170,7 +170,7 @@ static inline int thread_cond_init(COND* cond) {
|
||||
static inline int thread_cond_destroy(COND* cond) {
|
||||
#if _OS_WIN
|
||||
#elif _OS_LINUX
|
||||
if (pthread_cond_destroy(cond) != 0) { return ERR_THREAD_COND_DESTROY; }
|
||||
if (pthread_cond_destroy(cond) != 0) { return -ERR_THREAD_COND_DESTROY; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -179,7 +179,7 @@ static inline int thread_cond_singal(COND* cond) {
|
||||
#if _OS_WIN
|
||||
WakeConditionVariable(cond);
|
||||
#elif _OS_LINUX
|
||||
if (pthread_cond_signal(cond) != 0) { return ERR_THREAD_COND_SINGAL; }
|
||||
if (pthread_cond_signal(cond) != 0) { return -ERR_THREAD_COND_SINGAL; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
@ -188,16 +188,16 @@ static inline int thread_cond_broadcast(COND* cond) {
|
||||
#if _OS_WIN
|
||||
WakeAllConditionVariable(cond);
|
||||
#elif _OS_LINUX
|
||||
if (pthread_cond_broadcast(cond) != 0) { return ERR_THREAD_COND_BROADCAST; }
|
||||
if (pthread_cond_broadcast(cond) != 0) { return -ERR_THREAD_COND_BROADCAST; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
||||
|
||||
static inline int thread_cond_wait(COND* cond, MUTEX* mutex) {
|
||||
#if _OS_WIN
|
||||
int res = SleepConditionVariableCS(cond, mutex, INFINITE);
|
||||
if (SleepConditionVariableCS(cond, mutex, INFINITE) != 0) { return -ERR_THREAD_COND_WAIT; }
|
||||
#elif _OS_LINUX
|
||||
if (pthread_cond_wait(cond, mutex) != 0) { return ERR_THREAD_COND_WAIT; }
|
||||
if (pthread_cond_wait(cond, mutex) != 0) { return -ERR_THREAD_COND_WAIT; }
|
||||
#endif
|
||||
return ERR_THREAD_SUCCESS;
|
||||
}
|
@ -6,6 +6,7 @@ set(EXECUTABLE_OUTPUT_PATH ../)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(SRC_FILE client.c)
|
||||
|
||||
include_directories(../../include)
|
||||
add_executable(${PROJECT_NAME} ${SRC_FILE})
|
||||
|
||||
if(WIN32)
|
||||
|
@ -6,6 +6,7 @@ set(EXECUTABLE_OUTPUT_PATH ../)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(SRC_FILE server.c)
|
||||
|
||||
include_directories(../../include)
|
||||
add_executable(${PROJECT_NAME} ${SRC_FILE})
|
||||
|
||||
if(WIN32)
|
||||
|
@ -6,6 +6,7 @@ set(EXECUTABLE_OUTPUT_PATH ../)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(SRC_FILE thread.c)
|
||||
|
||||
include_directories(../../include)
|
||||
add_executable(${PROJECT_NAME} ${SRC_FILE})
|
||||
|
||||
if(WIN32)
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../../tthread.h"
|
||||
|
||||
#include <tthread.h>
|
||||
|
||||
MUTEX mutex;
|
||||
COND cond;
|
||||
|
Loading…
x
Reference in New Issue
Block a user