Changeset 18622
- Timestamp:
- 08/24/06 18:58:48 (2 years ago)
- Location:
- haiku/trunk
- Files:
-
- 2 modified
-
headers/private/kernel/thread_types.h (modified) (2 diffs)
-
src/system/kernel/team.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
haiku/trunk/headers/private/kernel/thread_types.h
r18543 r18622 58 58 struct process_session { 59 59 pid_t id; 60 struct list groups;60 int32 group_count; 61 61 }; 62 62 63 63 struct process_group { 64 struct list_link link;64 struct process_group *next; // next in hash 65 65 struct process_session *session; 66 66 pid_t id; … … 87 87 88 88 struct team { 89 struct team *next; / * next team in the hash */89 struct team *next; // next in hash 90 90 struct team *siblings_next; 91 91 struct team *parent; -
haiku/trunk/src/system/kernel/team.c
r18621 r18622 64 64 65 65 66 // team list67 66 static void *sTeamHash = NULL; 67 static void *sGroupHash = NULL; 68 68 static struct team *sKernelTeam = NULL; 69 69 … … 83 83 static int team_struct_compare(void *_p, const void *_key); 84 84 static uint32 team_struct_hash(void *_p, const void *_key, uint32 range); 85 static int process_group_compare(void *_p, const void *_key); 86 static uint32 process_group_hash(void *_p, const void *_key, uint32 range); 85 87 static void free_strings_array(char **strings, int32 count); 86 88 static status_t user_copy_strings_array(char * const *strings, int32 count, char ***_strings); … … 176 178 177 179 // create the team hash table 178 sTeamHash = hash_init(1 5, offsetof(struct team, next),180 sTeamHash = hash_init(16, offsetof(struct team, next), 179 181 &team_struct_compare, &team_struct_hash); 182 183 sGroupHash = hash_init(16, offsetof(struct process_group, next), 184 &process_group_compare, &process_group_hash); 180 185 181 186 // create initial session and process groups … … 362 367 363 368 369 static int 370 process_group_compare(void *_group, const void *_key) 371 { 372 struct process_group *group = _group; 373 const struct team_key *key = _key; 374 375 if (group->id == key->id) 376 return 0; 377 378 return 1; 379 } 380 381 382 static uint32 383 process_group_hash(void *_group, const void *_key, uint32 range) 384 { 385 struct process_group *group = _group; 386 const struct team_key *key = _key; 387 388 if (group != NULL) 389 return group->id % range; 390 391 return (uint32)key->id % range; 392 } 393 394 364 395 /** Quick check to see if we have a valid team ID. 365 396 */ … … 390 421 { 391 422 struct team_key key; 392 393 423 key.id = id; 394 424 … … 483 513 484 514 515 /** You must hold the team lock when calling this function. */ 516 485 517 static void 486 518 insert_group_into_session(struct process_session *session, struct process_group *group) … … 490 522 491 523 group->session = session; 492 list_add_link_to_tail(&session->groups, group); 493 } 494 524 hash_insert(sGroupHash, group); 525 session->group_count++; 526 } 527 528 529 /** You must hold the team lock when calling this function. */ 495 530 496 531 static void … … 521 556 return; 522 557 523 list_remove_link(group);558 hash_remove(sGroupHash, group); 524 559 525 560 // we cannot free the resource here, so we're keeping the group link 526 561 // around - this way it'll be freed by free_process_group() 527 if ( !list_is_empty(&session->groups))562 if (--session->group_count > 0) 528 563 group->session = NULL; 529 564 } … … 633 668 634 669 session->id = id; 635 list_init(&session->groups);670 session->group_count = 0; 636 671 637 672 return session; … … 1518 1553 get_process_group_locked(struct team *team, pid_t id) 1519 1554 { 1520 struct list *groups = &team->group->session->groups; 1521 struct process_group *group = NULL; 1522 1523 // ToDo: a process group lasts as long as its last member - and 1524 // that doesn't have to be the process leader. IOW we need 1525 // a separate hash table for those groups without a leader. 1526 1527 // a short cut when the current team's group is asked for 1528 if (team->group->id == id) 1529 return team->group; 1530 1531 while ((group = list_get_next_item(groups, group)) != NULL) { 1532 if (group->id == id) 1533 return group; 1534 } 1555 struct process_group *group; 1556 struct team_key key; 1557 key.id = id; 1558 1559 group = (struct process_group *)hash_lookup(sGroupHash, &key); 1560 if (group != NULL && team->group->session == group->session) 1561 return group; 1535 1562 1536 1563 return NULL; … … 2338 2365 insert_team_into_group(group, team); 2339 2366 } else { 2340 struct process_session *session = team->group->session;2341 struct process_group *group = NULL;2342 2343 2367 // check if this team can have the group ID; there must be one matching 2344 2368 // process ID in the team's session 2345 2369 2346 while ((group = list_get_next_item(&session->groups, group)) != NULL) { 2347 if (group->id == groupID) 2348 break; 2349 } 2350 2370 struct process_group *group = get_process_group_locked(team, groupID); 2351 2371 if (group) { 2352 2372 // we got a group, let's move the team there … … 2362 2382 restore_interrupts(state); 2363 2383 2364 if (status != B_OK && group != NULL) 2384 if (status != B_OK && group != NULL) { 2385 // in case of error, the group hasn't been added into the hash 2365 2386 team_delete_process_group(group); 2387 } 2366 2388 2367 2389 team_delete_process_group(freeGroup);
