* Introduced new job_control_entry structure which, among other things,

is used instead of death_entry for team::dead_children.
* Added team::{stopped,continued}_children, which, analoguously to
  dead_children, are used to track the state of stopped/continued
  children.
* A team does have a job_control_entry, which is allocated at team
  creation time. It will be inserted into the parent's
  {stopped,continued}_children lists as the team's main thread is
  stopped/continued and removed when waitpid() retrieves the child
  state. When the team dies the entry is detached from the team and goes
  into the parent's dead_children list.
* Removed the wait_for_any field from team_dead_children. It was solely
  used to avoid deletion of the contained entries in certain situations.
  wait_for_child() (the waitpid() backend) always deletes an entry now,
  regardless of whether other threads are waiting; that's in
  accordance with the waidpid() specification. wait_for_thread() removes
  the entry only, if the caller is the parent of the respective team.
* Introduced team_set_job_control_state() which performes the job
  control entry transitions between the respective lists and wakes up
  threads waiting in wait_for_child(). It is invoked on team death and
  when the team's main thread receives job control signals.
* Reorganized wait_for_child(). It handles WCONTINUED and WUNTRACED now,
  too. Removed a block that interpreted the supplied ID as thread ID.
* Added missing parts in waitpid().

Job control starts to work, though it seems to have some glitches.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22088 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2007-08-28 03:29:14 +00:00
parent c9e5503e5e
commit 24bcf55926
5 changed files with 348 additions and 156 deletions
+5 -2
View File
@@ -29,13 +29,16 @@ status_t team_get_address_space(team_id id,
struct vm_address_space **_addressSpace);
char **user_team_get_arguments(void);
int user_team_get_arg_count(void);
status_t team_get_death_entry(struct team *team, thread_id child,
struct death_entry *death, struct death_entry **_freeDeath);
struct job_control_entry* team_get_death_entry(struct team *team,
thread_id child, bool* _deleteEntry);
bool team_is_valid(team_id id);
struct team *team_get_team_struct_locked(team_id id);
int32 team_max_teams(void);
int32 team_used_teams(void);
void team_set_job_control_state(struct team* team, job_control_state newState,
int signal, bool threadsLocked);
status_t start_watching_team(team_id team, void (*hook)(team_id, void *),
void *data);
status_t stop_watching_team(team_id team, void (*hook)(team_id, void *),
+41 -6
View File
@@ -40,8 +40,17 @@ enum team_state {
TEAM_STATE_DEATH // being killed
};
typedef enum job_control_state {
JOB_CONTROL_STATE_NONE,
JOB_CONTROL_STATE_STOPPED,
JOB_CONTROL_STATE_CONTINUED,
JOB_CONTROL_STATE_DEAD
} job_control_state;
#define THREAD_RETURN_EXIT 0x1
#define THREAD_RETURN_INTERRUPTED 0x2
#define THREAD_STOPPED 0x3
#define THREAD_CONTINUED 0x4
struct image;
// defined in image.c
@@ -83,23 +92,44 @@ struct team_watcher {
// this is a soft limit for the number of dead entries in a team
typedef struct team_dead_children team_dead_children;
typedef struct team_job_control_children team_job_control_children;
typedef struct job_control_entry job_control_entry;
#ifdef __cplusplus
#include <condition_variable.h>
#include <util/DoublyLinkedList.h>
struct team_dead_children {
ConditionVariable<team_dead_children> condition_variable;
// wait for dead child entries
struct list list;
struct job_control_entry : DoublyLinkedListLinkImpl<job_control_entry> {
job_control_state state; // current team job control state
thread_id thread; // main thread ID == team ID
// valid while state != JOB_CONTROL_STATE_DEAD
struct team* team;
// valid when state == JOB_CONTROL_STATE_DEAD
pid_t group_id;
status_t status;
uint16 reason;
uint16 signal;
};
typedef DoublyLinkedList<job_control_entry> JobControlEntryList;
struct team_job_control_children {
ConditionVariable<team_job_control_children> condition_variable;
JobControlEntryList entries;
};
struct team_dead_children : team_job_control_children {
uint32 count;
vint32 wait_for_any; // count of wait_for_child() that wait for any
// child
bigtime_t kernel_time;
bigtime_t user_time;
};
#endif // __cplusplus
@@ -120,7 +150,12 @@ struct team {
int pending_signals;
void *io_context;
sem_id death_sem; // semaphore to wait on for dying threads
team_dead_children *dead_children;
team_job_control_children *stopped_children;
team_job_control_children *continued_children;
struct job_control_entry* job_control_entry;
struct vm_address_space *address_space;
struct thread *main_thread;
struct thread *thread_list;