Commit graph

250 commits

Author SHA1 Message Date
Daniel Kochmański
4e9fab94eb ecl_bignum: access the internal object with a macro ecl_bignum
This provides a better data encapsulation and is more portable. Moreover it is
consistent with how we handle other boxed values like ecl_doublefloat.
2022-05-06 10:13:08 +02:00
Marius Gerbershagen
806336ed2e multithreading: read-write-lock improvements
Read-write locks are always provided; if no operating system
primitives exist, emulate them using ordinary locks. Also provide a
Windows implementation.
2021-08-29 17:25:21 +02:00
Marius Gerbershagen
de5d56b4c6 multithreading: replace various synchronization objects by native mutexes
- Spinlocks have been replaced by ordinary locks. Without access to
  the underyling scheduler, spinlocks provide no performace benefit
  and may even be harmful in case of high contention.
- Synchronization of process creation and exiting has been simplified.
  Instead of a spinlock, a barrier and atomic operations we now use
  only a single lock protecting the shared process state and a
  condition variable for implementing process joins.
- Some locks which were implemented using Lisp objects now directly
  use a native mutex.
- Our own mutex implementation has been removed as it is now unused.
2021-08-29 17:23:20 +02:00
Marius Gerbershagen
23a7ade20c multithreading: implement mailboxes using native mutexes
The old implementation was not race condition free. If two threads (A
and B) were writing at the same time while one thread (C) was reading,
the following could happen:

1. thread A increases the write pointer (but does not store the
   message yet)
2. thread B increases the write pointer, stores the message and
   signals thread C
3. thread C tries to read from the location that thread A has not yet
   written to

The new implementation is a simple and obvious solution using a common
mutex and two condition variables for reading/writing. We don't bother
with a (complex) interrupt safe implementation.
2021-08-29 17:23:20 +02:00
Marius Gerbershagen
968083738a multithreading: implement semaphores using native mutexes 2021-08-29 17:23:20 +02:00
Marius Gerbershagen
b332f2c592 multithreading: implement barriers using native mutexes 2021-08-29 17:23:20 +02:00
Marius Gerbershagen
0f737b6ba6 multithreading: implement mutexes and condition variables using OS primitives
Replace slow homegrown mutex implementation by standard OS functions.

We try our best to be interrupt safe, however a completely safe
implementation is impossible (unless one completely removes the ability
to interrupt a thread waiting on a mutex). There is always a window
after the OS specific function has returned, but before we can set
the owner, in which interrupts will see an inconsistent state of the
mutex with regards to owner and count.

Condition variables are now based on OS functions as well. Timed
waiting on condition variables has also been implemented.
2021-08-29 17:23:19 +02:00
Marius Gerbershagen
8a38c9a3c2 remove register storage class specifier
This option is not needed anymore, ignored by modern compilers and has
been removed in the C++17 standard.

Fixes #647.
2021-07-17 12:13:05 +02:00
Marius Gerbershagen
ddb7bb72e9 gc: call finalizer for builtin object only when the object is truly unreachable
Otherwise it can happen that a user-defined finalizer for some object
A storing a builtin object B registers another finalizer for A making
B reachable again while B has already been finalized.

We can't impose an ordering for user-defined finalizers in general
since these may include cyclic references. Therefore it is the duty of
the user to write the finalizers in a consistent way which is
independent of the order in which the finalizers are called. This
doesn't work for builtin objects since the user can't influence
the finalizers in this case.

We also fix a bug which lead to the removal of the standard finalizer
if a user-defined finalizer was registered and then removed.

