コード例 #1
0
static int nbglGetExclusiveSceneAccess(scene_t* scene)
{
    int pid = (int) getpid();
    int oldPID = OPA_cas_int(&scene->attachedLock, 0, pid);
    if (oldPID != 0)
    {
        if (mwProcessIsAlive(oldPID))
        {
            mw_printf("Could not get exclusive access to simulation shared segment "
                      "(Owned by process %d)\n",
                      oldPID);
            return 1;
        }
        else
        {
            mw_printf("Simulation shared segment owned by dead process %d, stealing it\n",
                      oldPID);

            /* Process is dead, steal the lock */
            nbglReleaseSceneLocks(scene);
            return 0;
        }
    }
    else
    {
        OPA_store_int(&scene->attachedPID, 0);
        return 0;
    }
}
コード例 #2
0
ファイル: mutex.c プロジェクト: rafaelhaertel/T1-SO-Mutex
void lock() {
  do {
    if (OPA_cas_int(&flag, 1, 0)) break;
  } while (lockint);
}