Skip to content

Commit 8b4781d

Browse files
committed
Fixes some of the compile errors.
Still needs more work...
1 parent 377c2d6 commit 8b4781d

File tree

15 files changed

+159
-221
lines changed

15 files changed

+159
-221
lines changed

ext_mod/threading/common/inc/thread_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef __THREAD_EVENT_H__
77
#define __THREAD_EVENT_H__
88

9-
typedef struct _thread_event_t thread_event_t; // needs to be defined in port
9+
#include "thread_port.h"
1010

1111
typedef struct _mp_obj_thread_event_t {
1212
mp_obj_base_t base;

ext_mod/threading/common/inc/thread_lock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef __THREAD_LOCK_H__
77
#define __THREAD_LOCK_H__
88

9-
typedef struct _thread_lock_t thread_lock_t; // needs to be defined in port
9+
#include "thread_port.h"
1010

1111
typedef struct _mp_obj_lock_t {
1212
mp_obj_base_t base;

ext_mod/threading/common/inc/thread_rlock.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include "freertos/FreeRTOS.h"
66
#include "freertos/semphr.h"
77

8-
#include "thread_common.h"
8+
#include "threading.h"
99

1010
#ifndef __THREAD_RLOCK_H__
1111
#define __THREAD_RLOCK_H__
1212

13-
typedef struct _thread_rlock_t thread_rlock_t; // needs to be defined in port
13+
#include "thread_port.h"
1414

1515
typedef struct _mp_obj_rlock_t {
1616
mp_obj_base_t base;

ext_mod/threading/common/inc/thread_semaphore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef __THREAD_SEMAPHORE_H__
77
#define __THREAD_SEMAPHORE_H__
88

9-
typedef struct _thread_semaphore_t thread_semaphore_t; // needs to be defined in port
9+
#include "thread_port.h"
1010

1111
typedef struct _mp_obj_thread_semaphore_t {
1212
mp_obj_base_t base;
@@ -17,7 +17,7 @@
1717
uint16_t threading_semaphore_get_count(thread_semaphore_t *sem); // needs to be defined in port
1818
bool threading_semaphore_acquire(thread_semaphore_t *sem, int32_t wait_ms); // needs to be defined in port
1919
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
20+
void threading_semaphore_init(thread_semaphore_t *sem, uint16_t start_value); // needs to be defined in port
2121
void threading_semaphore_delete(thread_semaphore_t *sem); // needs to be defined in port
2222

2323
extern const mp_obj_type_t mp_type_threading_semaphore_t;

ext_mod/threading/common/inc/thread_thread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#ifndef __THREAD_THREAD_H__
77
#define __THREAD_THREAD_H__
88

9-
typedef struct _thread_t thread_t; // needs to be defined in port
9+
#include "thread_port.h"
1010

1111
typedef struct _thread_entry_args_t {
1212
mp_obj_dict_t *dict_locals;

ext_mod/threading/common/src/multiprocessing.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void multiprocessing_init(void)
1111
{
1212
processes = (mp_obj_t *)malloc(sizeof(mp_obj_t) * mp_get_cpu_count());
1313

14-
mp_obj_thread_t * main_thread = (mp_obj_thread_t *)MP_OBJ_TO_PTR(threading_main_thread());
14+
mp_obj_thread_t * main_thread = (mp_obj_thread_t *)MP_OBJ_TO_PTR(mp_get_main_thread());
1515
uint8_t curr_core_id = mp_get_process_core(&main_thread->thread);
1616
processes[curr_core_id] = MP_OBJ_FROM_PTR(main_thread);
1717
}
@@ -46,7 +46,7 @@ static MP_DEFINE_CONST_FUN_OBJ_0(multiprocessing_active_children_obj, multiproce
4646

4747
static mp_obj_t multiprocessing_cpu_count(void)
4848
{
49-
return mp_obj_new_int_truncated(mp_get_cpu_count());
49+
return mp_obj_new_int_from_uint(mp_get_cpu_count());
5050
}
5151

5252
static MP_DEFINE_CONST_FUN_OBJ_0(multiprocessing_cpu_count_obj, multiprocessing_cpu_count);
@@ -63,7 +63,7 @@ static MP_DEFINE_CONST_FUN_OBJ_0(multiprocessing_current_process_obj, multiproce
6363

6464
static mp_obj_t multiprocessing_parent_process(void)
6565
{
66-
mp_obj_t main_thread = threading_main_thread();
66+
// mp_obj_t main_thread = mp_get_main_thread();
6767
uint8_t core_id = mp_get_current_process_core();
6868

6969
return processes[core_id];

ext_mod/threading/common/src/thread_event.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#include "freertos/semphr.h"
77
#include "freertos/event_groups.h"
88

9+
#include "threading.h"
910
#include "thread_event.h"
1011

1112

13+
1214
static mp_obj_t event_is_set(mp_obj_t self_in)
1315
{
1416
mp_obj_thread_event_t *self = MP_OBJ_TO_PTR(self_in);
15-
bool res = threading_event_isset(&self->event);
16-
return mp_obj_new_bool(res);
17+
return mp_obj_new_bool(self->event.is_set);
1718
}
1819

1920
static MP_DEFINE_CONST_FUN_OBJ_1(event_is_set_obj, event_is_set);
@@ -23,6 +24,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(event_is_set_obj, event_is_set);
2324
static mp_obj_t event_set(mp_obj_t self_in)
2425
{
2526
mp_obj_thread_event_t *self = MP_OBJ_TO_PTR(self_in);
27+
self->event.is_set = true;
2628
threading_event_set(&self->event);
2729
return mp_const_none;
2830
}
@@ -34,6 +36,7 @@ static MP_DEFINE_CONST_FUN_OBJ_1(event_set_obj, event_set);
3436
static mp_obj_t event_clear(mp_obj_t self_in)
3537
{
3638
mp_obj_thread_event_t *self = MP_OBJ_TO_PTR(self_in);
39+
self->event.is_set = false;
3740
threading_event_clear(&self->event);
3841
return mp_const_none;
3942
}
@@ -64,7 +67,7 @@ static mp_obj_t event_wait(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw
6467
}
6568

6669
int32_t timeout = (int32_t)(timeout_f * 1000);
67-
threading_event_wait(&(self->event, timeout);
70+
threading_event_wait(&self->event, timeout);
6871
return mp_const_none;
6972
}
7073

@@ -82,7 +85,7 @@ static mp_obj_t event__del__(mp_obj_t self_in)
8285
static MP_DEFINE_CONST_FUN_OBJ_1(event__del__obj, event__del__);
8386

8487

85-
static mp_obj_t threading_event_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
88+
static mp_obj_t thread_event_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
8689
{
8790
THREAD_UNUSED(type);
8891
THREAD_UNUSED(n_args);
@@ -92,7 +95,7 @@ static mp_obj_t threading_event_make_new(const mp_obj_type_t *type, size_t n_arg
9295
// create new object
9396
mp_obj_thread_event_t *self = m_new_obj(mp_obj_thread_event_t);
9497
self->base.type = &mp_type_threading_event_t;
95-
98+
self->event.is_set = false;
9699
threading_event_init(&self->event);
97100
return MP_OBJ_FROM_PTR(self);
98101
}
@@ -113,17 +116,17 @@ MP_DEFINE_CONST_OBJ_TYPE(
113116
MP_QSTR_Event,
114117
MP_TYPE_FLAG_NONE,
115118
// print, mp_lv_grad_t_print,
116-
make_new, threading_event_make_new,
119+
make_new, thread_event_make_new,
117120
// binary_op, lv_struct_binary_op,
118121
// subscr, lv_struct_subscr,
119122
// attr, mp_threading_semaphore_attr,
120-
locals_dict, &threading_event_locals_dict
123+
locals_dict, &event_locals_dict
121124
// buffer, mp_blob_get_buffer,
122125
// parent, &mp_lv_base_struct_type
123126
);
124127

125128

126-
static mp_obj_t multiprocessing_event_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
129+
static mp_obj_t multiprocess_event_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
127130
{
128131
THREAD_UNUSED(type);
129132
THREAD_UNUSED(n_args);
@@ -133,7 +136,7 @@ static mp_obj_t multiprocessing_event_make_new(const mp_obj_type_t *type, size_t
133136
// create new object
134137
mp_obj_thread_event_t *self = m_new_obj(mp_obj_thread_event_t);
135138
self->base.type = &mp_type_multiprocessing_event_t;
136-
139+
self->event.is_set = false;
137140
threading_event_init(&self->event);
138141
return MP_OBJ_FROM_PTR(self);
139142
}
@@ -143,7 +146,7 @@ MP_DEFINE_CONST_OBJ_TYPE(
143146
MP_QSTR_Event,
144147
MP_TYPE_FLAG_NONE,
145148
// print, mp_lv_grad_t_print,
146-
make_new, multiprocessing_event_make_new,
149+
make_new, multiprocess_event_make_new,
147150
// binary_op, lv_struct_binary_op,
148151
// subscr, lv_struct_subscr,
149152
// attr, mp_threading_semaphore_attr,

ext_mod/threading/common/src/thread_lock.c

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include "py/runtime.h"
44

55
#include "thread_lock.h"
6-
#include "thread_common.h"
6+
#include "threading.h"
77

88

9-
static mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
9+
static mp_obj_t lock_acquire(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
1010
{
1111
enum { ARG_self, ARG_blocking, ARG_timeout };
1212

@@ -36,76 +36,77 @@ static mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *pos_args, mp_
3636
timeout = 0;
3737
}
3838

39-
self->ref_count += 1;
40-
int ret = threading_lock_acquire(&self->mutex, timeout);
39+
self->lock.ref_count += 1;
40+
int ret = threading_lock_acquire(&self->lock, timeout);
4141

4242
if (ret == 0) {
43-
self->ref_count -= 1;
43+
self->lock.ref_count -= 1;
4444
return mp_const_false;
4545
} else if (ret == 1) {
4646
return mp_const_true;
4747
} else {
48-
self->ref_count -= 1;
48+
self->lock.ref_count -= 1;
4949
mp_raise_OSError(-ret);
5050
return mp_const_none;
5151
}
5252
}
5353

54-
static MP_DEFINE_CONST_FUN_OBJ_KW(thread_lock_acquire_obj, 3, thread_lock_acquire);
54+
static MP_DEFINE_CONST_FUN_OBJ_KW(lock_acquire_obj, 3, lock_acquire);
5555

5656

57-
static mp_obj_t thread_lock__enter__(size_t n_args, const mp_obj_t *args)
57+
static mp_obj_t lock__enter__(size_t n_args, const mp_obj_t *args)
5858
{
5959
(void)n_args; // unused
6060
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(args[0]);
6161

62-
self->ref_count += 1;
63-
threading_lock_acquire(&self->mutex, -1);
62+
self->lock.ref_count += 1;
63+
threading_lock_acquire(&self->lock, -1);
6464
return mp_const_none
6565
}
6666

6767

68-
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock__enter__obj, 1, 1, thread_lock__enter__);
68+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lock__enter__obj, 1, 1, lock__enter__);
6969

7070

71-
static mp_obj_t thread_lock_release(mp_obj_t self_in)
71+
static mp_obj_t lock_release(mp_obj_t self_in)
7272
{
7373
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
74-
if (self->ref_count == 0) {
74+
if (self->lock.ref_count == 0) {
7575
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Lock is already released");
7676
} else {
7777
threading_lock_release(&self->mutex);
7878
}
7979

80-
self->ref_count -= 1;
80+
self->lock.ref_count -= 1;
8181

8282
return mp_const_none;
8383
}
8484

85-
static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release);
85+
static MP_DEFINE_CONST_FUN_OBJ_1(lock_release_obj, lock_release);
8686

8787

88-
static mp_obj_t thread_lock__exit__(size_t n_args, const mp_obj_t *args)
88+
static mp_obj_t lock__exit__(size_t n_args, const mp_obj_t *args)
8989
{
9090
(void)n_args; // unused
91-
return thread_lock_release(args[0]);
91+
lock_release(args[0]);
92+
return mp_const_none;
9293
}
9394

94-
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock__exit__obj, 4, 4, thread_lock__exit__);
95+
static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(lock__exit__obj, 4, 4, lock__exit__);
9596

9697

97-
static mp_obj_t thread_lock_locked(mp_obj_t self_in)
98+
static mp_obj_t lock_locked(mp_obj_t self_in)
9899
{
99100
mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in);
100101

101-
return mp_obj_new_bool(self->ref_count != 0);
102+
return mp_obj_new_bool(self->lock.ref_count != 0);
102103
}
103104

104-
static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked);
105+
static MP_DEFINE_CONST_FUN_OBJ_1(lock_locked_obj, lock_locked);
105106

106107

107108

108-
static mp_obj_t threading_lock_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
109+
static mp_obj_t thread_lock_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
109110
{
110111
THREAD_UNUSED(type);
111112
THREAD_UNUSED(n_args);
@@ -115,39 +116,39 @@ static mp_obj_t threading_lock_make_new(const mp_obj_type_t *type, size_t n_args
115116
mp_obj_thread_lock_t *self = m_new_obj(mp_obj_thread_lock_t);
116117
self->base.type = &mp_type_threading_lock_t;
117118

118-
lock_init(&self->mutex);
119+
threading_lock_init(&self->lock;
119120
self->locked = false;
120121
return MP_OBJ_FROM_PTR(self);
121122
}
122123

123124

124-
static const mp_rom_map_elem_t threading_lock_locals_dict_table[] = {
125+
static const mp_rom_map_elem_t lock_locals_dict_table[] = {
125126
{ MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) },
126127
{ MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) },
127128
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&thread_lock__enter__obj) },
128129
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock__exit__obj) },
129130
{ MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) },
130131
};
131132

132-
static MP_DEFINE_CONST_DICT(threading_lock_locals_dict, threading_lock_locals_dict_table);
133+
static MP_DEFINE_CONST_DICT(lock_locals_dict, lock_locals_dict_table);
133134

134135

135136
MP_DEFINE_CONST_OBJ_TYPE(
136137
mp_type_threading_lock_t,
137138
MP_QSTR_Lock,
138139
MP_TYPE_FLAG_NONE,
139140
// print, mp_lv_grad_t_print,
140-
make_new, threading_lock_make_new,
141+
make_new, thread_lock_make_new,
141142
// binary_op, lv_struct_binary_op,
142143
// subscr, lv_struct_subscr,
143144
// attr, mp_threading_semaphore_attr,
144-
locals_dict, &threading_lock_locals_dict
145+
locals_dict, &lock_locals_dict
145146
// buffer, mp_blob_get_buffer,
146147
// parent, &mp_lv_base_struct_type
147148
);
148149

149150

150-
static mp_obj_t multiprocessing_lock_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
151+
static mp_obj_t multiprocess_lock_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args)
151152
{
152153
THREAD_UNUSED(type);
153154
THREAD_UNUSED(n_args);
@@ -157,33 +158,22 @@ static mp_obj_t multiprocessing_lock_make_new(const mp_obj_type_t *type, size_t
157158
mp_obj_thread_lock_t *self = m_new_obj(mp_obj_thread_lock_t);
158159
self->base.type = &mp_type_multiprocessing_lock_t;
159160

160-
lock_init(&self->mutex);
161-
self->ref_count = 0;
161+
threading_lock_init(&self->lock);
162+
self->lock.ref_count = 0;
162163
return MP_OBJ_FROM_PTR(self);
163164
}
164165

165166

166-
static const mp_rom_map_elem_t multiprocessing_lock_locals_dict_table[] = {
167-
{ MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) },
168-
{ MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) },
169-
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&thread_lock__enter__obj) },
170-
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock__exit__obj) },
171-
{ MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) },
172-
};
173-
174-
static MP_DEFINE_CONST_DICT(multiprocessing_lock_locals_dict, multiprocessing_lock_locals_dict_table);
175-
176-
177167
MP_DEFINE_CONST_OBJ_TYPE(
178168
mp_type_multiprocessing_lock_t,
179169
MP_QSTR_Lock,
180170
MP_TYPE_FLAG_NONE,
181171
// print, mp_lv_grad_t_print,
182-
make_new, multiprocessing_lock_make_new,
172+
make_new, multiprocess_lock_make_new,
183173
// binary_op, lv_struct_binary_op,
184174
// subscr, lv_struct_subscr,
185175
// attr, mp_threading_semaphore_attr,
186-
locals_dict, &multiprocessing_lock_locals_dict
176+
locals_dict, &lock_locals_dict
187177
// buffer, mp_blob_get_buffer,
188178
// parent, &mp_lv_base_struct_type
189179
);

0 commit comments

Comments
 (0)