Skip to content

Commit

Permalink
ADDED: is_message_queue/1 to test the existence of a message queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
JanWielemaker committed Sep 26, 2024
1 parent bdbe507 commit 1a2e209
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions man/summary.doc
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ suggest predicates from a keyword.
\predicatesummary{is_dict}{2}{Type check for a dict in a class}
\predicatesummary{is_engine}{1}{Type check for an engine handle}
\predicatesummary{is_list}{1}{Type check for a list}
\predicatesummary{is_message_queue}{1}{Type check for a message queue}
\predicatesummary{is_most_general_term}{1}{Type check for general term}
\predicatesummary{is_object}{1}{WASM: Test JavaScript object}
\predicatesummary{is_object}{2}{WASM: Test JavaScript object and class}
Expand Down
6 changes: 6 additions & 0 deletions man/threads.doc
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,12 @@ permission error is raised if \arg{Queue} refers to (the default queue
of) a thread. Other threads that are waiting for \arg{Queue} using
thread_get_message/2 receive an existence error.

\predicate[semidet]{is_message_queue}{1}{@Term}
True if \arg{Term} refers to an existing message queue. This predicate
can not block and has no error conditions. Note that message queues may
be destroyed asynchronously by another thread and \jargon{anonymous}
message queues may be garbage collected asynchronously.

\predicate[det]{thread_get_message}{2}{+Queue, ?Term}
As thread_get_message/1, operating on a given queue. It is allowed (but
not advised) to get messages from the queue of other threads. This
Expand Down
23 changes: 23 additions & 0 deletions src/pl-thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -5478,6 +5478,28 @@ PRED_IMPL("message_queue_destroy", 1, message_queue_destroy, 0)
}


static
PRED_IMPL("is_message_queue", 1, is_message_queue, 0)
{ message_queue *q;
PL_blob_t *type;
void *data;
atom_t id;

if ( PL_get_blob(A1, &data, NULL, &type) && type == &message_queue_blob )
{ mqref *ref = data;

q = ref->queue;
return (q && !q->destroyed);
}

if ( queueTable && PL_get_atom(A1, &id) )
{ if ( (q = lookupHTableWP(queueTable, id)) )
return !q->destroyed;
}

return false;
}

/*******************************
* MESSAGE QUEUE PROPERTY *
*******************************/
Expand Down Expand Up @@ -8410,6 +8432,7 @@ BeginPredDefs(thread)
PRED_DEF("message_queue_create", 2, message_queue_create2, PL_FA_ISO)
PRED_DEF("message_queue_property", 2, message_property, NDET|PL_FA_ISO)
PRED_DEF("message_queue_set", 2, message_queue_set, 0)
PRED_DEF("is_message_queue", 1, is_message_queue, 0)

PRED_DEF("thread_send_message", 2, thread_send_message, PL_FA_ISO)
PRED_DEF("thread_send_message", 3, thread_send_message, 0)
Expand Down

0 comments on commit 1a2e209

Please sign in to comment.