forked from KolibriOS/kolibrios
libc.obj:
- Added atof function - Added example for working with threads git-svn-id: svn://kolibrios.org@9137 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
48a6c045c4
commit
e7ec006b8b
@ -43,4 +43,6 @@ extern int _FUNC(rand)(void);
|
|||||||
extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func);
|
extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func);
|
||||||
extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *));
|
extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *));
|
||||||
|
|
||||||
|
extern double _FUNC(atof)(const char *ascii);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
* All wrappers must start with the "_ksys_" prefix.
|
* All wrappers must start with the "_ksys_" prefix.
|
||||||
* I consider it mandatory to place the wrappers in the correct order in the official documentation.
|
* I consider it mandatory to place the wrappers in the correct order in the official documentation.
|
||||||
* Enjoy writing your code :)
|
* Enjoy writing your code :)
|
||||||
*/
|
|
||||||
|
|
||||||
// Warning! The end of the file is the old definitions of function/structure names.
|
* Warning! The end of the file is the old definitions of function/structure names.
|
||||||
// They are for compatibility... Better not to use them. */
|
* They are for compatibility... Better not to use them.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef _KSYS_H_
|
#ifndef _KSYS_H_
|
||||||
#define _KSYS_H_
|
#define _KSYS_H_
|
||||||
@ -686,6 +686,8 @@ void _ksys_kill_by_pid(uint32_t PID)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*===================== Function 18, subfunction 21 ====================*/
|
||||||
|
/*=====Get the slot number of the process / thread by identifier.. =====*/
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
int _ksys_get_thread_slot(int PID){
|
int _ksys_get_thread_slot(int PID){
|
||||||
@ -962,12 +964,13 @@ uint32_t _ksys_get_skin_height(){
|
|||||||
/*==================== Function 51 - create thread. ====================*/
|
/*==================== Function 51 - create thread. ====================*/
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
int _ksys_start_thread(void* thread_entry, void* stack_top){
|
int _ksys_create_thread(void* thread_entry, void* stack_top){
|
||||||
int val;
|
int val;
|
||||||
asm_inline(
|
asm_inline(
|
||||||
"int $0x40"
|
"int $0x40"
|
||||||
:"=a"(val)
|
:"=a"(val)
|
||||||
:"a"(51), "b"(1), "c"(thread_entry), "d"(stack_top)
|
:"a"(51), "b"(1), "c"(thread_entry), "d"(stack_top)
|
||||||
|
:"memory"
|
||||||
);
|
);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ clayer/libimg.kex \
|
|||||||
clayer/dialog.kex \
|
clayer/dialog.kex \
|
||||||
clayer/msgbox.kex \
|
clayer/msgbox.kex \
|
||||||
clayer/boxlib.kex \
|
clayer/boxlib.kex \
|
||||||
|
thread_work.kex
|
||||||
|
|
||||||
LIBS= -ltcc -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj
|
LIBS= -ltcc -ldialog -lrasterworks -limg -lbox -lmsgbox -lnetwork -lc.obj
|
||||||
|
|
||||||
|
69
programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c
Normal file
69
programs/develop/ktcc/trunk/libc.obj/samples/thread_work.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* An example of using threads to create a copy of a window.
|
||||||
|
* Built on top of the /programs/develop/examples/thread/trunk/thread.asm example.
|
||||||
|
*
|
||||||
|
* Created by turbocat (Maxim Logaev) 2021.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <sys/ksys.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define TH_STACK_SIZE 1024
|
||||||
|
|
||||||
|
enum BUTTONS{
|
||||||
|
BTN_QUIT = 1,
|
||||||
|
BTN_CREATE_TH = 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
ksys_colors_table_t sys_colors;
|
||||||
|
|
||||||
|
extern int main();
|
||||||
|
|
||||||
|
void redraw_window(void){
|
||||||
|
ksys_pos_t mouse_pos = _ksys_get_mouse_pos(KSYS_MOUSE_SCREEN_POS);
|
||||||
|
_ksys_start_draw();
|
||||||
|
_ksys_create_window(mouse_pos.x, mouse_pos.y, 140, 60, "Threads", sys_colors.work_area, 0x14);
|
||||||
|
_ksys_define_button(10, 30, 120, 20, BTN_CREATE_TH, sys_colors.work_button);
|
||||||
|
_ksys_draw_text("Create thread!", 15, 34, 0, 0x90000000 | sys_colors.work_button_text);
|
||||||
|
_ksys_end_draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
void create_thread(void){
|
||||||
|
unsigned tid; // New thread ID
|
||||||
|
void *th_stack = malloc(TH_STACK_SIZE); // Allocate memory for thread stack
|
||||||
|
if(!th_stack){
|
||||||
|
_ksys_debug_puts("Memory allocation error for thread!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tid = _ksys_create_thread(main, th_stack+TH_STACK_SIZE); // Create new thread with entry "main"
|
||||||
|
if(tid==-1){
|
||||||
|
_ksys_debug_puts("Unable to create a new thread!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
debug_printf("New thread created (TID=%u)\n", tid);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(){
|
||||||
|
_ksys_get_system_colors(&sys_colors);
|
||||||
|
int gui_event;
|
||||||
|
redraw_window();
|
||||||
|
|
||||||
|
while(1){
|
||||||
|
gui_event = _ksys_get_event();
|
||||||
|
switch(gui_event){
|
||||||
|
case KSYS_EVENT_REDRAW:
|
||||||
|
redraw_window();
|
||||||
|
break;
|
||||||
|
case KSYS_EVENT_BUTTON:
|
||||||
|
switch (_ksys_get_button()){
|
||||||
|
case BTN_CREATE_TH:
|
||||||
|
create_thread();
|
||||||
|
break;
|
||||||
|
case BTN_QUIT:
|
||||||
|
_ksys_exit();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -100,6 +100,7 @@
|
|||||||
#include "stdlib/rand.c"
|
#include "stdlib/rand.c"
|
||||||
#include "stdlib/qsort.c"
|
#include "stdlib/qsort.c"
|
||||||
#include "stdlib/assert.c"
|
#include "stdlib/assert.c"
|
||||||
|
#include "stdlib/atof.c"
|
||||||
|
|
||||||
#include "math/acosh.c"
|
#include "math/acosh.c"
|
||||||
#include "math/asinh.c"
|
#include "math/asinh.c"
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
double
|
||||||
|
atof(const char *ascii)
|
||||||
|
{
|
||||||
|
return strtod(ascii, 0);
|
||||||
|
}
|
@ -46,6 +46,7 @@ abs
|
|||||||
atoi
|
atoi
|
||||||
atol
|
atol
|
||||||
atoll
|
atoll
|
||||||
|
atof
|
||||||
calloc
|
calloc
|
||||||
div
|
div
|
||||||
exit
|
exit
|
||||||
|
Loading…
Reference in New Issue
Block a user