Co-authored-by: Daniel Kochmański <daniel@turtleware.eu>
2021-06-12 21:26:47 +02:00
Marius Gerbershagen
36a9c95c80 tree-wide: use new dpp @"" specifier for constant base strings where appropriate 2021-03-12 19:53:33 +01:00
Daniel Kochmański
7f1813cd93 ecl_alloc_weak_pointer: don't register immediate objects as disappearing
We have special-cased all immediate objects except ECL_T. Creating such link
leads to a segmentation fault when GC tries to dereference the pointer. Fixes #610.
2020-10-19 16:54:40 +02:00
Marius Gerbershagen
adaeaaf06c gc: fix for finalizers called from non-initialized threads
We can't use the standard functions like cl_list for allocating the
wrapper object for the finalizer since these need a working environment
for disabling interrupts.
2020-08-02 10:55:25 +02:00
Marius Gerbershagen
e0bf0f5ac2 gc: remove unnecessary workarounds for old bdwgc versions 2020-05-10 19:47:05 +02:00
Marius Gerbershagen
d8fbbb213e gc: fix type info for precise garbage collector mode 2020-05-08 21:10:41 +02:00
Marius Gerbershagen
c6b4296bb8 cosmetic: fix some compiler warnings 2020-04-29 20:35:37 +02:00
Daniel Kochmański
b9d54d6be7 internals: rename instance.sig to instance.slotds
Slot definitions are no longer a signature, but they are still needed
to update obsolete instances. Reader function name is also changed to
SI:INSTANCE-SLOTDS. SI:INSTANCE-SIG-SET name does not change, because
it sets both SLOTDS and the STAMP.
2020-04-19 17:04:42 +02:00
Daniel Kochmański
f1bc883ed6 clos: introduce class stamps for marking instances obsolete
We should call make-instances-obsolete from finalize-inheritance if we
want to be conforming, because user may have added their own auxiliary
methods.

This change while being last in a serie of commits was locally the
first change which solved problems. It will enable us to implement the
fast generic dispatch after the release.
2020-04-19 17:04:41 +02:00
Daniel Kochmański
3e0a8c63eb weak-pointer: return two values: value and whenever it is present
We do that to avoid confusion (like with hashtables).
2019-05-25 09:56:08 +02:00
Daniel Kochmański
ea87100a06 long-float: remove conditionalization
Many parts of the source code were bent backward to support builds
without long floats which are always present given we depend expect
c99 compiler.

The corresponding C macros (ECL_LONG_FLOAT) and the *feature*
entry (:long-float) are marked as deprecated in the documentation.
2019-05-24 21:04:59 +00:00
Daniel Kochmański
20a7030277 complex float: add gc boilerplate 2019-05-06 08:17:33 +02:00
Daniel Kochmański
f78cb49def complex float: rename cl_lispunion member complex to gencomplex
Complex is a macro specified in complex.h for c99 to simplify using
_Complex type. This file also contains functions to work on complex
floats. To avoid conflicts we rename internal name complex to
gencomplex and update all references to it.
2019-05-06 08:17:33 +02:00
Daniel Kochmański
3766821b25 cosmetic: indent, line breaks 2019-04-20 22:31:21 +02:00
Marius Gerbershagen
24dcb778cf clean up functions creating base strings from C strings
Make functions behave as documented, remove use of legacy names.
    Fixes #462.
2019-01-07 18:43:55 +01:00
Marius Gerbershagen
b5194ca774 threading: fix interrupt safety of out_of_memory function
This function used writes in the thread local environment while
    interrupts where disabled with the env->disable_interrupts
    mechanism, which causes problems with the mprotect() mechanism for
    fast interrupt dispatch.
2018-09-09 17:06:32 +02:00
Marius Gerbershagen
146b4a6ae1 cosmetic: fixed some typos and style issues 2018-03-26 21:11:11 +02:00
Marius Gerbershagen
a8d7305fb6 threading: fix race condition in stacks_scanner
The garbage collector can call stacks_scanner in a thread before
    pthread_setspecific, leading to a wrong error message. The
    solution is simply not to mark the environment, if
    pthread_setspecific has not yet been called.
2018-02-20 21:40:04 +01:00
Marius Gerbershagen
79b77fc7e5 add another forgotten ecl_enable_interrupts 2018-01-22 21:13:07 +01:00
Daniel Kochmański
2877ffde65 Merge branch 'fix-memory-corruption' into 'develop'
Use bdwgc macros to allow memory debug.

