Skip to content

Commit 377c2d6

Browse files
committed
Getting closer to being finished.
Adding in unix support and combining code into a common API to minimize the amount of duplicate code needed between ports. Almost finished with the changes and then need to do the compile tests and fix any issues.
1 parent b52ed57 commit 377c2d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+213
-1268
lines changed

ext_mod/micropython.cmake

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ include(${CMAKE_CURRENT_LIST_DIR}/lcd_utils/micropython.cmake)
44

55
set(MICROPY_MULTICORE_THREAD $ENV{MICROPY_MULTICORE_THREADING})
66

7-
# if(ESP_PLATFORM)
8-
# if(MICROPY_MULTICORE_THREAD)
9-
# include(${CMAKE_CURRENT_LIST_DIR}/threading/micropython.cmake)
10-
# endif(MICROPY_MULTICORE_THREAD)
11-
# endif(ESP_PLATFORM)
7+
if(MICROPY_MULTICORE_THREAD)
8+
include(${CMAKE_CURRENT_LIST_DIR}/threading/micropython.cmake)
9+
endif(MICROPY_MULTICORE_THREAD)

ext_mod/threading/common/inc/thread_event.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
void threading_event_init(thread_event_t *event); // needs to be defined in port
2222
void threading_event_delete(thread_event_t *event); // needs to be defined in port
2323

24+
extern const mp_obj_type_t mp_type_threading_event_t;
25+
extern const mp_obj_type_t mp_type_multiprocessing_event_t;
26+
2427
#endif
2528

2629

ext_mod/threading/common/inc/thread_lock.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
void threading_lock_init(thread_lock_t *lock); // needs to be defined in port
2020
void threading_lock_delete(thread_lock_t *lock); // needs to be defined in port
2121

22+
extern const mp_obj_type_t mp_type_threading_lock_t;
23+
extern const mp_obj_type_t mp_type_multiprocessing_lock_t;
24+
25+
2226
#endif

ext_mod/threading/common/inc/thread_rlock.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,7 @@
2424
void threading_rlock_init(thread_rlock_t *rlock); // needs to be defined in port
2525
void threading_rlock_delete(thread_rlock_t *rlock); // needs to be defined in port
2626

27+
extern const mp_obj_type_t mp_type_threading_rlock_t;
28+
extern const mp_obj_type_t mp_type_multiprocessing_rlock_t;
29+
2730
#endif

ext_mod/threading/common/inc/thread_semaphore.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,21 @@
66
#ifndef __THREAD_SEMAPHORE_H__
77
#define __THREAD_SEMAPHORE_H__
88

9-
#include "threading_common.h"
10-
11-
typedef struct _thread_semphamore_t thread_semphamore_t; // needs to be defined in port
9+
typedef struct _thread_semaphore_t thread_semaphore_t; // needs to be defined in port
1210

1311
typedef struct _mp_obj_thread_semaphore_t {
1412
mp_obj_base_t base;
15-
thread_semphamore_t sem;
13+
thread_semaphore_t sem;
1614
uint16_t start_value;
1715
} mp_obj_thread_semaphore_t;
1816

19-
uint16_t threading_semphamore_get_count(thread_semphamore_t *sem); // needs to be defined in port
20-
bool threading_semphamore_acquire(thread_semphamore_t *sem, int32_t wait_ms); // needs to be defined in port
21-
void threading_semphamore_release(thread_semphamore_t *sem); // needs to be defined in port
22-
void threading_semphamore_init(thread_semphamore_t *sem); // needs to be defined in port
23-
void threading_semphamore_delete(thread_semphamore_t *sem); // needs to be defined in port
17+
uint16_t threading_semaphore_get_count(thread_semaphore_t *sem); // needs to be defined in port
18+
bool threading_semaphore_acquire(thread_semaphore_t *sem, int32_t wait_ms); // needs to be defined in port
19+
void threading_semaphore_release(thread_semaphore_t *sem); // needs to be defined in port
20+
void threading_semaphore_init(thread_semaphore_t *sem); // needs to be defined in port
21+
void threading_semaphore_delete(thread_semaphore_t *sem); // needs to be defined in port
22+
23+
extern const mp_obj_type_t mp_type_threading_semaphore_t;
24+
extern const mp_obj_type_t mp_type_multiprocessing_semaphore_t;
2425

2526
#endif

ext_mod/threading/common/inc/thread_thread.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
int ready; // whether the thread is ready and running
3131
int is_alive;
3232
uint8_t core_id;
33-
void *arg; // thread Python args, a GC root pointer
3433
void *stack; // pointer to the stack
3534
size_t stack_len; // number of words in the stack
3635
struct _mp_obj_thread_t *next;
3736

3837
} mp_obj_thread_t;
3938

4039
mp_uint_t threading_create_thread(mp_obj_thread_t *self); // needs to be defined in port
41-
void threading_delete_thread(thread_t *thread); // needs to be defined in port
40+
void threading_delete_thread(mp_obj_thread_t *self); // needs to be defined in port
41+
42+
extern const mp_obj_type_t mp_type_threading_thread_t;
43+
extern const mp_obj_type_t mp_type_multiprocessing_process_t;
4244

4345
#endif

ext_mod/threading/common/inc/threading.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "thread_thread.h"
1111
#include "thread_lock.h"
1212
#include "thread_rlock.h"
13-
#include "thread_semphamore.h"
13+
#include "thread_semaphore.h"
1414
#include "thread_event.h"
1515

1616
void threading_init(void *stack, uint32_t stack_len); // needs to be defined in port

ext_mod/threading/common/src/multiprocessing.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
mp_obj_t processes[2];
21

2+
#include "multiprocessing.h"
3+
#include "threading.h"
4+
#include "thread_lock.h"
5+
#include "thread_port.h"
6+
7+
8+
mp_obj_t *processes;
39

410
void multiprocessing_init(void)
511
{
6-
mp_obj_thread_thread_t * main_thread = (mp_obj_thread_thread_t *)MP_OBJ_TO_PTR(threading_main_thread());
12+
processes = (mp_obj_t *)malloc(sizeof(mp_obj_t) * mp_get_cpu_count());
13+
14+
mp_obj_thread_t * main_thread = (mp_obj_thread_t *)MP_OBJ_TO_PTR(threading_main_thread());
715
uint8_t curr_core_id = mp_get_process_core(&main_thread->thread);
816
processes[curr_core_id] = MP_OBJ_FROM_PTR(main_thread);
917
}
@@ -16,9 +24,9 @@ static mp_obj_t multiprocessing_active_children(void)
1624
uint8_t core_id = mp_get_current_process_core();
1725
uint8_t task_core_id;
1826

19-
threading_lock_acquire(&t_mutex, 1);
27+
threading_lock_acquire((thread_lock_t *)(&t_mutex), 1);
2028

21-
for (mp_obj_thread_thread_t *th = t_thread; th != NULL; th = th->next) {
29+
for (mp_obj_thread_t *th = t_thread; th != NULL; th = th->next) {
2230
if (!th->is_alive) {
2331
continue;
2432
}
@@ -29,7 +37,7 @@ static mp_obj_t multiprocessing_active_children(void)
2937
}
3038
}
3139

32-
threading_lock_release(&t_mutex);
40+
threading_lock_release((thread_lock_t *)(&t_mutex));
3341
return list;
3442
}
3543

ext_mod/threading/common/src/thread_event.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ static const mp_rom_map_elem_t event_locals_dict_table[] = {
108108

109109
static MP_DEFINE_CONST_DICT(event_locals_dict, event_locals_dict_table);
110110

111-
112111
MP_DEFINE_CONST_OBJ_TYPE(
113112
mp_type_threading_event_t,
114113
MP_QSTR_Event,

ext_mod/threading/common/src/thread_semaphore.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ static mp_obj_t thread_semaphore_acquire(size_t n_args, const mp_obj_t *pos_args
5959
bool res;
6060

6161
uint16_t
62-
bool threading_semphamore_acquire(thread_semphamore_t *sem, int32_t wait_ms);
63-
void threading_semphamore_release(thread_semphamore_t *sem);
64-
void threading_semphamore_init(thread_event_t *mutex);
65-
void threading_semphamore_delete(thread_event_t *mutex);
62+
bool threading_semaphore_acquire(thread_semaphore_t *sem, int32_t wait_ms);
63+
void threading_semaphore_release(thread_semaphore_t *sem);
64+
void threading_semaphore_init(thread_semaphore_t *sem);
65+
void threading_semaphore_delete(thread_semaphore_t *sem);
6666

67-
uint16_t count = threading_semphamore_get_count(&self->sem);
67+
uint16_t count = threading_semaphore_get_count(&self->sem);
6868

6969
if (!blocking) {
7070
if (count >= self->start_value) {
7171
res = false;
7272
} else {
73-
res = threading_semphamore_acquire(&self->sem, 0);
73+
res = threading_semaphore_acquire(&self->sem, 0);
7474
}
7575
} else {
7676
float timeout_f;
@@ -87,7 +87,7 @@ static mp_obj_t thread_semaphore_acquire(size_t n_args, const mp_obj_t *pos_args
8787
self->waiting += 1;
8888
}
8989

90-
res = threading_semphamore_acquire(&self->sem, timeout);
90+
res = threading_semaphore_acquire(&self->sem, timeout);
9191

9292
if (res == true) {
9393
if (self->waiting > 0) {
@@ -140,7 +140,7 @@ static mp_obj_t thread_semaphore_release(size_t n_args, const mp_obj_t *pos_args
140140
if (self->value > 0) {
141141
self->value -= 1;
142142
}
143-
threading_semphamore_release(&self->sem);
143+
threading_semaphore_release(&self->sem);
144144
}
145145
return mp_const_none;
146146
}
@@ -165,10 +165,10 @@ static mp_obj_t thread_semaphore__del__(mp_obj_t self_in)
165165
mp_obj_thread_semaphore_t *self = MP_OBJ_TO_PTR(self_in);
166166

167167
for (uint16_t i=self->value;i<self->start_value;i++) {
168-
threading_semphamore_release(&self->sem);
168+
threading_semaphore_release(&self->sem);
169169
}
170170

171-
threading_semphamore_delete(&self->sem);
171+
threading_semaphore_delete(&self->sem);
172172
return mp_const_none;
173173
}
174174

@@ -204,7 +204,7 @@ static mp_obj_t threading_semaphore_make_new(const mp_obj_type_t *type, size_t n
204204
return mp_const_none;
205205
}
206206

207-
threading_semphamore_init(&self->sem, (uint16_t)start_value)
207+
threading_semaphore_init(&self->sem, (uint16_t)start_value)
208208
self->start_value = (uint16_t)start_value;
209209

210210
return MP_OBJ_FROM_PTR(self);
@@ -267,7 +267,7 @@ static mp_obj_t multiprocessing_semaphore_make_new(const mp_obj_type_t *type, si
267267
return mp_const_none;
268268
}
269269

270-
threading_semphamore_init(&self->sem, (uint16_t)start_value);
270+
threading_semaphore_init(&self->sem, (uint16_t)start_value);
271271
self->start_value = (uint16_t)start_value;
272272

273273
return MP_OBJ_FROM_PTR(self);

0 commit comments

Comments
 (0)