mirror of https://github.com/rusefi/bldc.git
Merge commit 'a746ac32cf1ec99b92b9802cca6ca92eec7deb53'
This commit is contained in:
commit
949943b3ac
|
@ -119,7 +119,15 @@ lbm_cid lbm_get_event_handler_pid(void);
|
|||
* \param pid The ID of the process to which events should be sent
|
||||
*/
|
||||
void lbm_set_event_handler_pid(lbm_cid pid);
|
||||
/** Check if an event handler is registerd.
|
||||
* \return True if event handler exists, otherwise false.
|
||||
*/
|
||||
bool lbm_event_handler_exists(void);
|
||||
/** Send an event to the registered event handler process.
|
||||
* If lbm_event returns false the C code will still be responsible for
|
||||
* the flat_value passed into lbm_event. If lbm_event returns true,
|
||||
* the LBM runtime system will take responsibility for the freeing
|
||||
* of the memory allocated in the flat_value.
|
||||
* \param event The event to send to the registered handler.
|
||||
* \param opt_array An optional array to pass to the event handler.
|
||||
* \param opt_array_len Length of array mandatory if array is passed in.
|
||||
|
@ -223,12 +231,12 @@ void lbm_block_ctx_from_extension(void);
|
|||
bool lbm_unblock_ctx(lbm_cid cid, lbm_flat_value_t *fv);
|
||||
/** Unblock a context bypassing the event-queue.
|
||||
* Since the context will be unblocked in a separate tread it cannot
|
||||
* take a composite return value. True or Nil are allowed.
|
||||
* take a composite return value. Only unboxed lbm_values are allowed.
|
||||
* \param cid Lisp process to inblock.
|
||||
* \param r_val If true the process unblocks with value t otherwise nil.
|
||||
* \param unboxed An unboxed lbm_value: char, i, u or symbol type.
|
||||
* \return True on successfully unblocking. False otherwise.
|
||||
*/
|
||||
bool lbm_force_unblock(lbm_cid cid, bool r_val);
|
||||
bool lbm_unblock_ctx_unboxed(lbm_cid cid, lbm_value unboxed);
|
||||
/** Iterate over all ready contexts and apply function on each context.
|
||||
*
|
||||
* \param f Function to apply to each context.
|
||||
|
|
|
@ -225,19 +225,23 @@ void lbm_set_event_handler_pid(lbm_cid pid) {
|
|||
}
|
||||
|
||||
static bool event_internal(lbm_event_type_t event_type, lbm_uint parameter, lbm_uint buf_ptr, uint32_t buf_len) {
|
||||
if (!lbm_events) return false;
|
||||
mutex_lock(&lbm_events_mutex);
|
||||
if (lbm_events_full) return false;
|
||||
lbm_event_t event;
|
||||
event.type = event_type;
|
||||
event.parameter = parameter;
|
||||
event.buf_ptr = buf_ptr;
|
||||
event.buf_len = buf_len;
|
||||
lbm_events[lbm_events_head] = event;
|
||||
lbm_events_head = (lbm_events_head + 1) % lbm_events_max;
|
||||
lbm_events_full = lbm_events_head == lbm_events_tail;
|
||||
mutex_unlock(&lbm_events_mutex);
|
||||
return true;
|
||||
bool r = false;
|
||||
if (lbm_events) {
|
||||
mutex_lock(&lbm_events_mutex);
|
||||
if (!lbm_events_full) {
|
||||
lbm_event_t event;
|
||||
event.type = event_type;
|
||||
event.parameter = parameter;
|
||||
event.buf_ptr = buf_ptr;
|
||||
event.buf_len = buf_len;
|
||||
lbm_events[lbm_events_head] = event;
|
||||
lbm_events_head = (lbm_events_head + 1) % lbm_events_max;
|
||||
lbm_events_full = lbm_events_head == lbm_events_tail;
|
||||
r = true;
|
||||
}
|
||||
mutex_unlock(&lbm_events_mutex);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
bool lbm_event_unboxed(lbm_value unboxed) {
|
||||
|
@ -257,10 +261,13 @@ bool lbm_event(lbm_flat_value_t *fv) {
|
|||
if (lbm_event_handler_pid > 0) {
|
||||
return event_internal(LBM_EVENT_FOR_HANDLER, 0, (lbm_uint)fv->buf, fv->buf_size);
|
||||
}
|
||||
lbm_free(fv->buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool lbm_event_handler_exists(void) {
|
||||
return(lbm_event_handler_pid > 0);
|
||||
}
|
||||
|
||||
static bool lbm_event_pop(lbm_event_t *event) {
|
||||
mutex_lock(&lbm_events_mutex);
|
||||
if (lbm_events_head == lbm_events_tail && !lbm_events_full) {
|
||||
|
@ -930,19 +937,25 @@ bool lbm_unblock_ctx(lbm_cid cid, lbm_flat_value_t *fv) {
|
|||
return event_internal(LBM_EVENT_UNBLOCK_CTX, (lbm_uint)cid, (lbm_uint)fv->buf, fv->buf_size);
|
||||
}
|
||||
|
||||
bool lbm_force_unblock(lbm_cid cid, bool r_val) {
|
||||
bool lbm_unblock_ctx_unboxed(lbm_cid cid, lbm_value unboxed) {
|
||||
bool r = false;
|
||||
lbm_value v = r_val ? ENC_SYM_TRUE : ENC_SYM_NIL;
|
||||
eval_context_t *found = NULL;
|
||||
mutex_lock(&qmutex);
|
||||
found = lookup_ctx_nm(&blocked, cid);
|
||||
if (found) {
|
||||
drop_ctx_nm(&blocked,found);
|
||||
found->r = v;
|
||||
enqueue_ctx_nm(&queue,found);
|
||||
r = true;
|
||||
lbm_uint t = lbm_type_of(unboxed);
|
||||
if (t == LBM_TYPE_SYMBOL ||
|
||||
t == LBM_TYPE_I ||
|
||||
t == LBM_TYPE_U ||
|
||||
t == LBM_TYPE_CHAR) {
|
||||
|
||||
eval_context_t *found = NULL;
|
||||
mutex_lock(&qmutex);
|
||||
found = lookup_ctx_nm(&blocked, cid);
|
||||
if (found) {
|
||||
drop_ctx_nm(&blocked,found);
|
||||
found->r = unboxed;
|
||||
enqueue_ctx_nm(&queue,found);
|
||||
r = true;
|
||||
}
|
||||
mutex_unlock(&qmutex);
|
||||
}
|
||||
mutex_unlock(&qmutex);
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue