Skip to content

multi-thread in the Patmos Platform#582

Open
EhsanKhodadad wants to merge 7 commits into
lf-lang:mainfrom
EhsanKhodadad:main
Open

multi-thread in the Patmos Platform#582
EhsanKhodadad wants to merge 7 commits into
lf-lang:mainfrom
EhsanKhodadad:main

Conversation

@EhsanKhodadad

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings April 29, 2026 12:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to add multi-threaded runtime support for the Patmos platform by introducing Patmos implementations of the LF threading/synchronization abstractions when LF_SINGLE_THREADED is not defined.

Changes:

  • Added a Patmos “threaded” branch in lf_patmos_support.c with implementations for threads, mutexes, and condition variables.
  • Added Patmos platform typedefs for lf_thread_t, lf_mutex_t, and lf_cond_t under !LF_SINGLE_THREADED.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
low_level_platform/impl/src/lf_patmos_support.c Adds Patmos-side threaded implementations (threads/mutex/cond) and related helpers under #else of LF_SINGLE_THREADED.
low_level_platform/api/platform/lf_patmos_support.h Introduces threaded Patmos typedefs and includes <pthread.h> when !LF_SINGLE_THREADED.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/api/platform/lf_patmos_support.h Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Co-authored-by: Copilot <copilot@github.com>

@edwardalee edwardalee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to me like the Copilot suggestions need to be addressed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/impl/src/lf_patmos_support.c Outdated
Comment thread low_level_platform/api/platform/lf_patmos_support.h
@edwardalee

Copy link
Copy Markdown
Contributor

As you address issues raised by Copilot, please record a brief comment on how the issue was addressed and mark the comment "Resolved".

@EhsanKhodadad EhsanKhodadad requested a review from Copilot May 23, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

Comment thread low_level_platform/api/platform/lf_patmos_support.h
Comment thread low_level_platform/impl/src/lf_patmos_support.c
Comment on lines +167 to +173
int lf_disable_interrupts_nested() {
// Disable interrupts first and increment the per-core nesting counter.
intr_disable();
volatile int* nested_counter = _lf_current_core_nested_counter();
(*nested_counter)++;
return 0;
}
Comment on lines 21 to 33
int lf_atomic_fetch_add(int* ptr, int value) {
lf_disable_interrupts_nested();
#if defined(PLATFORM_PATMOS) && !defined(LF_SINGLE_THREADED)
_lf_patmos_global_lock_acquire();
#endif
int res = *ptr;
*ptr += value;
#if defined(PLATFORM_PATMOS) && !defined(LF_SINGLE_THREADED)
_lf_patmos_global_lock_release();
#endif
lf_enable_interrupts_nested();
return res;
}
Comment on lines +25 to +38
#if !defined(LF_SINGLE_THREADED)
#include <pthread.h>
typedef pthread_t lf_thread_t;
typedef pthread_mutex_t lf_mutex_t;
typedef struct {
lf_mutex_t* mutex;
pthread_cond_t condition;
} lf_cond_t;
#if !defined(LF_SINGLE_THREADED)
// Cross-core global lock used by atomic implementations on Patmos.
void _lf_patmos_global_lock_acquire(void);
void _lf_patmos_global_lock_release(void);
#endif
#endif
Comment on lines 99 to 107
int lf_disable_interrupts_nested() {
// For the single-threaded path, disable interrupts first then increment
// the nesting counter to avoid preemption windows on this core.
intr_disable();
if (_lf_num_nested_critical_sections++ == 0) {
intr_disable();
// already disabled above
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants