summaryrefslogtreecommitdiff
path: root/lib/libthr/thread/thr_mutex.c
Commit message (Collapse)AuthorAgeFilesLines
* MFC:David Xu2006-01-161-6/+11
| | | | | | | Sync with HEAD. Notes: svn path=/stable/6/; revision=154423
* MFC revision 1.35:David Xu2005-12-151-2/+0
| | | | | | | Remove unused _get_curthread() call. Notes: svn path=/stable/6/; revision=153444
* Import my recent 1:1 threading working. some features improved includes:David Xu2005-04-021-589/+1385
| | | | | | | | | | | | | | | | | | | 1. fast simple type mutex. 2. __thread tls works. 3. asynchronous cancellation works ( using signal ). 4. thread synchronization is fully based on umtx, mainly, condition variable and other synchronization objects were rewritten by using umtx directly. those objects can be shared between processes via shared memory, it has to change ABI which does not happen yet. 5. default stack size is increased to 1M on 32 bits platform, 2M for 64 bits platform. As the result, some mysql super-smack benchmarks show performance is improved massivly. Okayed by: jeff, mtm, rwatson, scottl Notes: svn path=/head/; revision=144518
* Remove vestiges of libthr's signal mangling past. This fixes that lastMike Makonnen2004-09-221-14/+1
| | | | | | | known problem with mysql on libthr: not being able to kill mysqld. Notes: svn path=/head/; revision=135579
* The SUSv3 function say that the affected functions MAY FAIL, if theMike Makonnen2004-09-221-27/+6
| | | | | | | | | | | | | | | specified mutex is invalid. In spec parlance 'MAY FAIL' means it's up to the implementor. So, remove the check for NULL pointers for two reasons: 1. A mutex may be invalid without necessarily being NULL. 2. If the pointer to the mutex is NULL core-dumping in the vicinity of the problem is much much much better than failing in some other part of the code (especially when the application doesn't check the return value of the function that you oh so helpfully set to EINVAL). Notes: svn path=/head/; revision=135575
* o Assertions to catch that stuff that shouldn't happen is not happening.Mike Makonnen2004-07-301-0/+2
| | | | | | | | | | | | | o In the rwlock code: move a duplicated check inside an if..else to after the if...else clause. o When initializing a static rwlock move the initialization check inside the lock. o In thr_setschedparam.c: When breaking out of the trylock...retry if busy loop make sure to reset the mtx pointer to null if the mutex is nolonger in a queue. Notes: svn path=/head/; revision=132890
* Change the thread ID (thr_id_t) used for 1:1 threading from being aMarcel Moolenaar2004-07-021-4/+4
| | | | | | | | | | | | | | | | | | | | | | | pointer to the corresponding struct thread to the thread ID (lwpid_t) assigned to that thread. The primary reason for this change is that libthr now internally uses the same ID as the debugger and the kernel when referencing to a kernel thread. This allows us to implement the support for debugging without additional translations and/or mappings. To preserve the ABI, the 1:1 threading syscalls, including the umtx locking API have not been changed to work on a lwpid_t. Instead the 1:1 threading syscalls operate on long and the umtx locking API has not been changed except for the contested bit. Previously this was the least significant bit. Now it's the most significant bit. Since the contested bit should not be tested by userland, this change is not expected to be visible. Just to be sure, UMTX_CONTESTED has been removed from <sys/umtx.h>. Reviewed by: mtm@ ABI preservation tested on: i386, ia64 Notes: svn path=/head/; revision=131431
* Make libthr async-signal-safe without costly signal masking. The guidlines IMike Makonnen2004-05-201-42/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | followed are: Only 3 functions (pthread_cancel, pthread_setcancelstate, pthread_setcanceltype) are required to be async-signal-safe by POSIX. None of the rest of the pthread api is required to be async-signal-safe. This means that only the three mentioned functions are safe to use from inside signal handlers. However, there are certain system/libc calls that are cancellation points that a caller may call from within a signal handler, and since they are cancellation points calls have to be made into libthr to test for cancellation and exit the thread if necessary. So, the cancellation test and thread exit code paths must be async-signal-safe as well. A summary of the changes follows: o Almost all of the code paths that masked signals, as well as locking the pthread structure now lock only the pthread structure. o Signals are masked (and left that way) as soon as a thread enters pthread_exit(). o The active and dead threads locks now explicitly require that signals are masked. o Access to the isdead field of the pthread structure is protected by both the active and dead list locks for writing. Either one is sufficient for reading. o The thread state and type fields have been combined into one three-state switch to make it easier to read without requiring a lock. It doesn't need a lock for writing (and therefore for reading either) because only the current thread can write to it and it is an integer value. o The thread state field of the pthread structure has been eliminated. It was an unnecessary field that mostly duplicated the flags field, but required additional locking that would make a lot more code paths require signal masking. Any truly unique values (such as PS_DEAD) have been reborn as separate members of the pthread structure. o Since the mutex and condvar pthread functions are not async-signal-safe there is no need to muck about with the wait queues when handling a signal ... o ... which also removes the need for wrapping signal handlers and sigaction(2). o The condvar and mutex async-cancellation code had to be revised as a result of some of these changes, which resulted in semi-unrelated changes which would have been difficult to work on as a separate commit, so they are included as well. The only part of the changes I am worried about is related to locking for the pthread joining fields. But, I will take a closer look at them once this mega-patch is committed. Notes: svn path=/head/; revision=129484
* q§Mike Makonnen2004-05-201-7/+5
| | | | Notes: svn path=/head/; revision=129482
* The thread suspend function now returns ETIMEDOUT, not EAGAIN.Mike Makonnen2004-03-291-1/+1
| | | | Notes: svn path=/head/; revision=127561
* Stop using signals for synchronizing threads. The performance penaltyMike Makonnen2004-03-271-1/+1
| | | | | | | was too much. Notes: svn path=/head/; revision=127485
* o The mutex locking functions aren't normally cancellation points. But,Mike Makonnen2004-03-261-3/+12
| | | | | | | | | | we still have to DTRT when an asynchronously cancellable thread is cancelled while waiting for a mutex. o While dequeueing a waiting mutex don't skip a thread if it has a cancel pending. Only skip it if it is also async cancellable. Notes: svn path=/head/; revision=127454
* o Refactor and, among other things, get rid of insane nesting levels.Mike Makonnen2004-02-181-810/+300
| | | | | | | | | | o Fix mutex priority protocols. Keep separate counts of priority inheritance and protection mutexes to make things easier. This will not have much affect since this is only the userland side, and the rest involves kernel scheduling. Notes: svn path=/head/; revision=125966
* Refactor _pthread_mutex_initMike Makonnen2004-01-191-125/+64
| | | | | | | | | | | | | | | o Simplify the logic by removing a lot of unnecesary nesting o Reduce the amount of local variables o Zero-out the allocated structure and get rid of all the unnecessary setting to 0 and NULL; Refactor _pthread_mutex_destroy o Simplify the logic by removing a lot of unnecesary nesting o No need to check pointer that the mutex attributes points to. Checking passed in pointer is enough. Notes: svn path=/head/; revision=124719
* o Implement pthread_mutex_timedlock(), which does not block indefinitely onMike Makonnen2003-12-301-0/+32
| | | | | | | | a mutex locked by another thread. o document it: pthread_mutex_timedlock(3) Notes: svn path=/head/; revision=123987
* Make it possible for the library to specify a timeout value whenMike Makonnen2003-12-301-20/+47
| | | | | | | | | | | | | waiting on a locked mutex. This involves passing a struct timespec from the pthread mutex locking interfaces all the way down to the function that suspends the thread until the mutex is released. The timeout is assumed to be an absolute time (i.e. not relative to the current time). Also, in _thread_suspend() make the passed in timespec const. Notes: svn path=/head/; revision=123986
* Fix the wrapper function around signals so that a signal handlingMike Makonnen2003-12-091-25/+1
| | | | | | | | thread on one of the mutex or condition variable queues is removed from those queues before the real signal handler is called. Notes: svn path=/head/; revision=123350
* Change all instances of THR_LOCK/UNLOCK, etc to UMTX_*.Mike Makonnen2003-07-061-2/+2
| | | | | | | | It is a more acurate description of the locks they operate on. Notes: svn path=/head/; revision=117277
* _pthread_mutex_trylock() is another internal libc function that must blockMike Makonnen2003-07-031-0/+8
| | | | | | | signals. Notes: svn path=/head/; revision=117196
* Begin making libthr async signal safe.Mike Makonnen2003-07-021-2/+22
| | | | | | | | | | | Create a private, single underscore, version of pthread_mutex_unlock for libc. pthread_mutex_lock already has one. These versions are different from the ones that applications will link against because they block all signals from the time a call to lock the mutex is made until it is successfully unlocked. Notes: svn path=/head/; revision=117145
* Do not attempt to reque a thread on a mutex queue. It may be thatMike Makonnen2003-07-011-1/+1
| | | | | | | | | | | | a thread receives a spurious wakeup from sigtimedwait(), so make sure that the call to the queueing code is called only once before entering the loop (not in the loop). This should fix some fatal errors people are seeing with messages stating the thread is already on the mutex queue. These errors may still be triggered from signal handlers; however, since that part of the code is not locked down yet. Notes: svn path=/head/; revision=117127
* Catchup with _thread_suspend() changes.Mike Makonnen2003-06-301-1/+5
| | | | Notes: svn path=/head/; revision=117073
* Sweep through pthread locking and use the new locking primitives forMike Makonnen2003-06-291-2/+2
| | | | | | | libthr. Notes: svn path=/head/; revision=117049
* Consolidate static_init() and static_init_private into one function.Mike Makonnen2003-06-021-17/+11
| | | | | | | The behaviour of this function is controlled by the argument: private. Notes: svn path=/head/; revision=115692
* I botched one of my committs in the last round. Fix it.Mike Makonnen2003-05-311-10/+8
| | | | Notes: svn path=/head/; revision=115442
* Make the mutex static initializers look more like the one forMike Makonnen2003-05-291-25/+19
| | | | | | | | | | | | condition variables. Cosmetic. Explicitly compare against PTHREAD_MUTEX_INITIALIZER. We shouldn't encourage calls to the mutex functions with null pointers to mutexes. Approved by: re/jhb Notes: svn path=/head/; revision=115390
* Make WARNS2 clean. The fixes mostly included:Mike Makonnen2003-05-231-2/+4
| | | | | | | | | | | o removed unused variables o explicit inclusion of header files o prototypes for externally defined functions Approved by: re/blanket libthr Notes: svn path=/head/; revision=115260
* Insert a debugging aid:Mike Makonnen2003-05-211-1/+9
| | | | | | | | | | | When in either the mutex or cond queue we notice that the thread is already on one of the queues, don't just simply abort(). Print out the thread's identifiers and what queue it was on. Approved by: markm/mentor, re/blanket libthr Notes: svn path=/head/; revision=115198
* msg1Mike Makonnen2003-05-121-263/+129
| | | | Notes: svn path=/head/; revision=114938
* o Correct a debug message that refered to the wrong functionMike Makonnen2003-05-061-1/+1
| | | | | | | | | | o Remove an unncecesary if clause Approved by: markm (mentor)(implicit) Reviewd by: jeff Notes: svn path=/head/; revision=114772
* - Define curthread as _get_curthread() and remove all direct calls toJeff Roberson2003-04-021-8/+5
| | | | | | | | | | _get_curthread(). This is similar to the kernel's curthread. Doing this saves stack overhead and is more convenient to the programmer. - Pass the pointer to the newly created thread to _thread_init(). - Remove _get_curthread_slow(). Notes: svn path=/head/; revision=112965
* - Restore old mutex code from libc_r. It is more standards compliant.Jeff Roberson2003-04-011-199/+1328
| | | | | | | | | | This was changed because originally we were blocking on the umtx and allowing the kernel to do the queueing. It was decided that the lib should queue and start the threads in the order it decides and the umtx code would just be used like spinlocks. Notes: svn path=/head/; revision=112958
* - Add libthr but don't hook it up to the regular build yet. This is anJeff Roberson2003-04-011-0/+432
adaptation of libc_r for the thr system call interface. This is beta quality code. Notes: svn path=/head/; revision=112918