Sync to the latest version.
Can be broken or partially implemented.
This commit is contained in:
1
src/deflate.c
Normal file
1
src/deflate.c
Normal file
@@ -0,0 +1 @@
|
||||
#include <bh/deflate.h>
|
||||
0
src/file_posix.c
Normal file
0
src/file_posix.c
Normal file
0
src/file_win.c
Normal file
0
src/file_win.c
Normal file
83
src/io.c
Normal file
83
src/io.c
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <bh/internal/io.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
bh_io_t *bh_io_new(bh_io_table_t *table,
|
||||
size_t size)
|
||||
{
|
||||
bh_io_t *result;
|
||||
|
||||
result = malloc(size);
|
||||
if (result)
|
||||
bh_io_init(result, table);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void bh_io_free(bh_io_t *io)
|
||||
{
|
||||
bh_io_destroy(io);
|
||||
free(io);
|
||||
}
|
||||
|
||||
void bh_io_init(bh_io_t *io,
|
||||
bh_io_table_t *table)
|
||||
{
|
||||
io->table = table;
|
||||
io->flags = 0;
|
||||
}
|
||||
|
||||
void bh_io_destroy(bh_io_t *io)
|
||||
{
|
||||
io->table->destroy(io);
|
||||
}
|
||||
|
||||
size_t bh_io_read(bh_io_t *io,
|
||||
char *data,
|
||||
size_t size)
|
||||
{
|
||||
return io->table->read(io, data, size);
|
||||
}
|
||||
|
||||
size_t bh_io_write(bh_io_t *io,
|
||||
const char* data,
|
||||
size_t size)
|
||||
{
|
||||
return io->table->write(io, data, size);
|
||||
}
|
||||
|
||||
void bh_io_flush(bh_io_t *io)
|
||||
{
|
||||
io->table->flush(io);
|
||||
}
|
||||
|
||||
void bh_io_seek(bh_io_t *io,
|
||||
bh_off_t offset,
|
||||
int dir)
|
||||
{
|
||||
io->table->seek(io, offset, dir);
|
||||
}
|
||||
|
||||
bh_off_t bh_io_tell(bh_io_t *io)
|
||||
{
|
||||
return io->table->tell(io);
|
||||
}
|
||||
|
||||
bh_off_t bh_io_available(bh_io_t *io)
|
||||
{
|
||||
return io->table->available(io);
|
||||
}
|
||||
|
||||
int bh_io_error(bh_io_t *io)
|
||||
{
|
||||
return (io->flags & BH_IO_ERROR) > 0;
|
||||
}
|
||||
|
||||
int bh_io_eof(bh_io_t *io)
|
||||
{
|
||||
return (io->flags & BH_IO_EOF) > 0;
|
||||
}
|
||||
|
||||
void bh_io_clear(bh_io_t *io)
|
||||
{
|
||||
io->table->clear(io);
|
||||
}
|
||||
@@ -216,4 +216,4 @@ void bh_thread_pool_worker(void *arg)
|
||||
bh_mutex_unlock(&pool->lock);
|
||||
bh_cond_broadcast(&pool->done_task);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
113
src/thread_null.c
Normal file
113
src/thread_null.c
Normal file
@@ -0,0 +1,113 @@
|
||||
#include <bh/internal/thread.h>
|
||||
|
||||
int bh_thread_init(bh_thread_t *thread,
|
||||
bh_task_t *task)
|
||||
{
|
||||
(void)thread;
|
||||
(void)task;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bh_thread_t *bh_thread_new(bh_task_t *task)
|
||||
{
|
||||
(void)task;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int bh_thread_join(bh_thread_t *thread)
|
||||
{
|
||||
(void)thread;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_thread_detach(bh_thread_t *thread)
|
||||
{
|
||||
(void)thread;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_init(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void bh_mutex_destroy(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
}
|
||||
|
||||
int bh_mutex_lock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_try_lock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_unlock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_init(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void bh_cond_destroy(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
}
|
||||
|
||||
int bh_cond_wait(bh_cond_t *cond,
|
||||
bh_mutex_t *mutex)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_wait_for(bh_cond_t *cond,
|
||||
bh_mutex_t *mutex,
|
||||
unsigned long timeout)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mutex;
|
||||
(void)timeout;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_signal(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_broadcast(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_thread_pool_init(bh_thread_pool_t *pool,
|
||||
size_t size)
|
||||
{
|
||||
(void)pool;
|
||||
(void)size;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bh_thread_pool_t *bh_thread_pool_new(size_t size)
|
||||
{
|
||||
(void)size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,17 +20,46 @@ static void *bh_thread_run(void *arg)
|
||||
int bh_thread_init(bh_thread_t *thread,
|
||||
bh_task_t *task)
|
||||
{
|
||||
thread->allocated = 0;
|
||||
return pthread_create(&thread->handle, NULL, bh_thread_run, task);
|
||||
}
|
||||
|
||||
bh_thread_t *bh_thread_new(bh_task_t *task)
|
||||
{
|
||||
bh_thread_t *result;
|
||||
|
||||
result = malloc(sizeof(*result));
|
||||
|
||||
if (result && bh_thread_init(result, task))
|
||||
{
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
if (result)
|
||||
result->allocated = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_thread_join(bh_thread_t *thread)
|
||||
{
|
||||
return pthread_join(thread->handle, NULL);
|
||||
int result = pthread_join(thread->handle, NULL);
|
||||
|
||||
if (thread->allocated)
|
||||
free(thread);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_thread_detach(bh_thread_t *thread)
|
||||
{
|
||||
return pthread_detach(thread->handle);
|
||||
int result = pthread_detach(thread->handle);
|
||||
|
||||
if (thread->allocated)
|
||||
free(thread);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_mutex_init(bh_mutex_t *mutex)
|
||||
|
||||
120
src/thread_win.c
Normal file
120
src/thread_win.c
Normal file
@@ -0,0 +1,120 @@
|
||||
#include <bh/internal/thread.h>
|
||||
|
||||
int bh_thread_init_base(bh_thread_t *thread,
|
||||
bh_task_t *task,
|
||||
bh_thread_begin_cb_t begin,
|
||||
bh_thread_end_cb_t end)
|
||||
{
|
||||
(void)thread;
|
||||
(void)task;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bh_thread_t *bh_thread_new_base(bh_task_t *task,
|
||||
bh_thread_begin_cb_t begin,
|
||||
bh_thread_end_cb_t end)
|
||||
{
|
||||
(void)task;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int bh_thread_join(bh_thread_t *thread)
|
||||
{
|
||||
(void)thread;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_thread_detach(bh_thread_t *thread)
|
||||
{
|
||||
(void)thread;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_init(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void bh_mutex_destroy(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
}
|
||||
|
||||
int bh_mutex_lock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_try_lock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_mutex_unlock(bh_mutex_t *mutex)
|
||||
{
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_init(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void bh_cond_destroy(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
}
|
||||
|
||||
int bh_cond_wait(bh_cond_t *cond,
|
||||
bh_mutex_t *mutex)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mutex;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_wait_for(bh_cond_t *cond,
|
||||
bh_mutex_t *mutex,
|
||||
unsigned long timeout)
|
||||
{
|
||||
(void)cond;
|
||||
(void)mutex;
|
||||
(void)timeout;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_signal(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_cond_broadcast(bh_cond_t *cond)
|
||||
{
|
||||
(void)cond;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int bh_thread_pool_init_base(bh_thread_pool_t *pool,
|
||||
size_t size,
|
||||
bh_thread_begin_cb_t begin,
|
||||
bh_thread_end_cb_t end)
|
||||
{
|
||||
(void)pool;
|
||||
(void)size;
|
||||
return -1;
|
||||
}
|
||||
|
||||
bh_thread_pool_t *bh_thread_pool_new_base(size_t size,
|
||||
bh_thread_begin_cb_t begin,
|
||||
bh_thread_end_cb_t end)
|
||||
{
|
||||
(void)size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user