+/** @brief Returns true if acquiring this semaphore would block */
+XBT_INLINE int SIMIX_sem_would_block(smx_sem_t sem)
+{
+ XBT_IN("(%p)",sem);
+ XBT_OUT();
+ return (sem->value <= 0);
+}
+
+/** @brief Returns the current capacity of the semaphore */
+int SIMIX_sem_get_capacity(smx_sem_t sem)
+{
+ XBT_IN("(%p)",sem);
+ XBT_OUT();
+ return sem->value;
+}
+
+static void _SIMIX_sem_wait(smx_sem_t sem, double timeout, smx_process_t issuer,
+ smx_req_t req)
+{
+ XBT_IN("(%p, %f, %p, %p)",sem,timeout,issuer,req);
+ smx_action_t sync_act = NULL;
+
+ XBT_DEBUG("Wait semaphore %p (timeout:%f)", sem, timeout);
+ if (sem->value <= 0) {
+ sync_act = SIMIX_synchro_wait(issuer->smx_host, timeout);
+ xbt_fifo_unshift(sync_act->request_list, req);
+ issuer->waiting_action = sync_act;
+ xbt_swag_insert(issuer, sem->sleeping);
+ } else {
+ sem->value--;
+ SIMIX_request_answer(req);
+ }
+ XBT_OUT();
+}
+
+/**
+ * \brief Handle sem acquire requests without timeouts
+ */
+void SIMIX_pre_sem_acquire(smx_req_t req)
+{
+ XBT_IN("(%p)",req);
+ _SIMIX_sem_wait(req->sem_acquire.sem, -1, req->issuer, req);
+ XBT_OUT();
+}
+
+/**
+ * \brief Handle sem acquire requests with timeouts
+ */
+void SIMIX_pre_sem_acquire_timeout(smx_req_t req)
+{
+ XBT_IN("(%p)",req);
+ _SIMIX_sem_wait(req->sem_acquire_timeout.sem,
+ req->sem_acquire_timeout.timeout, req->issuer, req);
+ XBT_OUT();
+}