{MP_ "MAKE-SEMAPHORE", MP_ORDINARY, IF_MP(mp_make_semaphore), -1, OBJNULL},
{MP_ "SIGNAL-SEMAPHORE", MP_ORDINARY, IF_MP(mp_signal_semaphore), -1, OBJNULL},
{MP_ "WAIT-ON-SEMAPHORE", MP_ORDINARY, IF_MP(mp_wait_on_semaphore), 1, OBJNULL},
+{MP_ "TRY-GET-SEMAPHORE", MP_ORDINARY, IF_MP(mp_try_get_semaphore), 1, OBJNULL},
{MP_ "SEMAPHORE-COUNT", MP_ORDINARY, IF_MP(mp_semaphore_count), 1, OBJNULL},
{MP_ "SEMAPHORE-NAME", MP_ORDINARY, IF_MP(mp_semaphore_name), 1, OBJNULL},
{MP_ "SEMAPHORE-WAIT-COUNT", MP_ORDINARY, IF_MP(mp_semaphore_wait_count), 1, OBJNULL},
{MP_ "MAILBOX-COUNT", MP_ORDINARY, IF_MP(mp_mailbox_count), 1, OBJNULL},
{MP_ "MAILBOX-EMPTY-P", MP_ORDINARY, IF_MP(mp_mailbox_empty_p), 1, OBJNULL},
{MP_ "MAILBOX-READ", MP_ORDINARY, IF_MP(mp_mailbox_read), 1, OBJNULL},
+{MP_ "MAILBOX-TRY-READ", MP_ORDINARY, IF_MP(mp_mailbox_try_read), 1, OBJNULL},
{MP_ "MAILBOX-SEND", MP_ORDINARY, IF_MP(mp_mailbox_send), 2, OBJNULL},
+{MP_ "MAILBOX-TRY-SEND", MP_ORDINARY, IF_MP(mp_mailbox_try_send), 2, OBJNULL},
/* #endif defined(ECL_THREADS) */
{SYS_ "WHILE", SI_ORDINARY, NULL, -1, OBJNULL},
{MP_ "INTERRUPT-PROCESS",IF_MP("mp_interrupt_process")},
{MP_ "+LOAD-COMPILE-LOCK+",NULL},
{MP_ "WITH-LOCK",NULL},
-{MP_ "WITH-LOCK",NULL},
+{MP_ "WITH-RWLOCK",NULL},
{MP_ "BLOCK-SIGNALS",IF_MP("mp_block_signals")},
{MP_ "RESTORE-SIGNALS",IF_MP("mp_restore_signals")},
{MP_ "PROCESS-SUSPEND",IF_MP("mp_process_suspend")},
{MP_ "MAKE-SEMAPHORE",IF_MP("mp_make_semaphore")},
{MP_ "SIGNAL-SEMAPHORE",IF_MP("mp_signal_semaphore")},
{MP_ "WAIT-ON-SEMAPHORE",IF_MP("mp_wait_on_semaphore")},
+{MP_ "TRY-GET-SEMAPHORE",IF_MP("mp_try_get_semaphore")},
{MP_ "SEMAPHORE-COUNT",IF_MP("mp_semaphore_count")},
{MP_ "SEMAPHORE-NAME",IF_MP("mp_semaphore_name")},
{MP_ "SEMAPHORE-WAIT-COUNT",IF_MP("mp_semaphore_wait_count")},
{MP_ "MAILBOX-COUNT",IF_MP("mp_mailbox_count")},
{MP_ "MAILBOX-EMPTY-P",IF_MP("mp_mailbox_empty_p")},
{MP_ "MAILBOX-READ",IF_MP("mp_mailbox_read")},
+{MP_ "MAILBOX-TRY-READ",IF_MP("mp_mailbox_try_read")},
{MP_ "MAILBOX-SEND",IF_MP("mp_mailbox_send")},
+{MP_ "MAILBOX-TRY-SEND",IF_MP("mp_mailbox_try_send")},
/* #endif defined(ECL_THREADS) */
{SYS_ "WHILE",NULL},
}
cl_object
+mp_mailbox_try_read(cl_object mailbox)
+{
+ cl_env_ptr env = ecl_process_env();
+ cl_fixnum ndx;
+ cl_object output;
+ unlikely_if (ecl_t_of(mailbox) != t_mailbox) {
+ FEerror_not_a_mailbox(mailbox);
+ }
+ output = mp_try_get_semaphore(mailbox->mailbox.reader_semaphore);
+ if (output != ECL_NIL) {
+ ndx = AO_fetch_and_add1((AO_t*)&mailbox->mailbox.read_pointer) &
+ mailbox->mailbox.mask;
+ output = mailbox->mailbox.data->vector.self.t[ndx];
+ mp_signal_semaphore(1, mailbox->mailbox.writer_semaphore);
+ }
+ ecl_return1(env, output);
+}
+
+cl_object
mp_mailbox_send(cl_object mailbox, cl_object msg)
{
cl_env_ptr env = ecl_process_env();
mp_signal_semaphore(1, mailbox->mailbox.reader_semaphore);
ecl_return0(env);
}
+
+cl_object
+mp_mailbox_try_send(cl_object mailbox, cl_object msg)
+{
+ cl_env_ptr env = ecl_process_env();
+ cl_object output;
+ cl_fixnum ndx;
+ unlikely_if (ecl_t_of(mailbox) != t_mailbox) {
+ FEerror_not_a_mailbox(mailbox);
+ }
+ output = mp_try_get_semaphore(mailbox->mailbox.writer_semaphore);
+ if (output != ECL_NIL) {
+ output = msg;
+ ndx = AO_fetch_and_add1((AO_t*)&mailbox->mailbox.write_pointer) &
+ mailbox->mailbox.mask;
+ mailbox->mailbox.data->vector.self.t[ndx] = msg;
+ mp_signal_semaphore(1, mailbox->mailbox.reader_semaphore);
+ }
+ ecl_return1(env, output);
+}
+
}
ecl_return1(env, output);
}
+
+cl_object
+mp_try_get_semaphore(cl_object semaphore)
+{
+ cl_env_ptr env = ecl_process_env();
+ cl_object output;
+ unlikely_if (ecl_t_of(semaphore) != t_semaphore) {
+ FEerror_not_a_semaphore(semaphore);
+ }
+ ecl_return1(env, get_semaphore_inner(env, semaphore));
+}
+
extern ECL_API cl_object mp_semaphore_name(cl_object);
extern ECL_API cl_object mp_semaphore_wait_count(cl_object);
extern ECL_API cl_object mp_wait_on_semaphore(cl_object);
+extern ECL_API cl_object mp_try_get_semaphore(cl_object);
extern ECL_API cl_object mp_signal_semaphore _ECL_ARGS((cl_narg, cl_object, ...));
extern ECL_API cl_object ecl_make_semaphore(cl_object name, cl_fixnum count);
extern ECL_API cl_object mp_mailbox_count(cl_object mailbox);
extern ECL_API cl_object mp_mailbox_empty_p(cl_object);
extern ECL_API cl_object mp_mailbox_read(cl_object mailbox);
+extern ECL_API cl_object mp_mailbox_try_read(cl_object mailbox);
extern ECL_API cl_object mp_mailbox_send(cl_object mailbox, cl_object msg);
+extern ECL_API cl_object mp_mailbox_try_send(cl_object mailbox, cl_object msg);
/* threads/atomic.c */