From f273b13ddb6c92afd516f79f92447c1106a47238 Mon Sep 17 00:00:00 2001 From: Salvatore Benedetto Date: Sun, 31 Aug 2008 15:59:32 +0000 Subject: [PATCH] * Renamed xsi_ipc_init() to xsi_sem_init() as there will be a xsi_msg_init() for message queue * Removed unnecessary header Vector.h * Removed HasSemaphoreSet method: since there will be an IPC table for each subsystem, if a key exist, it already has a semaphore set associated with it git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27256 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/private/kernel/posix/xsi_semaphore.h | 2 +- src/system/kernel/main.cpp | 2 +- src/system/kernel/posix/xsi_semaphore.cpp | 41 ++++++-------------- 3 files changed, 14 insertions(+), 31 deletions(-) diff --git a/headers/private/kernel/posix/xsi_semaphore.h b/headers/private/kernel/posix/xsi_semaphore.h index 4ffc316178..1a6e66ff52 100644 --- a/headers/private/kernel/posix/xsi_semaphore.h +++ b/headers/private/kernel/posix/xsi_semaphore.h @@ -16,7 +16,7 @@ __BEGIN_DECLS -extern void xsi_ipc_init(); +extern void xsi_sem_init(); extern void xsi_sem_undo(struct team *team); /* user calls */ diff --git a/src/system/kernel/main.cpp b/src/system/kernel/main.cpp index 353a6a8656..6e5ce4d1f1 100644 --- a/src/system/kernel/main.cpp +++ b/src/system/kernel/main.cpp @@ -169,7 +169,7 @@ _start(kernel_args *bootKernelArgs, int currentCPU) arch_platform_init_post_thread(&sKernelArgs); TRACE("init POSIX semaphores\n"); realtime_sem_init(); - xsi_ipc_init(); + xsi_sem_init(); TRACE("init VM threads\n"); vm_init_post_thread(&sKernelArgs); diff --git a/src/system/kernel/posix/xsi_semaphore.cpp b/src/system/kernel/posix/xsi_semaphore.cpp index 6accb88fe9..40e4db1631 100644 --- a/src/system/kernel/posix/xsi_semaphore.cpp +++ b/src/system/kernel/posix/xsi_semaphore.cpp @@ -22,7 +22,6 @@ #include #include #include -#include //#define TRACE_XSI_SEM @@ -581,13 +580,6 @@ public: fSemaphoreSetId = semaphoreSet->ID(); } - bool HasSemaphoreSet() - { - if (fSemaphoreSetId != -1) - return true; - return false; - } - HashTableLink* Link() { return &fLink; @@ -626,7 +618,7 @@ struct IpcHashTableDefinition { }; // Arbitrary limit -#define MAX_XSI_SEMAPHORE 512 +#define MAX_XSI_SEMAPHORE 2048 static OpenHashTable sIpcHashTable; static OpenHashTable sSemaphoreHashTable; @@ -664,18 +656,18 @@ XsiSemaphoreSet::UnsetID() void -xsi_ipc_init() +xsi_sem_init() { // Initialize hash tables status_t status = sIpcHashTable.Init(); if (status != B_OK) - panic("xsi_ipc_init() failed to initialized ipc hash table\n"); + panic("xsi_sem_init() failed to initialize ipc hash table\n"); status = sSemaphoreHashTable.Init(); if (status != B_OK) - panic("xsi_ipc_init() failed to initialized semaphore hash table\n"); + panic("xsi_sem_init() failed to initialize semaphore hash table\n"); - mutex_init(&sIpcLock, "global Posix IPC table"); - mutex_init(&sXsiSemaphoreSetLock, "global Posix xsi sem table"); + mutex_init(&sIpcLock, "global POSIX semaphore IPC table"); + mutex_init(&sXsiSemaphoreSetLock, "global POSIX xsi sem table"); } @@ -738,11 +730,11 @@ _user_xsi_semget(key_t key, int numberOfSemaphores, int flags) MutexLocker _(sIpcLock); if (key != IPC_PRIVATE) { isPrivate = false; - // Check if key already has a semaphore associated with it + // Check if key already exist, if it does it already has a semaphore + // set associated with it ipcKey = sIpcHashTable.Lookup(key); if (ipcKey == NULL) { - // The ipc key have probably just been created - // by the caller, add it to the system + // The ipc key does not exist. Create it and add it to the system if (!(flags & IPC_CREAT)) { TRACE_ERROR(("xsi_semget: key %d does not exist, but the " "caller did not ask for creation\n",(int)key)); @@ -755,7 +747,7 @@ _user_xsi_semget(key_t key, int numberOfSemaphores, int flags) return ENOMEM; } sIpcHashTable.Insert(ipcKey); - } else if (ipcKey->HasSemaphoreSet()) { + } else { // The IPC key exist and it already has a semaphore if ((flags & IPC_CREAT) && (flags & IPC_EXCL)) { TRACE_ERROR(("xsi_semget: key %d already exist\n", (int)key)); @@ -768,27 +760,18 @@ _user_xsi_semget(key_t key, int numberOfSemaphores, int flags) if (!semaphoreSet->HasPermission()) { TRACE_ERROR(("xsi_semget: calling process has not permission " "on semaphore %d, key %d\n", semaphoreSet->ID(), - (int)semaphoreSet->IpcKey())); + (int)key)); return EACCES; } if (numberOfSemaphores > semaphoreSet->NumberOfSemaphores() && numberOfSemaphores != 0) { TRACE_ERROR(("xsi_semget: numberOfSemaphores greater than the " "one associated with semaphore %d, key %d\n", - semaphoreSet->ID(), (int)semaphoreSet->IpcKey())); + semaphoreSet->ID(), (int)key)); return EINVAL; } create = false; - } else { - // The IPC key exist but it has not semaphore associated with it - if (!(flags & IPC_CREAT)) { - TRACE_ERROR(("xsi_semget: key %d has not semaphore associated " - "with it and caller did not ask for creation\n",(int)key)); - return ENOENT; - } } - } else { - // TODO: Handle case of private key } if (create) {