rename definitions
This commit is contained in:
parent
c863bab412
commit
e98a4b220a
@ -2,24 +2,24 @@
|
||||
#include "../System Abstraction/cdb_sustem.h"
|
||||
|
||||
struct fp_File_impl{
|
||||
sus_File file;
|
||||
sys_File file;
|
||||
unsigned long pageSize;
|
||||
};
|
||||
|
||||
//Creates a new file, opens it, and resizes it to the specified page size
|
||||
fp_File fp_fileNew(char * fileName, unsigned long pageSize){ //there shouldn't be a page, longer than 4gb
|
||||
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_NEW);
|
||||
sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_NEW);
|
||||
if(currentFile == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
|
||||
fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl));
|
||||
returnable->pageSize = pageSize;
|
||||
returnable->file = currentFile;
|
||||
|
||||
//The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize
|
||||
if(sus_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||
sus_heapFree(returnable);
|
||||
//The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize
|
||||
if(sys_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||
sys_heapFree(returnable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -27,18 +27,18 @@ fp_File fp_fileNew(char * fileName, unsigned long pageSize){ //there shouldn't b
|
||||
}
|
||||
|
||||
fp_File fp_fileTemp(char * fileName, unsigned long pageSize){
|
||||
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_TEMP);
|
||||
sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_TEMP);
|
||||
if(currentFile == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
|
||||
fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl));
|
||||
returnable->pageSize = pageSize;
|
||||
returnable->file = currentFile;
|
||||
|
||||
//The new File will be initialized with one memroy Unit (Byte), so this code resizes it to the pageSize
|
||||
if(sus_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||
sus_heapFree(returnable);
|
||||
//The new File will be initialized with one memory Unit (Byte), so this code resizes it to the pageSize
|
||||
if(sys_fileResize(returnable->file, pageSize - 1) == NULL){
|
||||
sys_heapFree(returnable);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -46,12 +46,12 @@ fp_File fp_fileTemp(char * fileName, unsigned long pageSize){
|
||||
}
|
||||
|
||||
fp_File fp_fileOpen(char * fileName){
|
||||
sus_File currentFile = sus_fileOpenInMem(fileName, SUS_FILE_NOTHING);
|
||||
sys_File currentFile = sys_fileOpenInMem(fileName, SYS_FILE_NOTHING);
|
||||
if(currentFile == NULL){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp_File returnable = sus_heapAlloc(sizeof(struct fp_File_impl));
|
||||
fp_File returnable = sys_heapAlloc(sizeof(struct fp_File_impl));
|
||||
//returnable->pageSize = pageSize;
|
||||
returnable->file = currentFile;
|
||||
|
||||
@ -67,9 +67,9 @@ void fp_fileInit(fp_File file, unsigned long pageSize){
|
||||
|
||||
//negative values indicate the removable of the latest pages; so this library doesn't need more functions
|
||||
void * fp_fileAppendPages(fp_File file, long numberOfPages){
|
||||
void *newMem = sus_fileResize(file->file, file->pageSize * numberOfPages);
|
||||
void *newMem = sys_fileResize(file->file, file->pageSize * numberOfPages);
|
||||
if(newMem == NULL) {
|
||||
sus_fileClose(file->file);
|
||||
sys_fileClose(file->file);
|
||||
file->file = NULL;
|
||||
file->pageSize = 0;
|
||||
return NULL;
|
||||
@ -78,18 +78,18 @@ void * fp_fileAppendPages(fp_File file, long numberOfPages){
|
||||
return newMem;
|
||||
}
|
||||
|
||||
void * fp_fileToMemroy(fp_File file){
|
||||
return sus_fileFileToMemroy(file->file);
|
||||
void * fp_fileToMemory(fp_File file){
|
||||
return sys_fileFileToMemory(file->file);
|
||||
}
|
||||
|
||||
void fp_fileFlush(fp_File file) {
|
||||
sus_fileFlush(file->file);
|
||||
sys_fileFlush(file->file);
|
||||
}
|
||||
|
||||
void fp_fileClose(fp_File file){
|
||||
if(file->file != NULL) {
|
||||
sus_fileClose(file->file);
|
||||
sys_fileClose(file->file);
|
||||
}
|
||||
|
||||
sus_heapFree(file);
|
||||
sys_heapFree(file);
|
||||
}
|
@ -12,7 +12,7 @@ void fp_fileSetPageSize(fp_File file, unsigned long pageSize);
|
||||
//negative values indicate the removable of the latest pages; so this library doesn't need more functions
|
||||
void * fp_fileAppendPages(fp_File file, long numberOfPages);
|
||||
|
||||
void * fp_fileToMemroy(fp_File file);
|
||||
void * fp_fileToMemory(fp_File file);
|
||||
|
||||
void fp_fileFlush(fp_File file);
|
||||
|
||||
|
@ -1,46 +0,0 @@
|
||||
//TODO finland up
|
||||
|
||||
//#include <stddef.h>
|
||||
|
||||
// TODO should propably be placed in a global header
|
||||
#define sus_Bool char
|
||||
#define sus_True 1
|
||||
#define sus_False 0
|
||||
|
||||
#define SUS_FILE_TEMP ((1UL << 0) | SUS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file
|
||||
#define SUS_FILE_NEW (1UL << 1)
|
||||
#define SUS_FILE_NOTHING 0UL
|
||||
|
||||
//Naming: firstly the package, then the topic, lastly the operation
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
//Operating System independent implementation
|
||||
typedef struct sus_File_impl * sus_File;
|
||||
|
||||
// File IO API
|
||||
//sus_File sus_file_OpenInMem(char * fileName, unsigned long parameter);
|
||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memroy of the current process
|
||||
//void * sus_fileOpenNewinMem(char * fileName); //prevent user errors
|
||||
//void * sus_fileOpenTempFileinMem(char * fileName);
|
||||
|
||||
void * sus_fileFileToMemroy(sus_File file); //retrieves the memroy Pointer of where the file was mapped in memroy
|
||||
|
||||
sus_Bool sus_fileExists(char * fileName); //check if a file exists in the specified path with the specified name
|
||||
void sus_fileClose(sus_File file); //Closes the file mapping and all the system specific stuff for that mapping
|
||||
void sus_fileFlush(sus_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance)
|
||||
void * sus_fileResize(sus_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size
|
||||
void sus_fileDelete(char * fileName);
|
||||
void sus_fileRename(char * fileName, char * newFileName);
|
||||
|
||||
// Memory API
|
||||
void * sus_heapAlloc(size_t bytes); // returns NULL, if there is no memroy left or an error occured
|
||||
void * sus_heapResize(void * memroy, size_t newBytes); // returns NULL, if there is no memroy left or an error occured
|
||||
void sus_heapFree(void * memroy); // what should this function do, if an error occurse..
|
||||
|
||||
// Networking API -- coming soon, cuz idk
|
||||
|
||||
//Threads
|
||||
typedef __attribute__ ((sysv_abi)) void (*sus_threadProc)(void * arg);
|
||||
sus_Bool sus_threadNew(sus_threadProc proc, void * arg);
|
||||
void sus_threadSleep(unsigned long seconds);
|
46
System Abstraction/cdb_system.h
Normal file
46
System Abstraction/cdb_system.h
Normal file
@ -0,0 +1,46 @@
|
||||
//TODO finland up
|
||||
|
||||
//#include <stddef.h>
|
||||
|
||||
// TODO should propably be placed in a global header
|
||||
#define sys_Bool char
|
||||
#define sys_True 1
|
||||
#define sys_False 0
|
||||
|
||||
#define SYS_FILE_TEMP ((1UL << 0) | SYS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file
|
||||
#define SYS_FILE_NEW (1UL << 1)
|
||||
#define SYS_FILE_NOTHING 0UL
|
||||
|
||||
//Naming: firstly the package, then the topic, lastly the operation
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
//Operating System independent implementation
|
||||
typedef struct sys_File_impl * sys_File;
|
||||
|
||||
// File IO API
|
||||
//sys_File sys_file_OpenInMem(char * fileName, unsigned long parameter);
|
||||
sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memory of the current process
|
||||
//void * sys_fileOpenNewinMem(char * fileName); //prevent user errors
|
||||
//void * sys_fileOpenTempFileinMem(char * fileName);
|
||||
|
||||
void * sys_fileFileToMemory(sys_File file); //retrieves the memory Pointer of where the file was mapped in memory
|
||||
|
||||
sys_Bool sys_fileExists(char * fileName); //check if a file exists in the specified path with the specified name
|
||||
void sys_fileClose(sys_File file); //Closes the file mapping and all the system specific stuff for that mapping
|
||||
void sys_fileFlush(sys_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance)
|
||||
void * sys_fileResize(sys_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size
|
||||
void sys_fileDelete(char * fileName);
|
||||
void sys_fileRename(char * fileName, char * newFileName);
|
||||
|
||||
// Memory API
|
||||
void * sys_heapAlloc(size_t bytes); // returns NULL, if there is no memory left or an error occured
|
||||
void * sys_heapResize(void * memory, size_t newBytes); // returns NULL, if there is no memory left or an error occured
|
||||
void sys_heapFree(void * memory); // what should this function do, if an error occurse..
|
||||
|
||||
// Networking API -- coming soon, cuz idk
|
||||
|
||||
//Threads
|
||||
typedef __attribute__ ((sysv_abi)) void (*sys_threadProc)(void * arg);
|
||||
sys_Bool sys_threadNew(sys_threadProc proc, void * arg);
|
||||
void sys_threadSleep(unsigned long seconds);
|
@ -1,4 +1,4 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#define _GNU_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@ -8,15 +8,15 @@
|
||||
#include <sys/file.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
struct sus_File_impl{
|
||||
void * memroy;
|
||||
struct sys_File_impl{
|
||||
void * memory;
|
||||
size_t length;
|
||||
int fd;
|
||||
};
|
||||
|
||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
||||
sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter) {
|
||||
int flags = O_RDWR;
|
||||
if(parameter & SUS_FILE_NEW) flags |= O_CREAT | O_EXCL;
|
||||
if(parameter & SYS_FILE_NEW) flags |= O_CREAT | O_EXCL;
|
||||
int fd = open(fileName, flags, S_IRWXU);
|
||||
if(fd == -1) return NULL;
|
||||
|
||||
@ -31,7 +31,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if((parameter & SUS_FILE_TEMP) == SUS_FILE_TEMP) unlink(fileName);
|
||||
if((parameter & SYS_FILE_TEMP) == SYS_FILE_TEMP) unlink(fileName);
|
||||
|
||||
if(info.st_size == 0) {
|
||||
write(fd, "", 1);
|
||||
@ -45,61 +45,61 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sus_File file = (sus_File) sus_heapAlloc(sizeof(struct sus_File_impl));
|
||||
file->memroy = mem;
|
||||
sys_File file = (sys_File) sys_heapAlloc(sizeof(struct sys_File_impl));
|
||||
file->memory = mem;
|
||||
file->length = info.st_size;
|
||||
file->fd = fd;
|
||||
return file;
|
||||
}
|
||||
|
||||
void * sus_fileFileToMemroy(sus_File file) {
|
||||
return file->memroy;
|
||||
void * sys_fileFileToMemory(sys_File file) {
|
||||
return file->memory;
|
||||
}
|
||||
|
||||
sus_Bool sus_fileExists(char * fileName) {
|
||||
sys_Bool sys_fileExists(char * fileName) {
|
||||
struct stat bro;
|
||||
return !stat(fileName, &bro);
|
||||
}
|
||||
|
||||
void sus_fileClose(sus_File file) {
|
||||
if(file->memroy != NULL) {
|
||||
msync(file->memroy, file->length, MS_SYNC);
|
||||
munmap(file->memroy, file->length);
|
||||
void sys_fileClose(sys_File file) {
|
||||
if(file->memory != NULL) {
|
||||
msync(file->memory, file->length, MS_SYNC);
|
||||
munmap(file->memory, file->length);
|
||||
close(file->fd);
|
||||
}
|
||||
|
||||
sus_heapFree(file);
|
||||
sys_heapFree(file);
|
||||
}
|
||||
|
||||
void sus_fileFlush(sus_File file) {
|
||||
msync(file->memroy, file->length, MS_SYNC);
|
||||
void sys_fileFlush(sys_File file) {
|
||||
msync(file->memory, file->length, MS_SYNC);
|
||||
}
|
||||
|
||||
void * sus_fileResize(sus_File file, signed long appendBytes) {
|
||||
void * sys_fileResize(sys_File file, signed long appendBytes) {
|
||||
size_t newSize = file->length + appendBytes;
|
||||
lseek(file->fd, newSize - 1, SEEK_SET);
|
||||
write(file->fd, "", 1);
|
||||
|
||||
munmap(file->memroy, file->length);
|
||||
munmap(file->memory, file->length);
|
||||
void *newMem = mmap(NULL, newSize, PROT_READ | PROT_WRITE, MAP_SHARED, file->fd, 0);
|
||||
if(newMem == MAP_FAILED) {
|
||||
sus_fileClose(file);
|
||||
sys_fileClose(file);
|
||||
file->fd = 0;
|
||||
file->length = 0;
|
||||
file->memroy = NULL;
|
||||
file->memory = NULL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
file->length = newSize;
|
||||
file->memroy = newMem;
|
||||
file->memory = newMem;
|
||||
return newMem;
|
||||
}
|
||||
|
||||
void sus_fileDelete(char * fileName) {
|
||||
void sys_fileDelete(char * fileName) {
|
||||
unlink(fileName);
|
||||
}
|
||||
|
||||
void sus_fileRename(char * fileName, char * newFileName) {
|
||||
void sys_fileRename(char * fileName, char * newFileName) {
|
||||
link(fileName, newFileName);
|
||||
unlink(fileName);
|
||||
}
|
@ -1,15 +1,15 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
// Memory API
|
||||
void * sus_heapAlloc(size_t bytes) {
|
||||
void * sys_heapAlloc(size_t bytes) {
|
||||
return malloc(bytes);
|
||||
}
|
||||
|
||||
void * sus_heapResize(void * memroy, size_t newBytes) {
|
||||
return realloc(memroy, newBytes);
|
||||
void * sys_heapResize(void * memory, size_t newBytes) {
|
||||
return realloc(memory, newBytes);
|
||||
}
|
||||
|
||||
void sus_heapFree(void * memroy) {
|
||||
free(memroy);
|
||||
void sys_heapFree(void * memory) {
|
||||
free(memory);
|
||||
}
|
@ -1,38 +1,38 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct sus_thread_args {
|
||||
sus_threadProc proc;
|
||||
struct sys_thread_args {
|
||||
sys_threadProc proc;
|
||||
void *arg;
|
||||
};
|
||||
|
||||
typedef struct sus_thread_args sus_thread_args;
|
||||
typedef struct sys_thread_args sys_thread_args;
|
||||
|
||||
// Linux only uses System V AMD64 ABI calling convention (source: https://en.wikipedia.org/wiki/X86_calling_conventions)
|
||||
void *uwu_runThread(void *arg) {
|
||||
sus_thread_args *args = (sus_thread_args *) arg;
|
||||
sus_threadProc proc = args->proc;
|
||||
sys_thread_args *args = (sys_thread_args *) arg;
|
||||
sys_threadProc proc = args->proc;
|
||||
void *arg2 = args->arg;
|
||||
sus_heapFree(args);
|
||||
sys_heapFree(args);
|
||||
proc(arg2);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sus_Bool sus_threadNew(sus_threadProc proc, void *arg) {
|
||||
sus_thread_args *args = (sus_thread_args *) sus_heapAlloc(sizeof(sus_thread_args));
|
||||
sys_Bool sys_threadNew(sys_threadProc proc, void *arg) {
|
||||
sys_thread_args *args = (sys_thread_args *) sys_heapAlloc(sizeof(sys_thread_args));
|
||||
args->proc = proc;
|
||||
args->arg = arg;
|
||||
|
||||
pthread_t thread;
|
||||
if(pthread_create(&thread, NULL, uwu_runThread, args)) {
|
||||
sus_heapFree(args);
|
||||
return sus_False;
|
||||
sys_heapFree(args);
|
||||
return sys_False;
|
||||
}else {
|
||||
return sus_True;
|
||||
return sys_True;
|
||||
}
|
||||
}
|
||||
|
||||
void sus_threadSleep(unsigned long seconds) {
|
||||
void sys_threadSleep(unsigned long seconds) {
|
||||
sleep(seconds);
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#include <windows.h>
|
||||
|
||||
struct sus_File_impl{
|
||||
void * memroy;
|
||||
struct sys_File_impl{
|
||||
void * memory;
|
||||
HANDLE fileHandle;
|
||||
HANDLE fileMapHandle;
|
||||
};
|
||||
@ -12,24 +12,24 @@ struct sus_File_impl{
|
||||
// if(fileMap == NULL || fileMap == INVALID_HANDLE_VALUE){
|
||||
// return NULL;
|
||||
// }
|
||||
// void * memroy = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
// if(memroy == NULL){
|
||||
// void * memory = MapViewOfFile(fileMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
// if(memory == NULL){
|
||||
// CloseHandle(fileMap);
|
||||
// }
|
||||
// return memroy;
|
||||
// return memory;
|
||||
//}
|
||||
|
||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
sus_File currentFile = sus_heapAlloc(sizeof(struct sus_File_impl));
|
||||
sys_File sys_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
sys_File currentFile = sys_heapAlloc(sizeof(struct sys_File_impl));
|
||||
if(currentFile == NULL) return NULL;
|
||||
|
||||
currentFile->fileHandle = CreateFileA(fileName,
|
||||
GENERIC_READ | GENERIC_WRITE, //Open for reading and writing
|
||||
FILE_SHARE_READ, //It wouldn't be a good idea, if a different process wrote to the file at the same time
|
||||
NULL,
|
||||
(parameter & SUS_FILE_NEW ? CREATE_NEW : OPEN_EXISTING), //Open the file only if it exists/if it DOES NOT EXIST to prevent user error
|
||||
(parameter & SYS_FILE_NEW ? CREATE_NEW : OPEN_EXISTING), //Open the file only if it exists/if it DOES NOT EXIST to prevent user error
|
||||
FILE_FLAG_RANDOM_ACCESS | //optimize for random access to file
|
||||
((parameter & SUS_FILE_TEMP == SUS_FILE_TEMP) ? (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE) : FILE_ATTRIBUTE_NORMAL), // just a normal file :D / automatically remove the file, if no longer needed
|
||||
((parameter & SYS_FILE_TEMP == SYS_FILE_TEMP) ? (FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE) : FILE_ATTRIBUTE_NORMAL), // just a normal file :D / automatically remove the file, if no longer needed
|
||||
NULL);
|
||||
if(currentFile->fileHandle == NULL || currentFile->fileHandle == INVALID_HANDLE_VALUE){
|
||||
//debug
|
||||
@ -39,7 +39,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
}
|
||||
//void * currentAdress = internal_fileOpeninMem(currentFile);
|
||||
|
||||
//If the file is empty, there is nothing to map into memroy, so this code puts something into the file
|
||||
//If the file is empty, there is nothing to map into memory, so this code puts something into the file
|
||||
if(GetFileSize(currentFile->fileHandle, NULL) == 0){
|
||||
if(!WriteFile(currentFile->fileHandle, "", sizeof(""), NULL, NULL)){
|
||||
goto cleanup2;
|
||||
@ -51,8 +51,8 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
//return NULL;
|
||||
goto cleanup2;
|
||||
}
|
||||
currentFile->memroy = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(currentFile->memroy == NULL){
|
||||
currentFile->memory = MapViewOfFile(currentFile->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(currentFile->memory == NULL){
|
||||
goto cleanup3;
|
||||
}
|
||||
return currentFile;
|
||||
@ -68,7 +68,7 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
cleanup2:
|
||||
CloseHandle(currentFile->fileHandle);
|
||||
cleanup1:
|
||||
sus_heapFree(currentFile);
|
||||
sys_heapFree(currentFile);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -113,40 +113,40 @@ sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter){
|
||||
// return currentAdress;
|
||||
//}
|
||||
|
||||
void * sus_fileFileToMemroy(sus_File file){
|
||||
return file->memroy;
|
||||
void * sys_fileFileToMemory(sys_File file){
|
||||
return file->memory;
|
||||
}
|
||||
|
||||
void sus_fileClose(sus_File file){
|
||||
if(file->memroy == NULL){
|
||||
FlushViewOfFile(file->memroy, 0);
|
||||
UnmapViewOfFile(file->memroy);
|
||||
void sys_fileClose(sys_File file){
|
||||
if(file->memory == NULL){
|
||||
FlushViewOfFile(file->memory, 0);
|
||||
UnmapViewOfFile(file->memory);
|
||||
CloseHandle(file->fileMapHandle);
|
||||
CloseHandle(file->fileHandle);
|
||||
}
|
||||
sus_heapFree(file);
|
||||
sys_heapFree(file);
|
||||
}
|
||||
|
||||
void sus_fileFlush(sus_File file){
|
||||
FlushViewOfFile(file->memroy, 0);
|
||||
void sys_fileFlush(sys_File file){
|
||||
FlushViewOfFile(file->memory, 0);
|
||||
}
|
||||
|
||||
void sus_fileRename(char * fileName, char * newFileName){
|
||||
void sys_fileRename(char * fileName, char * newFileName){
|
||||
MoveFile(fileName, newFileName);
|
||||
}
|
||||
|
||||
void sus_fileDelete(char * fileName){
|
||||
void sys_fileDelete(char * fileName){
|
||||
DeleteFile(fileName);
|
||||
}
|
||||
|
||||
sus_Bool sus_fileExists(char * fileName){
|
||||
sys_Bool sys_fileExists(char * fileName){
|
||||
DWORD fileAttributes = GetFileAttributes(fileName);
|
||||
return (fileAttributes == INVALID_FILE_ATTRIBUTES ? sus_True : sus_False);
|
||||
return (fileAttributes == INVALID_FILE_ATTRIBUTES ? sys_True : sys_False);
|
||||
}
|
||||
|
||||
void * sus_fileResize(sus_File file, signed long appendBytes){
|
||||
FlushViewOfFile(file->memroy, 0);
|
||||
UnmapViewOfFile(file->memroy);
|
||||
void * sys_fileResize(sys_File file, signed long appendBytes){
|
||||
FlushViewOfFile(file->memory, 0);
|
||||
UnmapViewOfFile(file->memory);
|
||||
CloseHandle(file->fileMapHandle);
|
||||
SetFilePointer(file->fileHandle, appendBytes, NULL, FILE_END); //Very cursed Unix style...
|
||||
SetEndOfFile(file->fileHandle);
|
||||
@ -157,11 +157,11 @@ void * sus_fileResize(sus_File file, signed long appendBytes){
|
||||
//return NULL;
|
||||
goto cleanup2;
|
||||
}
|
||||
file->memroy = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(file->memroy == NULL){
|
||||
file->memory = MapViewOfFile(file->fileMapHandle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
|
||||
if(file->memory == NULL){
|
||||
goto cleanup3;
|
||||
}
|
||||
return file->memroy;
|
||||
return file->memory;
|
||||
|
||||
cleanup3:
|
||||
CloseHandle(file->fileMapHandle);
|
||||
@ -169,8 +169,8 @@ void * sus_fileResize(sus_File file, signed long appendBytes){
|
||||
cleanup2:
|
||||
CloseHandle(file->fileHandle);
|
||||
file->fileHandle = NULL;
|
||||
//sus_heapFree(file);
|
||||
file->memroy = NULL;
|
||||
//sys_heapFree(file);
|
||||
file->memory = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1,17 +1,17 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#include <windows.h>
|
||||
|
||||
// returns NULL, if there is no memroy left or an error occured
|
||||
void * sus_heapAlloc(size_t bytes){
|
||||
// returns NULL, if there is no memory left or an error occured
|
||||
void * sys_heapAlloc(size_t bytes){
|
||||
return HeapAlloc(GetProcessHeap(), 0, bytes); //generic call to the windows heapAlloc function
|
||||
}
|
||||
|
||||
// returns NULL, if there is no memroy left or an error occured
|
||||
void * sus_heapResize(void * memroy, size_t newBytes){
|
||||
return HeapReAlloc(GetProcessHeap(), 0, memroy, newBytes);
|
||||
// returns NULL, if there is no memory left or an error occured
|
||||
void * sys_heapResize(void * memory, size_t newBytes){
|
||||
return HeapReAlloc(GetProcessHeap(), 0, memory, newBytes);
|
||||
}
|
||||
|
||||
// what should this function do, if an error occurse..
|
||||
void sus_heapFree(void * memroy){
|
||||
HeapFree(GetProcessHeap(), 0, memroy);
|
||||
void sys_heapFree(void * memory){
|
||||
HeapFree(GetProcessHeap(), 0, memory);
|
||||
}
|
||||
|
@ -1,31 +1,31 @@
|
||||
#include "../cdb_sustem.h"
|
||||
#include "../cdb_system.h"
|
||||
#include <windows.h>
|
||||
|
||||
struct threadInfo{
|
||||
sus_threadProc proc;
|
||||
sys_threadProc proc;
|
||||
void * args;
|
||||
};
|
||||
|
||||
DWORD WINAPI threadProc(void * tiarg){
|
||||
struct threadInfo * ti = tiarg;
|
||||
struct threadInfo currentTI = {.args = ti->args, .proc = ti->proc};
|
||||
sus_heapFree(ti);
|
||||
sys_heapFree(ti);
|
||||
currentTI.proc(currentTI.args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sus_Bool sus_threadNew(sus_threadProc proc, void * arg){
|
||||
struct threadInfo * ti = sus_heapAlloc(sizeof(struct threadInfo));
|
||||
sys_Bool sys_threadNew(sys_threadProc proc, void * arg){
|
||||
struct threadInfo * ti = sys_heapAlloc(sizeof(struct threadInfo));
|
||||
ti->proc = proc;
|
||||
ti->args = arg;
|
||||
if(CreateThread(NULL, 0, threadProc, ti, 0, NULL) == NULL){
|
||||
sus_heapFree(ti);
|
||||
return sus_False;
|
||||
sys_heapFree(ti);
|
||||
return sys_False;
|
||||
}else{
|
||||
return sus_True;
|
||||
return sys_True;
|
||||
}
|
||||
}
|
||||
|
||||
void sus_threadSleep(unsigned long seconds){
|
||||
void sys_threadSleep(unsigned long seconds){
|
||||
Sleep(seconds * 1000);
|
||||
}
|
45
cdb_sustem.h
45
cdb_sustem.h
@ -1,45 +0,0 @@
|
||||
//TODO finland up
|
||||
|
||||
//#include <stddef.h>
|
||||
|
||||
// TODO should propably be placed in a global header
|
||||
#define sus_Bool char
|
||||
#define sus_True 1
|
||||
#define sus_False 0
|
||||
|
||||
#define SUS_FILE_TEMP ((1UL << 0) | SUS_FILE_NEW) //A temporary file gets automatically deleted, once it is no longer needed; a temp file also has to be a new file
|
||||
#define SUS_FILE_NEW (1UL << 1)
|
||||
#define SUS_FILE_NOTHING 0UL
|
||||
|
||||
//Naming: firstly the package, then the topic, lastly the operation
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
//Operating System independent implementation
|
||||
typedef struct sus_File_impl * sus_File;
|
||||
|
||||
// File IO API
|
||||
//sus_File sus_file_OpenInMem(char * fileName, unsigned long parameter);
|
||||
sus_File sus_fileOpenInMem(char * fileName, unsigned long parameter); // Map a file into the memroy of the current process
|
||||
//void * sus_fileOpenNewinMem(char * fileName); //prevent user errors
|
||||
//void * sus_fileOpenTempFileinMem(char * fileName);
|
||||
|
||||
void * sus_fileFileToMemroy(sus_File file); //retrieves the memroy Pointer of where the file was mapped in memroy
|
||||
|
||||
sus_Bool sus_fileExists(char * fileName); //check if a file exists in the specified path with the specified name
|
||||
void sus_fileClose(sus_File file); //Closes the file mapping and all the system specific stuff for that mapping
|
||||
void sus_fileFlush(sus_File file); //Flushes the filemapping; synchronize the written data in the filemapping to the actual file on disk (without blocking for better performance)
|
||||
void * sus_fileResize(sus_File file, signed long appendBytes); //if appendBytes is negative, the file shrinks. This prevents me from definining a new function for retreving the file Size
|
||||
void sus_fileDelete(char * fileName);
|
||||
void sus_fileRename(char * fileName, char * newFileName);
|
||||
|
||||
// Memory API
|
||||
void * sus_heapAlloc(size_t bytes); // returns NULL, if there is no memroy left or an error occured
|
||||
void * sus_heapResize(void * memroy, size_t newBytes); // returns NULL, if there is no memroy left or an error occured
|
||||
void sus_heapFree(void * memroy); // what should this function do, if an error occurse..
|
||||
|
||||
// Networking API -- coming soon, cuz idk
|
||||
|
||||
//Threads
|
||||
sus_Bool sus_threadNew(int (*proc)(void));
|
||||
void sus_threadSleep(unsigned long seconds);
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g filePageTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest1
|
||||
gcc -g filePageTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest1
|
@ -8,7 +8,7 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char * memory = fp_fileToMemroy(file);
|
||||
char * memory = fp_fileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[511] = 'b';
|
||||
|
||||
@ -32,7 +32,7 @@ int main() {
|
||||
|
||||
printf("Init\n");
|
||||
fp_fileInit(file, 512);
|
||||
memory = fp_fileToMemroy(file);
|
||||
memory = fp_fileToMemory(file);
|
||||
printf("%c%c%c\n", memory[0],memory[511],memory[1023]);
|
||||
|
||||
fp_fileClose(file);
|
||||
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g filePageTest2.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest2
|
||||
gcc -g filePageTest2.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../File-Page Abstraction/cdb_file-page.c" -o run/filePageTest2
|
@ -9,7 +9,7 @@ int main() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
char * memory = fp_fileToMemroy(file);
|
||||
char * memory = fp_fileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[511] = 'b';
|
||||
|
||||
|
@ -1 +1 @@
|
||||
gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe
|
||||
gcc.exe systemAbstractionTest1.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/systemAbstractionTest1
|
||||
gcc systemAbstractionTest1.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/systemAbstractionTest1
|
@ -1,32 +1,32 @@
|
||||
#include "../../../System Abstraction/cdb_sustem.h"
|
||||
#include "../../../System Abstraction/cdb_system.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void main(){
|
||||
sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
||||
sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||
if(file == NULL){
|
||||
printf("file is null\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char * memroy = sus_fileFileToMemroy(file);
|
||||
if(memroy == 0){
|
||||
printf("memroy was null\n");
|
||||
char * memory = sys_fileFileToMemory(file);
|
||||
if(memory == 0){
|
||||
printf("memory was null\n");
|
||||
return;
|
||||
}else{
|
||||
printf("Read chars: %c%c%c\n", memroy[0], memroy[1], memroy[2]);
|
||||
printf("Read chars: %c%c%c\n", memory[0], memory[1], memory[2]);
|
||||
}
|
||||
|
||||
sus_fileResize(file, 2);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'a';
|
||||
memroy[1] = 'b';
|
||||
memroy[2] = 'c';
|
||||
memroy[3] = 'd';
|
||||
memroy[4] = 'e';
|
||||
sus_fileClose(file);
|
||||
sys_fileResize(file, 2);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[1] = 'b';
|
||||
memory[2] = 'c';
|
||||
memory[3] = 'd';
|
||||
memory[4] = 'e';
|
||||
sys_fileClose(file);
|
||||
|
||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'O';
|
||||
sus_fileClose(file);
|
||||
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'O';
|
||||
sys_fileClose(file);
|
||||
}
|
@ -1 +1 @@
|
||||
gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o systemAbstractionTest1.exe
|
||||
gcc.exe openNewFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o systemAbstractionTest1.exe
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openNewFiletest
|
||||
gcc -g openNewFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openNewFiletest
|
@ -2,32 +2,32 @@
|
||||
#include "stdio.h"
|
||||
|
||||
void main(){
|
||||
sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NEW);
|
||||
sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NEW);
|
||||
if(file == NULL){
|
||||
printf("file is null\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char * memroy = sus_fileFileToMemroy(file);
|
||||
if(memroy == 0){
|
||||
printf("memroy was null\n");
|
||||
char * memory = sys_fileFileToMemory(file);
|
||||
if(memory == 0){
|
||||
printf("memory was null\n");
|
||||
return;
|
||||
}else{
|
||||
printf("%c\n", memroy[0] == 0 ? 'Y' : 'N');
|
||||
printf("%c\n", memory[0] == 0 ? 'Y' : 'N');
|
||||
}
|
||||
|
||||
sus_fileResize(file, 4);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'a';
|
||||
memroy[1] = 'b';
|
||||
memroy[2] = 'c';
|
||||
memroy[3] = 'd';
|
||||
memroy[4] = 'e';
|
||||
sus_fileFlush(file);
|
||||
sus_fileClose(file);
|
||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'O';
|
||||
sus_fileFlush(file);
|
||||
sus_fileClose(file);
|
||||
sys_fileResize(file, 4);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[1] = 'b';
|
||||
memory[2] = 'c';
|
||||
memory[3] = 'd';
|
||||
memory[4] = 'e';
|
||||
sys_fileFlush(file);
|
||||
sys_fileClose(file);
|
||||
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'O';
|
||||
sys_fileFlush(file);
|
||||
sys_fileClose(file);
|
||||
}
|
@ -1 +1 @@
|
||||
gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memroy.c" -o openTempFiletest.exe
|
||||
gcc.exe openTempFiletest.c "../../../System Abstraction/win32/cdb_file.c" "../../../System Abstraction/win32/cdb_memory.c" -o openTempFiletest.exe
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/openTempFiletest
|
||||
gcc -g openTempFiletest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/openTempFiletest
|
@ -2,34 +2,34 @@
|
||||
#include "stdio.h"
|
||||
|
||||
void main(){
|
||||
sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_TEMP);
|
||||
sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_TEMP);
|
||||
if(file == NULL){
|
||||
printf("file is null\n");
|
||||
return;
|
||||
}
|
||||
|
||||
char * memroy = sus_fileFileToMemroy(file);
|
||||
if(memroy == 0){
|
||||
printf("memroy was null\n");
|
||||
char * memory = sys_fileFileToMemory(file);
|
||||
if(memory == 0){
|
||||
printf("memory was null\n");
|
||||
return;
|
||||
}else{
|
||||
printf("%c\n", memroy[0] == 0 ? 'Y' : 'N');
|
||||
printf("%c\n", memory[0] == 0 ? 'Y' : 'N');
|
||||
}
|
||||
|
||||
sus_fileResize(file, 4);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'a';
|
||||
memroy[1] = 'b';
|
||||
memroy[2] = 'c';
|
||||
memroy[3] = 'd';
|
||||
memroy[4] = 'e';
|
||||
sus_fileClose(file);
|
||||
sys_fileResize(file, 4);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[1] = 'b';
|
||||
memory[2] = 'c';
|
||||
memory[3] = 'd';
|
||||
memory[4] = 'e';
|
||||
sys_fileClose(file);
|
||||
|
||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
||||
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||
if(file == NULL) {
|
||||
printf("Second file is null\n");
|
||||
}else {
|
||||
printf("Second file is NOT null\n");
|
||||
sus_fileClose(file);
|
||||
sys_fileClose(file);
|
||||
}
|
||||
}
|
@ -2,32 +2,32 @@
|
||||
#include "stdio.h"
|
||||
|
||||
void main(){
|
||||
sus_File file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NEW);
|
||||
sys_File file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NEW);
|
||||
if(file == NULL){
|
||||
printf("file is null");
|
||||
return;
|
||||
}
|
||||
|
||||
char * memroy = sus_fileFileToMemroy(file);
|
||||
if(memroy == 0){
|
||||
printf("memroy was null\n");
|
||||
char * memory = sys_fileFileToMemory(file);
|
||||
if(memory == 0){
|
||||
printf("memory was null\n");
|
||||
return;
|
||||
}else{
|
||||
printf("%c%c%c%c", memroy[0], memroy[1], memroy[2], memroy[3]);
|
||||
printf("%c%c%c%c", memory[0], memory[1], memory[2], memory[3]);
|
||||
}
|
||||
|
||||
sus_fileResize(file, 2);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'a';
|
||||
memroy[1] = 'b';
|
||||
memroy[2] = 'c';
|
||||
memroy[3] = 'd';
|
||||
memroy[4] = 'e';
|
||||
sus_fileFlush(file);
|
||||
sus_fileClose(file);
|
||||
file = sus_fileOpenInMem("testfile.txt", SUS_FILE_NOTHING);
|
||||
memroy = sus_fileFileToMemroy(file);
|
||||
memroy[0] = 'O';
|
||||
sus_fileFlush(file);
|
||||
sus_fileClose(file);
|
||||
sys_fileResize(file, 2);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'a';
|
||||
memory[1] = 'b';
|
||||
memory[2] = 'c';
|
||||
memory[3] = 'd';
|
||||
memory[4] = 'e';
|
||||
sys_fileFlush(file);
|
||||
sys_fileClose(file);
|
||||
file = sys_fileOpenInMem("testfile.txt", SYS_FILE_NOTHING);
|
||||
memory = sys_fileFileToMemory(file);
|
||||
memory[0] = 'O';
|
||||
sys_fileFlush(file);
|
||||
sys_fileClose(file);
|
||||
}
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" -o run/renameFileTest
|
||||
gcc -g renameFileTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" -o run/renameFileTest
|
@ -2,5 +2,5 @@
|
||||
#include "stdio.h"
|
||||
|
||||
int main() {
|
||||
sus_fileRename("testfile.txt", "renamedtestfile.txt");
|
||||
sys_fileRename("testfile.txt", "renamedtestfile.txt");
|
||||
}
|
@ -1 +1 @@
|
||||
gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memroy.c" -o threadTests.exe
|
||||
gcc.exe threadsTest.c "../../../System Abstraction/win32/cdb_thread.c" "../../../System Abstraction/win32/cdb_memory.c" -o threadTests.exe
|
@ -2,4 +2,4 @@
|
||||
if [ ! -d run ]; then
|
||||
mkdir run
|
||||
fi
|
||||
gcc -g threadsTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memroy.c" "../../../System Abstraction/linux/cdb_thread.c" -o run/threadsTest
|
||||
gcc -g threadsTest.c "../../../System Abstraction/linux/cdb_file.c" "../../../System Abstraction/linux/cdb_memory.c" "../../../System Abstraction/linux/cdb_thread.c" -o run/threadsTest
|
@ -3,14 +3,14 @@
|
||||
|
||||
__attribute__ ((sysv_abi)) void testProc(void * arg){
|
||||
printf("in testProc ... Going to sleep, %i\n", *(int *)arg);
|
||||
sus_threadSleep(5);
|
||||
sys_threadSleep(5);
|
||||
printf("after sleeping in testProc\n");
|
||||
}
|
||||
|
||||
int main(){
|
||||
int amogus = 1234567;
|
||||
printf("Thread creation succesfull? %i\n", sus_threadNew(&testProc, &amogus));
|
||||
printf("Thread creation succesfull? %i\n", sys_threadNew(&testProc, &amogus));
|
||||
printf("Going to sleep in main Thread\n");
|
||||
sus_threadSleep(10);
|
||||
sys_threadSleep(10);
|
||||
printf("After sleeping in main Thread\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user