See merge request embeddable-common-lisp/ecl!92
2017-09-19 14:02:08 +00:00
Fabrizio Fabbri
bc522801a9
Use bdwgc macros to allow memory debug. 2017-09-19 00:23:47 -04:00
Marius Gerbershagen
8c2748da17 fix segmentation faults when interrupting a thread while it is exiting
When mp_process_interrupt and thread_cleanup are called at the same
time, it is possible that the thread-local environment is deallocated
while ecl_interrupt_process tries to use it. This two methods thus
need to be protected with a lock.
2017-09-13 18:51:44 +02:00
Kris Katterjohn
5095097a6a Wrap variable definitions in #ifdef's to avoid unused-variable warnings 2017-03-14 15:53:32 -05:00
Daniel Kochmański
2287b02b53 gc-stats: always return correct number of bytes consed 2016-12-04 15:53:50 +01:00
Daniel Kochmański
b51576c90d cosmetic: comment wrap 2016-12-04 15:19:53 +01:00
Daniel Kochmański
426ab1f172 gc-stats: handle unsinged int overflow correctly 2016-12-04 14:48:26 +01:00
Daniel Kochmański
e4e3bc64bc cosmetic: comment wrap 2016-12-04 14:47:59 +01:00
Daniel Kochmański
c1067620a7 Improve rwlock built-in class recognition
Fixes #303.
2016-11-10 19:42:52 +01:00
Daniel Kochmański
0f6793aab4 alloc_2: wrapped_finalizer: fix no-thread builds 2016-09-06 18:01:04 +02:00
Daniel Kochmański
5024c38e33 cosmetic: indent 2016-09-06 18:00:31 +02:00
Fabrizio Fabbri
28a0f957fe Use the project comment style. 2016-08-29 03:55:16 -04:00
Fabrizio Fabbri
1e5e86c1d2 Fix on several minor issue on thread.
- fix #262 to manage CTRL+c on Win.
- unregistered thread are left registered and enviroment not cleanup.
-  manage when a finalizer is invoked before a valid enviroment is available.
2016-08-23 15:28:23 -04:00
Daniel Kochmański
749b97d06c indent: indent files according to GNU standard
(a-c)

doc: list files
2016-05-05 13:40:27 +02:00
Matthew Mondor
c5c606cc01 - User-defined heap sizes can now exceed the size of a fixnum on 32-bit
Fixes issue #140

- The heap size limit was intended to be 1GB on 32-bit or 4GB on 64-bit
  but inconsistency between ECL_FIXNUM_BITS and FIXNUM_BITS in the code
  prevented the heap to grow for 64-bit.  This now occurs, and a few
  other less visible bugs were fixed by restoring consistency to
  ECL_FIXNUM_BITS.
2015-09-11 16:54:18 -04:00
Matthew Mondor
8f07cd58d8 The ECL code no longer uses tabulator characters, they were replaced
by spaces.

A custom script was used to insert/replace Emacs and ViM per-file editor
settings according to their type and the new ECL coding style.
2015-09-03 07:35:47 -04:00
Daniel Kochmański
7a29be4337 CLOS: remove dead code and conditionals for non-clos builds
Builds without CLOS weren't possible for long time, yet a lot of dead
code for non-clos builds was spread across sources. This commit
removes all ifdefs and dead blocks from codebase.

Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
2015-07-01 16:56:17 +02:00
Daniel Kochmański
4d19a27424 cosmetic: untabify
Signed-off-by: Daniel Kochmański <dkochmanski@turtle-solutions.eu>
2015-06-21 14:38:20 +02:00
Roger Sen
cddb87313d Updated GC api to remove deprecated methods 2015-04-12 11:47:43 +02:00
Philipp Marek
3e9f5cafe1 Fix declaration that was activated by commit 285eb318,
"fixes for the detection of GC_start_call_back"
2014-02-27 20:47:53 +01:00
D Herring
285eb31812 fixes for the detection of GC_start_call_back
- HAVE_GC_SET_START_CALLBACK was defined unconditionally
- there was no AC_DEFINE if system_boehm was false
- there was a typo in one usage site of this macro

see 6b754564f1
2014-02-27 09:43:21 +01:00
Juanjo Garcia-Ripoll
f0e31ded05 Fixed declaration of GC_start_call_back 2013-10-06 22:39:11 +02:00
Juanjo Garcia-Ripoll
6b754564f1 GC_start_call_back disappeared in recent versions of the GC library 2013-10-06 17:01:01 +02:00