コード例 #1
0
ファイル: test_mutex.c プロジェクト: AOSC-Dev/nss-purified
static
void createMutexes(
        PKIX_PL_Mutex **mutex,
        PKIX_PL_Mutex **mutex2,
        PKIX_PL_Mutex **mutex3)
{
        PKIX_TEST_STD_VARS();

        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(mutex, plContext));
        PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(mutex2, plContext));

        *mutex3 = *mutex;
        PKIX_TEST_EXPECT_NO_ERROR
                (PKIX_PL_Object_IncRef((PKIX_PL_Object*)*mutex3, plContext));

cleanup:
        PKIX_TEST_RETURN();
}
コード例 #2
0
/*
 * FUNCTION: PKIX_PL_HashTable_Create (see comments in pkix_pl_system.h)
 */
PKIX_Error *
PKIX_PL_HashTable_Create(
    PKIX_UInt32 numBuckets,
    PKIX_UInt32 maxEntriesPerBucket,
    PKIX_PL_HashTable **pResult,
    void *plContext)
{
    PKIX_PL_HashTable *hashTable = NULL;

    PKIX_ENTER(HASHTABLE, "PKIX_PL_HashTable_Create");
    PKIX_NULLCHECK_ONE(pResult);

    if (numBuckets == 0) {
        PKIX_ERROR(PKIX_NUMBUCKETSEQUALSZERO);
    }

    /* Allocate a new hashtable */
    PKIX_CHECK(PKIX_PL_Object_Alloc
               (PKIX_HASHTABLE_TYPE,
                sizeof (PKIX_PL_HashTable),
                (PKIX_PL_Object **)&hashTable,
                plContext),
               PKIX_COULDNOTCREATEHASHTABLEOBJECT);

    /* Create the underlying primitive hash table type */
    PKIX_CHECK(pkix_pl_PrimHashTable_Create
               (numBuckets, &hashTable->primHash, plContext),
               PKIX_PRIMHASHTABLECREATEFAILED);

    /* Create a lock for this table */
    PKIX_CHECK(PKIX_PL_Mutex_Create(&hashTable->tableLock, plContext),
               PKIX_ERRORCREATINGTABLELOCK);

    hashTable->maxEntriesPerBucket = maxEntriesPerBucket;

    *pResult = hashTable;

cleanup:

    if (PKIX_ERROR_RECEIVED) {
        PKIX_DECREF(hashTable);
    }

    PKIX_RETURN(HASHTABLE);
}
コード例 #3
0
ファイル: test_mutex2.c プロジェクト: MichaelKohler/gecko-dev
int
test_mutex2(int argc, char *argv[])
{

    PRThread *consThread, *prodThread, *prodThread2, *prodThread3;
    int x = 10, y = 20, z = 30;
    PKIX_UInt32 actualMinorVersion;
    PKIX_UInt32 j = 0;

    PKIX_TEST_STD_VARS();

    startTests("Mutex and Threads");

    PKIX_TEST_EXPECT_NO_ERROR(
        PKIX_PL_NssContext_Create(0, PKIX_FALSE, NULL, &plContext));

    (void)printf("Attempting to create new mutex...\n");
    subTest("Mutex Creation");
    PKIX_TEST_EXPECT_NO_ERROR(PKIX_PL_Mutex_Create(&mutex, plContext));

    cv = PR_NewCondVar(*(PRLock **)mutex);

    subTest("Starting consumer thread");
    consThread = PR_CreateThread(PR_USER_THREAD,
                                 consumer,
                                 NULL,
                                 PR_PRIORITY_NORMAL,
                                 PR_LOCAL_THREAD,
                                 PR_JOINABLE_THREAD,
                                 0);

    subTest("Starting producer thread 1");
    prodThread = PR_CreateThread(PR_USER_THREAD,
                                 producer,
                                 &x,
                                 PR_PRIORITY_NORMAL,
                                 PR_LOCAL_THREAD,
                                 PR_JOINABLE_THREAD,
                                 0);

    subTest("Starting producer thread 2");
    prodThread2 = PR_CreateThread(PR_USER_THREAD,
                                  producer,
                                  &y,
                                  PR_PRIORITY_NORMAL,
                                  PR_LOCAL_THREAD,
                                  PR_JOINABLE_THREAD,
                                  0);

    subTest("Starting producer thread 3");
    prodThread3 = PR_CreateThread(PR_USER_THREAD,
                                  producer,
                                  &z,
                                  PR_PRIORITY_NORMAL,
                                  PR_LOCAL_THREAD,
                                  PR_JOINABLE_THREAD,
                                  0);

    PR_JoinThread(consThread);

    (void)PR_DestroyCondVar(cv);
    PKIX_TEST_DECREF_BC(mutex);

    /*
         * Note: we should also be freeing each thread's stack, but we
         * don't have access to the prodThread->stack variable (since
         * it is not exported). As a result, we have 120 bytes of memory
         * leakage.
         */

    PR_Free(prodThread);
    PR_Free(prodThread2);
    PR_Free(prodThread3);

cleanup:

    PKIX_Shutdown(plContext);

    PKIX_TEST_RETURN();

    endTests("Mutex and Threads");

    return (0);
}