Mercurial > cpython-lru_cache-weakref
view Python/thread_sgi.h @ 45852:30c4e1ca8421
Merged revisions 61431,61433-61436,61439,61444,61449-61450,61453,61458,61465,61468,61471-61474,61480,61483-61484,61488,61495-61496,61498,61503-61504,61507,61509-61510,61515-61518 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r61431 | vinay.sajip | 2008-03-16 22:35:58 +0100 (So, 16 Mär 2008) | 1 line
Clarified documentation on use of shutdown().
........
r61433 | mark.summerfield | 2008-03-17 09:28:15 +0100 (Mo, 17 Mär 2008) | 5 lines
Added a footnote to each pointing out that for XML output if an encoding
string is given it should conform to the appropriate XML standards---for
example, "UTF-8" is okay, but "UTF8" is not.
........
r61434 | eric.smith | 2008-03-17 12:01:01 +0100 (Mo, 17 Mär 2008) | 7 lines
Issue 2264: empty float presentation type needs to have at least one digit past the decimal point.
Added "Z" format_char to PyOS_ascii_formatd to support empty float presentation type.
Renamed buf_size in PyOS_ascii_formatd to more accurately reflect it's meaning.
Modified format.__float__ to use the new "Z" format as the default.
Added test cases.
........
r61435 | eric.smith | 2008-03-17 13:14:29 +0100 (Mo, 17 Mär 2008) | 2 lines
Reformated lines > 79 chars.
Deleted unused macro ISXDIGIT.
........
r61436 | jeffrey.yasskin | 2008-03-17 15:40:53 +0100 (Mo, 17 Mär 2008) | 13 lines
Allow Gnu gcc's to build python on OSX by removing -Wno-long-double,
-no-cpp-precomp, and -mno-fused-madd from configure.
* r22183 added -no-cpp-precomp, which
http://gcc.gnu.org/ml/gcc/2005-12/msg00368.html claims hasn't been
needed since gcc-3.1.
* r25607 added -Wno-long-double to avoid a warning in
Include/objimpl.h (issue 525481). The long double is still there,
but OSX 10.4's gcc no longer warns about it.
* r33666 fixed issue 775892 on OSX 10.3 by adding -mno-fused-madd,
which changed the sign of some float 0s. Tim Peters said it wasn't
a real issue anyway, and it no longer causes test failures.
Fixes issue #1779871.
........
r61439 | martin.v.loewis | 2008-03-17 17:31:57 +0100 (Mo, 17 Mär 2008) | 2 lines
Add Trent Nelson.
........
r61444 | travis.oliphant | 2008-03-17 18:36:12 +0100 (Mo, 17 Mär 2008) | 1 line
Add necessary headers to back-port new buffer protocol to Python 2.6
........
r61449 | gregory.p.smith | 2008-03-17 19:48:05 +0100 (Mo, 17 Mär 2008) | 8 lines
Force zlib.crc32 and zlib.adler32 to return a signed integer on all platforms
regardless of the native sizeof(long) used in the integer object.
This somewhat odd behavior of returning a signed is maintained in 2.x for
compatibility reasons of always returning an integer rather than a long object.
Fixes Issue1202 for Python 2.6
........
r61450 | neal.norwitz | 2008-03-17 20:02:45 +0100 (Mo, 17 Mär 2008) | 3 lines
Use a buffer large enough to ensure we don't overrun, even if the value
is outside the range we expect.
........
r61453 | steven.bethard | 2008-03-17 20:33:11 +0100 (Mo, 17 Mär 2008) | 1 line
Document unicode.isnumeric() and unicode.isdecimal() (issue2326)
........
r61458 | neal.norwitz | 2008-03-17 21:22:43 +0100 (Mo, 17 Mär 2008) | 5 lines
Issue 2321: reduce memory usage (increase the memory that is returned
to the system) by using pymalloc for the data of unicode objects.
Will backport.
........
r61465 | martin.v.loewis | 2008-03-17 22:55:30 +0100 (Mo, 17 Mär 2008) | 2 lines
Add David Wolever.
........
r61468 | gregory.p.smith | 2008-03-18 01:20:01 +0100 (Di, 18 Mär 2008) | 3 lines
Fix the IOError message text when opening a file with an invalid filename.
Error reported by Ilan Schnell.
........
r61471 | brett.cannon | 2008-03-18 02:00:07 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_strftime, test_getargs, and test_pep247 to use unittest.
........
r61472 | jeffrey.yasskin | 2008-03-18 02:09:59 +0100 (Di, 18 Mär 2008) | 2 lines
Fix build on platforms that don't have intptr_t. Patch by Joseph Armbruster.
........
r61473 | brett.cannon | 2008-03-18 02:50:25 +0100 (Di, 18 Mär 2008) | 2 lines
Convert test_dummy_threading and test_dbm to unittest.
........
r61474 | brett.cannon | 2008-03-18 02:58:56 +0100 (Di, 18 Mär 2008) | 2 lines
Move test_extcall to doctest.
........
r61480 | brett.cannon | 2008-03-18 04:46:22 +0100 (Di, 18 Mär 2008) | 2 lines
test_errno was a no-op test; now it actually tests things and uses unittest.
........
r61483 | brett.cannon | 2008-03-18 05:09:00 +0100 (Di, 18 Mär 2008) | 3 lines
Remove our implementation of memmove() and strerror(); both are in the C89
standard library.
........
r61484 | brett.cannon | 2008-03-18 05:16:06 +0100 (Di, 18 Mär 2008) | 2 lines
The output directory for tests that compare against stdout is now gone!
........
r61488 | jeffrey.yasskin | 2008-03-18 05:29:35 +0100 (Di, 18 Mär 2008) | 2 lines
Block the "socket.ssl() is deprecated" warning from test_socket_ssl.
........
r61495 | jeffrey.yasskin | 2008-03-18 05:56:06 +0100 (Di, 18 Mär 2008) | 4 lines
Speed test_thread up from 51.328s to 0.081s by reducing its sleep times. We
still sleep at all to make it likely that all threads are active at the same
time.
........
r61496 | jeffrey.yasskin | 2008-03-18 06:12:41 +0100 (Di, 18 Mär 2008) | 4 lines
Speed up test_dict by about 10x by only checking selected dict literal sizes,
instead of every integer from 0 to 400. Exhaustive testing wastes time without
providing enough more assurance that the code is correct.
........
r61498 | neal.norwitz | 2008-03-18 06:20:29 +0100 (Di, 18 Mär 2008) | 1 line
Try increasing the timeout to reduce the flakiness of this test.
........
r61503 | brett.cannon | 2008-03-18 06:43:04 +0100 (Di, 18 Mär 2008) | 2 lines
Improve the error message for a test that failed on the S-390 Debian buildbot.
........
r61504 | jeffrey.yasskin | 2008-03-18 06:45:40 +0100 (Di, 18 Mär 2008) | 3 lines
Add a -S/--slow flag to regrtest to have it print the 10 slowest tests with
their times.
........
r61507 | neal.norwitz | 2008-03-18 07:03:46 +0100 (Di, 18 Mär 2008) | 1 line
Add some info to the failure messages
........
r61509 | trent.nelson | 2008-03-18 08:02:12 +0100 (Di, 18 Mär 2008) | 1 line
Issue 2286: bump up the stack size of the 64-bit debug python_d.exe to 2100000. The default value of 200000 causes a stack overflow at 1965 iterations of r_object() in marshal.c, 35 iterations before the 2000 limit enforced by MAX_MARSHAL_STACK_DEPTH.
........
r61510 | trent.nelson | 2008-03-18 08:32:47 +0100 (Di, 18 Mär 2008) | 5 lines
The behaviour of winsound.Beep() seems to differ between different versions of Windows when there's either:
a) no sound card entirely
b) legacy beep driver has been disabled
c) the legacy beep driver has been uninstalled
Sometimes RuntimeErrors are raised, sometimes they're not. If _have_soundcard() returns False, don't expect winsound.Beep() to raise a RuntimeError, as this clearly isn't the case, as demonstrated by the various Win32 XP buildbots.
........
r61515 | martin.v.loewis | 2008-03-18 13:20:15 +0100 (Di, 18 Mär 2008) | 2 lines
norwitz-amd64 (gentoo) has EREMOTEIO.
........
r61516 | martin.v.loewis | 2008-03-18 13:45:37 +0100 (Di, 18 Mär 2008) | 2 lines
Add more Linux error codes.
........
r61517 | martin.v.loewis | 2008-03-18 14:05:03 +0100 (Di, 18 Mär 2008) | 2 lines
Add WSA errors.
........
r61518 | martin.v.loewis | 2008-03-18 14:16:05 +0100 (Di, 18 Mär 2008) | 2 lines
Note that the stderr output of the test is intentional.
........
| author | Christian Heimes <christian@cheimes.de> |
|---|---|
| date | Tue, 18 Mar 2008 15:15:01 +0000 |
| parents | e20fc1b80205 |
| children | e38335d4df91 df5719c298db |
line wrap: on
line source
#include <stdlib.h> #include <stdio.h> #include <signal.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/prctl.h> #include <ulocks.h> #include <errno.h> #define HDR_SIZE 2680 /* sizeof(ushdr_t) */ #define MAXPROC 100 /* max # of threads that can be started */ static usptr_t *shared_arena; static ulock_t count_lock; /* protection for some variables */ static ulock_t wait_lock; /* lock used to wait for other threads */ static int waiting_for_threads; /* protected by count_lock */ static int nthreads; /* protected by count_lock */ static int exit_status; #ifndef NO_EXIT_PROG static int do_exit; /* indicates that the program is to exit */ #endif static int exiting; /* we're already exiting (for maybe_exit) */ static pid_t my_pid; /* PID of main thread */ static struct pidlist { pid_t parent; pid_t child; } pidlist[MAXPROC]; /* PIDs of other threads; protected by count_lock */ static int maxpidindex; /* # of PIDs in pidlist */ #ifndef NO_EXIT_PROG /* * This routine is called as a signal handler when another thread * exits. When that happens, we must see whether we have to exit as * well (because of an PyThread_exit_prog()) or whether we should continue on. */ static void exit_sig(void) { d2printf(("exit_sig called\n")); if (exiting && getpid() == my_pid) { d2printf(("already exiting\n")); return; } if (do_exit) { d2printf(("exiting in exit_sig\n")); #ifdef Py_DEBUG if ((thread_debug & 8) == 0) thread_debug &= ~1; /* don't produce debug messages */ #endif PyThread_exit_thread(); } } /* * This routine is called when a process calls exit(). If that wasn't * done from the library, we do as if an PyThread_exit_prog() was intended. */ static void maybe_exit(void) { dprintf(("maybe_exit called\n")); if (exiting) { dprintf(("already exiting\n")); return; } PyThread_exit_prog(0); } #endif /* NO_EXIT_PROG */ /* * Initialization. */ static void PyThread__init_thread(void) { #ifndef NO_EXIT_PROG struct sigaction s; #endif /* NO_EXIT_PROG */ #ifdef USE_DL long addr, size; #endif /* USE_DL */ #ifdef USE_DL if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0) perror("usconfig - CONF_INITSIZE (check)"); if (usconfig(CONF_INITSIZE, size) < 0) perror("usconfig - CONF_INITSIZE (reset)"); addr = (long) dl_getrange(size + HDR_SIZE); dprintf(("trying to use addr %p-%p for shared arena\n", addr, addr+size)); errno = 0; if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0) perror("usconfig - CONF_ATTACHADDR (set)"); #endif /* USE_DL */ if (usconfig(CONF_INITUSERS, 16) < 0) perror("usconfig - CONF_INITUSERS"); my_pid = getpid(); /* so that we know which is the main thread */ #ifndef NO_EXIT_PROG atexit(maybe_exit); s.sa_handler = exit_sig; sigemptyset(&s.sa_mask); /*sigaddset(&s.sa_mask, SIGUSR1);*/ s.sa_flags = 0; sigaction(SIGUSR1, &s, 0); if (prctl(PR_SETEXITSIG, SIGUSR1) < 0) perror("prctl - PR_SETEXITSIG"); #endif /* NO_EXIT_PROG */ if (usconfig(CONF_ARENATYPE, US_SHAREDONLY) < 0) perror("usconfig - CONF_ARENATYPE"); usconfig(CONF_LOCKTYPE, US_DEBUG); /* XXX */ #ifdef Py_DEBUG if (thread_debug & 4) usconfig(CONF_LOCKTYPE, US_DEBUGPLUS); else if (thread_debug & 2) usconfig(CONF_LOCKTYPE, US_DEBUG); #endif /* Py_DEBUG */ if ((shared_arena = usinit(tmpnam(0))) == 0) perror("usinit"); #ifdef USE_DL if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */ perror("usconfig - CONF_ATTACHADDR (reset)"); #endif /* USE_DL */ if ((count_lock = usnewlock(shared_arena)) == NULL) perror("usnewlock (count_lock)"); (void) usinitlock(count_lock); if ((wait_lock = usnewlock(shared_arena)) == NULL) perror("usnewlock (wait_lock)"); dprintf(("arena start: %p, arena size: %ld\n", shared_arena, (long) usconfig(CONF_GETSIZE, shared_arena))); } /* * Thread support. */ static void clean_threads(void) { int i, j; pid_t mypid, pid; /* clean up any exited threads */ mypid = getpid(); i = 0; while (i < maxpidindex) { if (pidlist[i].parent == mypid && (pid = pidlist[i].child) > 0) { pid = waitpid(pid, 0, WNOHANG); if (pid > 0) { /* a thread has exited */ pidlist[i] = pidlist[--maxpidindex]; /* remove references to children of dead proc */ for (j = 0; j < maxpidindex; j++) if (pidlist[j].parent == pid) pidlist[j].child = -1; continue; /* don't increment i */ } } i++; } /* clean up the list */ i = 0; while (i < maxpidindex) { if (pidlist[i].child == -1) { pidlist[i] = pidlist[--maxpidindex]; continue; /* don't increment i */ } i++; } } long PyThread_start_new_thread(void (*func)(void *), void *arg) { #ifdef USE_DL long addr, size; static int local_initialized = 0; #endif /* USE_DL */ int success = 0; /* init not needed when SOLARIS_THREADS and */ /* C_THREADS implemented properly */ dprintf(("PyThread_start_new_thread called\n")); if (!initialized) PyThread_init_thread(); switch (ussetlock(count_lock)) { case 0: return 0; case -1: perror("ussetlock (count_lock)"); } if (maxpidindex >= MAXPROC) success = -1; else { #ifdef USE_DL if (!local_initialized) { if ((size = usconfig(CONF_INITSIZE, 64*1024)) < 0) perror("usconfig - CONF_INITSIZE (check)"); if (usconfig(CONF_INITSIZE, size) < 0) perror("usconfig - CONF_INITSIZE (reset)"); addr = (long) dl_getrange(size + HDR_SIZE); dprintf(("trying to use addr %p-%p for sproc\n", addr, addr+size)); errno = 0; if ((addr = usconfig(CONF_ATTACHADDR, addr)) < 0 && errno != 0) perror("usconfig - CONF_ATTACHADDR (set)"); } #endif /* USE_DL */ clean_threads(); if ((success = sproc(func, PR_SALL, arg)) < 0) perror("sproc"); #ifdef USE_DL if (!local_initialized) { if (usconfig(CONF_ATTACHADDR, addr) < 0) /* reset address */ perror("usconfig - CONF_ATTACHADDR (reset)"); local_initialized = 1; } #endif /* USE_DL */ if (success >= 0) { nthreads++; pidlist[maxpidindex].parent = getpid(); pidlist[maxpidindex++].child = success; dprintf(("pidlist[%d] = %d\n", maxpidindex-1, success)); } } if (usunsetlock(count_lock) < 0) perror("usunsetlock (count_lock)"); return success; } long PyThread_get_thread_ident(void) { return getpid(); } static void do_PyThread_exit_thread(int no_cleanup) { dprintf(("PyThread_exit_thread called\n")); if (!initialized) if (no_cleanup) _exit(0); else exit(0); if (ussetlock(count_lock) < 0) perror("ussetlock (count_lock)"); nthreads--; if (getpid() == my_pid) { /* main thread; wait for other threads to exit */ exiting = 1; #ifndef NO_EXIT_PROG if (do_exit) { int i; /* notify other threads */ clean_threads(); if (nthreads >= 0) { dprintf(("kill other threads\n")); for (i = 0; i < maxpidindex; i++) if (pidlist[i].child > 0) (void) kill(pidlist[i].child, SIGKILL); _exit(exit_status); } } #endif /* NO_EXIT_PROG */ waiting_for_threads = 1; if (ussetlock(wait_lock) < 0) perror("ussetlock (wait_lock)"); for (;;) { if (nthreads < 0) { dprintf(("really exit (%d)\n", exit_status)); if (no_cleanup) _exit(exit_status); else exit(exit_status); } if (usunsetlock(count_lock) < 0) perror("usunsetlock (count_lock)"); dprintf(("waiting for other threads (%d)\n", nthreads)); if (ussetlock(wait_lock) < 0) perror("ussetlock (wait_lock)"); if (ussetlock(count_lock) < 0) perror("ussetlock (count_lock)"); } } /* not the main thread */ if (waiting_for_threads) { dprintf(("main thread is waiting\n")); if (usunsetlock(wait_lock) < 0) perror("usunsetlock (wait_lock)"); } #ifndef NO_EXIT_PROG else if (do_exit) (void) kill(my_pid, SIGUSR1); #endif /* NO_EXIT_PROG */ if (usunsetlock(count_lock) < 0) perror("usunsetlock (count_lock)"); _exit(0); } void PyThread_exit_thread(void) { do_PyThread_exit_thread(0); } void PyThread__exit_thread(void) { do_PyThread_exit_thread(1); } #ifndef NO_EXIT_PROG static void do_PyThread_exit_prog(int status, int no_cleanup) { dprintf(("PyThread_exit_prog(%d) called\n", status)); if (!initialized) if (no_cleanup) _exit(status); else exit(status); do_exit = 1; exit_status = status; do_PyThread_exit_thread(no_cleanup); } void PyThread_exit_prog(int status) { do_PyThread_exit_prog(status, 0); } void PyThread__exit_prog(int status) { do_PyThread_exit_prog(status, 1); } #endif /* NO_EXIT_PROG */ /* * Lock support. */ PyThread_type_lock PyThread_allocate_lock(void) { ulock_t lock; dprintf(("PyThread_allocate_lock called\n")); if (!initialized) PyThread_init_thread(); if ((lock = usnewlock(shared_arena)) == NULL) perror("usnewlock"); (void) usinitlock(lock); dprintf(("PyThread_allocate_lock() -> %p\n", lock)); return (PyThread_type_lock) lock; } void PyThread_free_lock(PyThread_type_lock lock) { dprintf(("PyThread_free_lock(%p) called\n", lock)); usfreelock((ulock_t) lock, shared_arena); } int PyThread_acquire_lock(PyThread_type_lock lock, int waitflag) { int success; dprintf(("PyThread_acquire_lock(%p, %d) called\n", lock, waitflag)); errno = 0; /* clear it just in case */ if (waitflag) success = ussetlock((ulock_t) lock); else success = uscsetlock((ulock_t) lock, 1); /* Try it once */ if (success < 0) perror(waitflag ? "ussetlock" : "uscsetlock"); dprintf(("PyThread_acquire_lock(%p, %d) -> %d\n", lock, waitflag, success)); return success; } void PyThread_release_lock(PyThread_type_lock lock) { dprintf(("PyThread_release_lock(%p) called\n", lock)); if (usunsetlock((ulock_t) lock) < 0) perror("usunsetlock"); }
