Skip to content

Commit

Permalink
support gil exit with bare
Browse files Browse the repository at this point in the history
  • Loading branch information
pikasTech committed May 14, 2024
1 parent 599759a commit 65249be
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
19 changes: 14 additions & 5 deletions src/PikaObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ PikaObj* _pika_dict_new(int num_args, ...) {
}

NativeProperty* obj_getProp(PikaObj* self) {
Arg* aProp = obj_getArg(self, "@p");
Arg* aProp = obj_getArg(self, "@p_");
PikaObj* class_obj = NULL;
if (NULL == aProp) {
if (NULL != self->constructor) {
class_obj = obj_getClassObj(self);
aProp = obj_getArg(class_obj, "@p");
aProp = obj_getArg(class_obj, "@p_");
}
}
NativeProperty* prop = NULL;
Expand Down Expand Up @@ -694,7 +694,7 @@ void* getNewClassObjFunByName(PikaObj* obj, char* name) {
PikaObj* removeMethodInfo(PikaObj* thisClass) {
#if PIKA_METHOD_CACHE_ENABLE
#else
args_removeArg(thisClass->list, args_getArg(thisClass->list, "@p"));
args_removeArg(thisClass->list, args_getArg(thisClass->list, "@p_"));
#endif
return thisClass;
}
Expand Down Expand Up @@ -2962,7 +2962,7 @@ void pika_debug_bytes(uint8_t* buff, size_t len) {
for (size_t i = 0; i < len; i++) {
pika_debug_raw("0x%02X", buff[i]);
if (i < len - 1) {
printf(",");
pika_debug_raw(",");
}
}
pika_debug_raw("]\n");
Expand Down Expand Up @@ -3016,7 +3016,16 @@ PIKA_RES _do_pika_eventListener_send(PikaEventListener* self,
if (pika_GIL_isInit()) {
/* python thread is running */
/* wait python thread get first lock */
while (!_VM_is_first_lock() && g_PikaVMState.vm_cnt != 0) {
while (1){
if (_VM_is_first_lock()){
break;
}
if (pika_GIL_getBareLock() == 0){
break;
}
if (g_PikaVMState.vm_cnt == 0){
break;
}
pika_platform_thread_yield();
}
pika_GIL_ENTER();
Expand Down
4 changes: 3 additions & 1 deletion src/PikaObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ const MethodProp floatMethod = {

void _obj_updateProxyFlag(PikaObj* self);
#define obj_setClass(_self, _method) \
obj_setPtr((_self), "@p", (void*)&pika_class(_method)); \
obj_setPtr((_self), "@p_", (void*)&pika_class(_method)); \
_obj_updateProxyFlag((_self))

Arg* _obj_getPropArg(PikaObj* obj, char* name);
Expand Down Expand Up @@ -840,6 +840,8 @@ uint32_t pikaGC_printFreeList(void);

int pika_GIL_EXIT(void);
int pika_GIL_ENTER(void);
int pika_GIL_getBareLock(void);


int32_t pika_debug_find_break_point_pc(char* pyFile, uint32_t pyLine);

Expand Down
4 changes: 4 additions & 0 deletions src/PikaVM.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ int pika_GIL_ENTER(void) {
return ret;
}

int pika_GIL_getBareLock(void){
return g_pikaGIL.mutex.bare_lock;
}

int pika_GIL_EXIT(void) {
if (!g_pikaGIL.mutex.is_init) {
g_pikaGIL.mutex.bare_lock = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/pika_config_valid.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extern "C" {
#endif

#ifndef PIKA_STACK_BUFF_SIZE
#define PIKA_STACK_BUFF_SIZE 256
#define PIKA_STACK_BUFF_SIZE 512
#endif

#ifndef PIKA_NAME_BUFF_SIZE
Expand Down

0 comments on commit 65249be

Please sign in to comment.