mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-01-11 06:43:56 +00:00
[c-host] added linux thread support
This commit is contained in:
parent
3674b4ed96
commit
9170b24fee
2 changed files with 52 additions and 0 deletions
|
@ -29,6 +29,7 @@ ifdef OS
|
||||||
else
|
else
|
||||||
CC = gcc
|
CC = gcc
|
||||||
OBJS += linux/platform.o
|
OBJS += linux/platform.o
|
||||||
|
LIBS += -lpthread
|
||||||
endif
|
endif
|
||||||
|
|
||||||
all: $(OBJS) $(DLLS)
|
all: $(OBJS) $(DLLS)
|
||||||
|
|
|
@ -19,6 +19,17 @@ Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
struct osThreadHandle
|
||||||
|
{
|
||||||
|
const char * name;
|
||||||
|
osThreadFunction function;
|
||||||
|
void * opaque;
|
||||||
|
pthread_t handle;
|
||||||
|
int resultCode;
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
@ -43,3 +54,43 @@ void os_shmemUnmap()
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void * threadWrapper(void * opaque)
|
||||||
|
{
|
||||||
|
osThreadHandle * handle = (osThreadHandle *)opaque;
|
||||||
|
handle->resultCode = handle->function(handle->opaque);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool os_createThread(const char * name, osThreadFunction function, void * opaque, osThreadHandle ** handle)
|
||||||
|
{
|
||||||
|
*handle = (osThreadHandle*)malloc(sizeof(osThreadHandle));
|
||||||
|
(*handle)->name = name;
|
||||||
|
(*handle)->function = function;
|
||||||
|
(*handle)->opaque = opaque;
|
||||||
|
|
||||||
|
if (pthread_create(&(*handle)->handle, NULL, threadWrapper, *handle) != 0)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("pthread_create failed for thread: %s", name);
|
||||||
|
free(*handle);
|
||||||
|
*handle = NULL;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool os_joinThread(osThreadHandle * handle, int * resultCode)
|
||||||
|
{
|
||||||
|
if (pthread_join(handle->handle, NULL) != 0)
|
||||||
|
{
|
||||||
|
DEBUG_ERROR("pthread_join failed for thread: %s", handle->name);
|
||||||
|
free(handle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resultCode)
|
||||||
|
*resultCode = handle->resultCode;
|
||||||
|
|
||||||
|
free(handle);
|
||||||
|
return true;
|
||||||
|
}
|
Loading…
Reference in a new issue