Lines Matching refs:thread

17 #include <arch/thread.h>
18 // For the thread blocking inline functions only.
30 // thread notifications
43 Thread* thread;
47 // used as thread stack
50 arch_fork_arg* forkArgs; // If non-NULL, the userland thread
60 team_id team = -1, Thread* thread = NULL);
82 // called when the thread enters the kernel on behalf of the thread
92 void thread_map(void (*function)(Thread* thread, void* data), void* data);
97 const char* thread_state_to_text(Thread* thread, int32 state);
108 Thread *thread = thread_get_current_thread();
109 return thread ? thread->id : 0;
113 thread_is_idle_thread(Thread *thread)
115 return thread->priority == B_IDLE_PRIORITY;
121 status_t thread_enter_userspace_new_team(Thread* thread, addr_t entryFunction,
123 status_t thread_create_user_stack(Team* team, Thread* thread, void* stackBase,
138 void thread_unblock(Thread* thread, status_t status);
141 status_t _user_set_thread_priority(thread_id thread, int32 newPriority);
142 status_t _user_rename_thread(thread_id thread, const char *name);
143 status_t _user_suspend_thread(thread_id thread);
144 status_t _user_resume_thread(thread_id thread);
145 status_t _user_rename_thread(thread_id thread, const char *name);
152 status_t _user_kill_thread(thread_id thread);
156 bool _user_has_data(thread_id thread);
157 status_t _user_send_data(thread_id thread, int32 code, const void *buffer, size_t buffer_size);
165 status_t _user_unblock_thread(thread_id thread, status_t status);
179 /*! Checks whether the current thread would immediately be interrupted when
184 \param thread The current thread.
186 - \c B_CAN_INTERRUPT: The thread can be interrupted by any non-blocked
188 - \c B_KILL_CAN_INTERRUPT: The thread can be interrupted by a kill
190 \return \c true, if the thread would be interrupted, \c false otherwise.
193 thread_is_interrupted(Thread* thread, uint32 flags)
195 sigset_t pendingSignals = thread->AllPendingSignals();
197 && (pendingSignals & ~thread->sig_block_mask) != 0)
203 /*! Checks whether the given thread is currently blocked (i.e. still waiting
211 \param thread The thread in question.
212 \return \c true, if the thread is blocked, \c false otherwise.
215 thread_is_blocked(Thread* thread)
217 return atomic_get(&thread->wait.status) == 1;
221 /*! Prepares the current thread for waiting.
223 This is the first of two steps necessary to block the current thread
228 Usually the thread waits for some condition to change and this condition is
238 and the function that actually blocks the thread shall be invoked
240 two steps no functionality that uses the thread blocking API for this thread
243 When the caller determines that the condition for unblocking the thread
244 occurred, it calls thread_unblock_locked() to unblock the thread. At that
251 someone calls thread_interrupt() that is supposed to wake up the thread.
259 Blocking thread:
262 - Modify some client data structure to indicate that this thread is now
270 another thread concurrently changed the client condition and also tried
271 to unblock the waiting thread. It is even necessary when that other
272 thread changed the client data structures in a way that associate some
273 resource with the unblocked thread, or otherwise the unblocked thread
276 thread -- modify some client structure to indicate that the thread is no
279 Unblocking thread:
281 - Check client condition and decide whether a blocked thread can be woken
284 are waiting and which thread(s) need(s) to be woken up.
285 - Unblock respective thread(s).
286 - Possibly change some client structure, so that an unblocked thread can
290 Note that in the blocking thread the steps after blocking are strictly
292 the blocking thread can only be woken up explicitly by an unblocking thread,
294 modifications, so that the blocking thread wouldn't have to do that.
297 A mutex, a semaphore, or anything that doesn't try to use the thread
298 blocking API for the calling thread when releasing the lock is fine.
303 especially with a client lock that uses the thread blocking API. After a
304 blocked thread has been interrupted or the the time out occurred it cannot
305 acquire the client lock (or any other lock using the thread blocking API)
306 without first making sure that the thread doesn't still appear to be
307 waiting to other client code. Otherwise another thread could try to unblock
308 it which could erroneously unblock the thread while already waiting on the
312 \param thread The current thread.
314 - \c B_CAN_INTERRUPT: The thread can be interrupted by any non-blocked
316 - \c B_KILL_CAN_INTERRUPT: The thread can be interrupted by a kill
318 \param type The type of object the thread will be blocked at. Informative/
322 \param object The object the thread will be blocked at. Informative/for
326 thread_prepare_to_block(Thread* thread, uint32 flags, uint32 type,
329 thread->wait.flags = flags;
330 thread->wait.type = type;
331 thread->wait.object = object;
332 atomic_set(&thread->wait.status, 1);
334 // when a thread is waiting.
338 /*! Unblocks the specified blocked thread.
340 If the thread is no longer waiting (e.g. because thread_unblock_locked() has
347 \param thread The thread to be unblocked.
348 \param status The unblocking status. That's what the unblocked thread's
352 thread_unblock_locked(Thread* thread, status_t status)
354 if (atomic_test_and_set(&thread->wait.status, status, 1) != 1)
357 // wake up the thread, if it is sleeping
358 if (thread->state == B_THREAD_WAITING)
359 scheduler_enqueue_in_run_queue(thread);
363 /*! Interrupts the specified blocked thread, if possible.
365 The function checks whether the thread can be interrupted and, if so, calls
366 \code thread_unblock_locked(thread, B_INTERRUPTED) \endcode. Otherwise the
375 \param thread The thread to be interrupted.
376 \param kill If \c false, the blocked thread is only interrupted, when the
377 flag \c B_CAN_INTERRUPT was specified for the blocked thread. If
380 blocked thread.
381 \return \c B_OK, if the thread is interruptible and thread_unblock_locked()
383 thread actually has been interrupted -- it could have been unblocked
387 thread_interrupt(Thread* thread, bool kill)
389 if (thread_is_blocked(thread)) {
390 if ((thread->wait.flags & B_CAN_INTERRUPT) != 0
391 || (kill && (thread->wait.flags & B_KILL_CAN_INTERRUPT) != 0)) {
392 thread_unblock_locked(thread, B_INTERRUPTED);
402 thread_pin_to_current_cpu(Thread* thread)
404 thread->pinned_to_cpu++;
409 thread_unpin_from_current_cpu(Thread* thread)
411 thread->pinned_to_cpu--;
418 Thread* thread = thread_get_current_thread();
419 thread->going_to_suspend = true;
426 Thread* thread = thread_get_current_thread();
431 acquire_spinlock(&thread->scheduler_lock);
433 if (thread->going_to_suspend)
436 release_spinlock(&thread->scheduler_lock);
442 thread_continue(Thread* thread)
444 thread->going_to_suspend = false;
447 acquire_spinlock(&thread->scheduler_lock);
449 if (thread->state == B_THREAD_SUSPENDED)
450 scheduler_enqueue_in_run_queue(thread);
452 release_spinlock(&thread->scheduler_lock);