Fixed a few smaller issues.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4224 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+13
-11
@@ -32,7 +32,6 @@
|
|||||||
# define TRACE_BLOCK(x) ;
|
# define TRACE_BLOCK(x) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
struct sem_entry {
|
struct sem_entry {
|
||||||
sem_id id;
|
sem_id id;
|
||||||
int count;
|
int count;
|
||||||
@@ -55,9 +54,6 @@ static spinlock sem_spinlock = 0;
|
|||||||
#define GRAB_SEM_LOCK(s) acquire_spinlock(&(s).lock)
|
#define GRAB_SEM_LOCK(s) acquire_spinlock(&(s).lock)
|
||||||
#define RELEASE_SEM_LOCK(s) release_spinlock(&(s).lock)
|
#define RELEASE_SEM_LOCK(s) release_spinlock(&(s).lock)
|
||||||
|
|
||||||
// used in functions that may put a bunch of threads in the run q at once
|
|
||||||
#define READY_THREAD_CACHE_SIZE 16
|
|
||||||
|
|
||||||
static int remove_thread_from_sem(struct thread *t, struct sem_entry *sem, struct thread_queue *queue, int sem_errcode);
|
static int remove_thread_from_sem(struct thread *t, struct sem_entry *sem, struct thread_queue *queue, int sem_errcode);
|
||||||
|
|
||||||
struct sem_timeout_args {
|
struct sem_timeout_args {
|
||||||
@@ -198,12 +194,16 @@ create_sem_etc(int32 count, const char *name, team_id owner)
|
|||||||
// find the first empty spot
|
// find the first empty spot
|
||||||
for (i = 0; i < MAX_SEMS; i++) {
|
for (i = 0; i < MAX_SEMS; i++) {
|
||||||
if (gSems[i].id == -1) {
|
if (gSems[i].id == -1) {
|
||||||
// make the sem id be a multiple of the slot it's in
|
// adjust the sem ID so that: sem ID % MAX_SEMS == slot
|
||||||
if (i >= gNextSemID % MAX_SEMS)
|
if (i >= gNextSemID % MAX_SEMS)
|
||||||
gNextSemID += i - gNextSemID % MAX_SEMS;
|
gNextSemID += i - gNextSemID % MAX_SEMS;
|
||||||
else
|
else
|
||||||
gNextSemID += MAX_SEMS - (gNextSemID % MAX_SEMS - i);
|
gNextSemID += MAX_SEMS - (gNextSemID % MAX_SEMS - i);
|
||||||
gSems[i].id = gNextSemID++;
|
gSems[i].id = gNextSemID;
|
||||||
|
|
||||||
|
// increment next free sem ID, check for overflow
|
||||||
|
if (++gNextSemID < 0)
|
||||||
|
gNextSemID = 0;
|
||||||
|
|
||||||
// Set the owner while the sem list lock is hold, or else it
|
// Set the owner while the sem list lock is hold, or else it
|
||||||
// might get lost if we have a sem_delete_owned_sems() running
|
// might get lost if we have a sem_delete_owned_sems() running
|
||||||
@@ -394,7 +394,7 @@ acquire_sem_etc(sem_id id, int32 count, uint32 flags, bigtime_t timeout)
|
|||||||
|
|
||||||
if (gSems[slot].count - count < 0 && (flags & B_TIMEOUT) != 0 && timeout <= 0) {
|
if (gSems[slot].count - count < 0 && (flags & B_TIMEOUT) != 0 && timeout <= 0) {
|
||||||
// immediate timeout
|
// immediate timeout
|
||||||
status = B_TIMED_OUT;
|
status = B_WOULD_BLOCK;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,6 +663,7 @@ _get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info, size_t sz
|
|||||||
{
|
{
|
||||||
int state;
|
int state;
|
||||||
int slot;
|
int slot;
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
if (gSemsActive == false)
|
if (gSemsActive == false)
|
||||||
return B_NO_MORE_SEMS;
|
return B_NO_MORE_SEMS;
|
||||||
@@ -677,10 +678,10 @@ _get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info, size_t sz
|
|||||||
slot = 0;
|
slot = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// start at index cookie, but check cookie against MAX_PORTS
|
// start at index cookie, but check cookie against MAX_SEMS
|
||||||
slot = *cookie;
|
slot = *cookie;
|
||||||
if (slot >= MAX_SEMS)
|
if (slot >= MAX_SEMS)
|
||||||
return B_BAD_SEM_ID;
|
return B_BAD_VALUE;
|
||||||
}
|
}
|
||||||
// spinlock
|
// spinlock
|
||||||
state = disable_interrupts();
|
state = disable_interrupts();
|
||||||
@@ -699,6 +700,7 @@ _get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info, size_t sz
|
|||||||
|
|
||||||
RELEASE_SEM_LOCK(gSems[slot]);
|
RELEASE_SEM_LOCK(gSems[slot]);
|
||||||
slot++;
|
slot++;
|
||||||
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
RELEASE_SEM_LOCK(gSems[slot]);
|
RELEASE_SEM_LOCK(gSems[slot]);
|
||||||
@@ -708,8 +710,8 @@ _get_next_sem_info(team_id team, int32 *cookie, struct sem_info *info, size_t sz
|
|||||||
RELEASE_SEM_LIST_LOCK();
|
RELEASE_SEM_LIST_LOCK();
|
||||||
restore_interrupts(state);
|
restore_interrupts(state);
|
||||||
|
|
||||||
if (slot == MAX_SEMS)
|
if (!found)
|
||||||
return B_BAD_SEM_ID;
|
return B_BAD_VALUE;
|
||||||
*cookie = slot;
|
*cookie = slot;
|
||||||
return B_NO_ERROR;
|
return B_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user